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