From d2e86f1c35074457dc49bad6a7ddca3bc5a9e379 Mon Sep 17 00:00:00 2001 From: Trismegiste Date: Sun, 12 May 2013 14:25:17 +0200 Subject: [PATCH] mediator in one pass --- Mediator/Colleague.php | 31 +++++++++++++++++++ Mediator/Mediator.php | 53 +++++++++++++++++++++++++++++++++ Mediator/MediatorInterface.php | 21 +++++++++++++ Mediator/Subsystem/Client.php | 27 +++++++++++++++++ Mediator/Subsystem/Database.php | 22 ++++++++++++++ Mediator/Subsystem/Server.php | 23 ++++++++++++++ Tests/Mediator/MediatorTest.php | 36 ++++++++++++++++++++++ 7 files changed, 213 insertions(+) create mode 100644 Mediator/Colleague.php create mode 100644 Mediator/Mediator.php create mode 100644 Mediator/MediatorInterface.php create mode 100644 Mediator/Subsystem/Client.php create mode 100644 Mediator/Subsystem/Database.php create mode 100644 Mediator/Subsystem/Server.php create mode 100644 Tests/Mediator/MediatorTest.php diff --git a/Mediator/Colleague.php b/Mediator/Colleague.php new file mode 100644 index 0000000..e410e86 --- /dev/null +++ b/Mediator/Colleague.php @@ -0,0 +1,31 @@ +mediator; + } + + public function __construct(MediatorInterface $medium) + { + // in this way, we are sure the concrete colleague knows the mediator + $this->mediator = $medium; + } + +} \ No newline at end of file diff --git a/Mediator/Mediator.php b/Mediator/Mediator.php new file mode 100644 index 0000000..d6edb8c --- /dev/null +++ b/Mediator/Mediator.php @@ -0,0 +1,53 @@ +database = $db; + $this->server = $srv; + $this->client = $cl; + } + + public function makeRequest() + { + $this->server->process(); + } + + public function queryDb() + { + return $this->database->getData(); + } + + public function sendResponse($content) + { + $this->client->output($content); + } + +} \ No newline at end of file diff --git a/Mediator/MediatorInterface.php b/Mediator/MediatorInterface.php new file mode 100644 index 0000000..019ad4e --- /dev/null +++ b/Mediator/MediatorInterface.php @@ -0,0 +1,21 @@ +getMediator()->makeRequest(); + } + + public function output($content) + { + echo $content; + } + +} \ No newline at end of file diff --git a/Mediator/Subsystem/Database.php b/Mediator/Subsystem/Database.php new file mode 100644 index 0000000..dd7bb01 --- /dev/null +++ b/Mediator/Subsystem/Database.php @@ -0,0 +1,22 @@ +getMediator()->queryDb(); + $this->getMediator()->sendResponse("Hello $data"); + } + +} \ No newline at end of file diff --git a/Tests/Mediator/MediatorTest.php b/Tests/Mediator/MediatorTest.php new file mode 100644 index 0000000..b673985 --- /dev/null +++ b/Tests/Mediator/MediatorTest.php @@ -0,0 +1,36 @@ +client = new Client($media); + $media->setColleague(new Database($media), $this->client, new Server($media)); + } + + public function testOutputHelloWorld() + { + // testing if Hello World is output : + $this->expectOutputString('Hello World'); + $this->client->request(); + } + +} \ No newline at end of file