diff --git a/Behavioral/Mediator/ConcreteMediator.php b/Behavioral/Mediator/ConcreteMediator.php deleted file mode 100644 index 384bb4a..0000000 --- a/Behavioral/Mediator/ConcreteMediator.php +++ /dev/null @@ -1,47 +0,0 @@ -database = $database; - $this->server = $server; - $this->client = $client; - - $this->database->setMediator($this); - $this->server->setMediator($this); - $this->client->setMediator($this); - } - - public function makeRequest() - { - $this->server->process(); - } - - public function queryDb(): string - { - return $this->database->getData(); - } - - public function sendResponse(string $content) - { - $this->client->output($content); - } -} diff --git a/Behavioral/Mediator/Mediator.php b/Behavioral/Mediator/Mediator.php index 62f0297..3402544 100644 --- a/Behavioral/Mediator/Mediator.php +++ b/Behavioral/Mediator/Mediator.php @@ -4,9 +4,5 @@ namespace DesignPatterns\Behavioral\Mediator; interface Mediator { - public function sendResponse(string $content); - - public function makeRequest(); - - public function queryDb(); + public function getUser(string $username): string; } diff --git a/Behavioral/Mediator/README.rst b/Behavioral/Mediator/README.rst index fe6d7f2..f235c53 100644 --- a/Behavioral/Mediator/README.rst +++ b/Behavioral/Mediator/README.rst @@ -30,33 +30,27 @@ Mediator.php :language: php :linenos: -ConcreteMediator.php - -.. literalinclude:: ConcreteMediator.php - :language: php - :linenos: - Colleague.php .. literalinclude:: Colleague.php :language: php :linenos: -Subsystem/Client.php +Ui.php -.. literalinclude:: Subsystem/Client.php +.. literalinclude:: Ui.php :language: php :linenos: -Subsystem/Database.php +UserRepository.php -.. literalinclude:: Subsystem/Database.php +.. literalinclude:: UserRepository.php :language: php :linenos: -Subsystem/Server.php +UserRepositoryUiMediator.php -.. literalinclude:: Subsystem/Server.php +.. literalinclude:: UserRepositoryUiMediator.php :language: php :linenos: diff --git a/Behavioral/Mediator/Subsystem/Client.php b/Behavioral/Mediator/Subsystem/Client.php deleted file mode 100644 index bdf157c..0000000 --- a/Behavioral/Mediator/Subsystem/Client.php +++ /dev/null @@ -1,21 +0,0 @@ -mediator->makeRequest(); - } - - public function output(string $content) - { - echo $content; - } -} diff --git a/Behavioral/Mediator/Subsystem/Database.php b/Behavioral/Mediator/Subsystem/Database.php deleted file mode 100644 index 383d358..0000000 --- a/Behavioral/Mediator/Subsystem/Database.php +++ /dev/null @@ -1,13 +0,0 @@ -mediator->queryDb(); - $this->mediator->sendResponse(sprintf("Hello %s", $data)); - } -} diff --git a/Behavioral/Mediator/Tests/MediatorTest.php b/Behavioral/Mediator/Tests/MediatorTest.php index 0081580..9b94ca1 100644 --- a/Behavioral/Mediator/Tests/MediatorTest.php +++ b/Behavioral/Mediator/Tests/MediatorTest.php @@ -2,20 +2,18 @@ namespace DesignPatterns\Tests\Mediator\Tests; -use DesignPatterns\Behavioral\Mediator\ConcreteMediator; -use DesignPatterns\Behavioral\Mediator\Subsystem\Client; -use DesignPatterns\Behavioral\Mediator\Subsystem\Database; -use DesignPatterns\Behavioral\Mediator\Subsystem\Server; +use DesignPatterns\Behavioral\Mediator\Ui; +use DesignPatterns\Behavioral\Mediator\UserRepository; +use DesignPatterns\Behavioral\Mediator\UserRepositoryUiMediator; use PHPUnit\Framework\TestCase; class MediatorTest extends TestCase { public function testOutputHelloWorld() { - $client = new Client(); - new ConcreteMediator(new Database(), $client, new Server()); + $mediator = new UserRepositoryUiMediator(new UserRepository(), new UI()); - $this->expectOutputString('Hello World'); - $client->request(); + $this->expectOutputString('User: Dominik'); + $mediator->printInfoAbout('Dominik'); } } diff --git a/Behavioral/Mediator/Ui.php b/Behavioral/Mediator/Ui.php new file mode 100644 index 0000000..2ba2820 --- /dev/null +++ b/Behavioral/Mediator/Ui.php @@ -0,0 +1,11 @@ +mediator->getUser($username); + } +} diff --git a/Behavioral/Mediator/UserRepository.php b/Behavioral/Mediator/UserRepository.php new file mode 100644 index 0000000..72801fe --- /dev/null +++ b/Behavioral/Mediator/UserRepository.php @@ -0,0 +1,11 @@ +userRepository = $userRepository; + $this->ui = $ui; + + $this->userRepository->setMediator($this); + $this->ui->setMediator($this); + } + + public function printInfoAbout(string $user) + { + $this->ui->outputUserInfo($user); + } + + public function getUser(string $username): string + { + return $this->userRepository->getUserName($username); + } +} diff --git a/Behavioral/Mediator/uml/uml.png b/Behavioral/Mediator/uml/uml.png index 5245f1e..8fb5793 100644 Binary files a/Behavioral/Mediator/uml/uml.png and b/Behavioral/Mediator/uml/uml.png differ