mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-25 13:59:08 +02:00
57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Mediator;
|
|
|
|
class Mediator implements MediatorInterface
|
|
{
|
|
/**
|
|
* @var Subsystem\Server
|
|
*/
|
|
private $server;
|
|
|
|
/**
|
|
* @var Subsystem\Database
|
|
*/
|
|
private $database;
|
|
|
|
/**
|
|
* @var Subsystem\Client
|
|
*/
|
|
private $client;
|
|
|
|
/**
|
|
* @param Subsystem\Database $database
|
|
* @param Subsystem\Client $client
|
|
* @param Subsystem\Server $server
|
|
*/
|
|
public function __construct(Subsystem\Database $database, Subsystem\Client $client, Subsystem\Server $server)
|
|
{
|
|
$this->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();
|
|
}
|
|
|
|
/**
|
|
* @param string $content
|
|
*/
|
|
public function sendResponse($content)
|
|
{
|
|
$this->client->output($content);
|
|
}
|
|
}
|