forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mediator.php
60 lines (51 loc) · 1.24 KB
/
Mediator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace DesignPatterns\Behavioral\Mediator;
/**
* Mediator is the concrete Mediator for this design pattern
*
* In this example, I have made a "Hello World" with the Mediator Pattern
*/
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);
}
}