@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -abstract class AbstractColleague |
|
6 | -{ |
|
5 | +abstract class AbstractColleague |
|
6 | +{ |
|
7 | 7 | /** |
8 | 8 | * @var \DesignPattern\Behavioral\Mediator\MediatorInterface |
9 | 9 | */ |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @param \DesignPattern\Behavioral\Mediator\MediatorInterface $mediator |
16 | 16 | */ |
17 | - public function __construct(MediatorInterface $mediator) |
|
18 | - { |
|
17 | + public function __construct(MediatorInterface $mediator) |
|
18 | + { |
|
19 | 19 | $this->mediator = $mediator; |
20 | 20 | } |
21 | 21 |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -interface MediatorInterface |
|
6 | -{ |
|
5 | +interface MediatorInterface |
|
6 | +{ |
|
7 | 7 | public function sendRequest(); |
8 | 8 | |
9 | 9 | public function query(); |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -class Consumer extends AbstractColleague |
|
6 | -{ |
|
7 | - public function request() |
|
8 | - { |
|
5 | +class Consumer extends AbstractColleague |
|
6 | +{ |
|
7 | + public function request() |
|
8 | + { |
|
9 | 9 | return $this->getMediator()->sendRequest(); |
10 | 10 | } |
11 | 11 | |
12 | - public function output($content) |
|
13 | - { |
|
12 | + public function output($content) |
|
13 | + { |
|
14 | 14 | return $content; |
15 | 15 | } |
16 | 16 | } |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -class Mediator implements MediatorInterface |
|
6 | -{ |
|
5 | +class Mediator implements MediatorInterface |
|
6 | +{ |
|
7 | 7 | /** |
8 | 8 | * @var \DesignPattern\Behavioral\Mediator\Consumer |
9 | 9 | */ |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return mixed |
68 | 68 | */ |
69 | - public function sendRequest() |
|
70 | - { |
|
69 | + public function sendRequest() |
|
70 | + { |
|
71 | 71 | return $this->server->response(); |
72 | 72 | } |
73 | 73 |
@@ -2,10 +2,10 @@ |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -class Server extends AbstractColleague |
|
6 | -{ |
|
7 | - public function response() |
|
8 | - { |
|
5 | +class Server extends AbstractColleague |
|
6 | +{ |
|
7 | + public function response() |
|
8 | + { |
|
9 | 9 | $data = $this->getMediator()->query(); |
10 | 10 | |
11 | 11 | return $this->getMediator()->recvResponse(sprintf('Hello %s', $data)); |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -class Database extends AbstractColleague |
|
6 | -{ |
|
5 | +class Database extends AbstractColleague |
|
6 | +{ |
|
7 | 7 | /** |
8 | 8 | * Query some data. |
9 | 9 | * |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | use Psr\Http\Message\RequestInterface; |
6 | 6 | |
7 | -class MemoryHandler extends Handler |
|
8 | -{ |
|
7 | +class MemoryHandler extends Handler |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @var array |
11 | 11 | */ |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * @param array $data |
18 | 18 | * @param \DesignPattern\Behavioral\ChainOfResponsibility\Handler|null $handler |
19 | 19 | */ |
20 | - public function __construct(array $data, Handler $handler = null) |
|
21 | - { |
|
20 | + public function __construct(array $data, Handler $handler = null) |
|
21 | + { |
|
22 | 22 | parent::__construct($handler); |
23 | 23 | |
24 | 24 | $this->data = $data; |
@@ -31,15 +31,15 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return mixed|null |
33 | 33 | */ |
34 | - protected function process(RequestInterface $request) |
|
35 | - { |
|
34 | + protected function process(RequestInterface $request) |
|
35 | + { |
|
36 | 36 | $key = sprintf( |
37 | 37 | '%s?%s', |
38 | 38 | $request->getUri()->getPath(), |
39 | 39 | $request->getUri()->getQuery() |
40 | 40 | ); |
41 | 41 | |
42 | - if (isset($this->data[$key]) && $request->getMethod() === 'GET') { |
|
42 | + if (isset($this->data[$key]) && $request->getMethod() === 'GET') { |
|
43 | 43 | return $this->data[$key]; |
44 | 44 | } |
45 | 45 |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | use Psr\Http\Message\RequestInterface; |
6 | 6 | |
7 | -abstract class Handler |
|
8 | -{ |
|
7 | +abstract class Handler |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @var \DesignPattern\Behavioral\ChainOfResponsibility\Handler|null |
11 | 11 | */ |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @param \DesignPattern\Behavioral\ChainOfResponsibility\Handler|null $handler |
18 | 18 | */ |
19 | - public function __construct(Handler $handler = null) |
|
20 | - { |
|
19 | + public function __construct(Handler $handler = null) |
|
20 | + { |
|
21 | 21 | $this->handler = $handler; |
22 | 22 | } |
23 | 23 | |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return mixed |
30 | 30 | */ |
31 | - final public function handle(RequestInterface $request) |
|
32 | - { |
|
31 | + final public function handle(RequestInterface $request) |
|
32 | + { |
|
33 | 33 | $process = $this->process($request); |
34 | 34 | |
35 | - if ($process === null && $this->handler !== null) { |
|
35 | + if ($process === null && $this->handler !== null) { |
|
36 | 36 | $process = $this->handler->handle($request); |
37 | 37 | } |
38 | 38 |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | use Psr\Http\Message\RequestInterface; |
6 | 6 | |
7 | -class DatabaseHandler extends Handler |
|
8 | -{ |
|
7 | +class DatabaseHandler extends Handler |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * Database processing. |
11 | 11 | * |