forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mediator.php
67 lines (57 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
61
62
63
64
65
66
67
<?php
namespace DesignPatterns\Behavioral\Mediator;
use DesignPatterns\Behavioral\Mediator\Subsystem;
/**
* 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
*/
protected $server;
/**
* @var Subsystem\Database
*/
protected $database;
/**
* @var Subsystem\Client
*/
protected $client;
/**
* @param Subsystem\Database $db
* @param Subsystem\Client $cl
* @param Subsystem\Server $srv
*/
public function setColleague(Subsystem\Database $db, Subsystem\Client $cl, Subsystem\Server $srv)
{
$this->database = $db;
$this->server = $srv;
$this->client = $cl;
}
/**
* make request
*/
public function makeRequest()
{
$this->server->process();
}
/**
* query db
* @return mixed
*/
public function queryDb()
{
return $this->database->getData();
}
/**
* send response
*
* @param string $content
*/
public function sendResponse($content)
{
$this->client->output($content);
}
}