Skip to content

Commit ef0226e

Browse files
author
Dominik Liebler
committed
Merge branch 'master' into flyweight
2 parents b2c034e + 3d3417a commit ef0226e

File tree

475 files changed

+21886
-1304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

475 files changed

+21886
-1304
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
.idea
33
/nbproject
44
/vendor/
5+
_build/
6+
*.mo
7+
.vagrant/
8+
phpunit.xml
9+
composer.phar

.travis.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
language: php
2+
3+
sudo: false
4+
25
php:
36
- 5.3
47
- 5.4
58
- 5.5
9+
- 5.6
10+
- 7.0
611
- hhvm
712

8-
before_script:
9-
- composer self-update
10-
- composer install --prefer-source --no-interaction --dev
11-
12-
branches:
13-
only:
14-
- master
15-
1613
matrix:
1714
allow_failures:
1815
- php: hhvm
16+
- php: 7.0
1917
fast_finish: true
18+
19+
cache:
20+
directories:
21+
- $HOME/.composer/cache
22+
23+
before_install:
24+
- composer self-update
25+
- composer validate
26+
27+
install:
28+
- composer install --prefer-dist --no-interaction
29+
30+
script:
31+
- vendor/bin/phpunit

Behavioral/ChainOfResponsibilities/Handler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace DesignPatterns\Behavioral\ChainOfResponsibilities;
44

55
/**
6-
* Handler is a generic handler in the chain of responsibilities
6+
* Handler is a generic handler in the chain of responsibilities.
77
*
88
* Yes you could have a lighter CoR with a simpler handler but if you want your CoR
99
* to be extendable and decoupled, it's a better idea to do things like that in real
@@ -18,7 +18,7 @@ abstract class Handler
1818
private $successor = null;
1919

2020
/**
21-
* Append a responsibility to the end of chain
21+
* Append a responsibility to the end of chain.
2222
*
2323
* A prepend method could be done with the same spirit
2424
*
@@ -68,7 +68,7 @@ final public function handle(Request $req)
6868
}
6969

7070
/**
71-
* Each concrete handler has to implement the processing of the request
71+
* Each concrete handler has to implement the processing of the request.
7272
*
7373
* @param Request $req
7474
*

Behavioral/ChainOfResponsibilities/README.md

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
`Chain Of Responsibilities`__
2+
=============================
3+
4+
Purpose:
5+
--------
6+
7+
To build a chain of objects to handle a call in sequential order. If one
8+
object cannot handle a call, it delegates the call to the next in the
9+
chain and so forth.
10+
11+
Examples:
12+
---------
13+
14+
- logging framework, where each chain element decides autonomously what
15+
to do with a log message
16+
- a Spam filter
17+
- Caching: first object is an instance of e.g. a Memcached Interface,
18+
if that "misses" it delegates the call to the database interface
19+
- Yii Framework: CFilterChain is a chain of controller action filters.
20+
the executing point is passed from one filter to the next along the
21+
chain, and only if all filters say "yes", the action can be invoked
22+
at last.
23+
24+
UML Diagram
25+
-----------
26+
27+
.. image:: uml/uml.png
28+
:alt: Alt ChainOfResponsibility UML Diagram
29+
:align: center
30+
31+
Code
32+
----
33+
34+
You can also find these code on `GitHub`_
35+
36+
Request.php
37+
38+
.. literalinclude:: Request.php
39+
:language: php
40+
:linenos:
41+
42+
Handler.php
43+
44+
.. literalinclude:: Handler.php
45+
:language: php
46+
:linenos:
47+
48+
Responsible/SlowStorage.php
49+
50+
.. literalinclude:: Responsible/SlowStorage.php
51+
:language: php
52+
:linenos:
53+
54+
Responsible/FastStorage.php
55+
56+
.. literalinclude:: Responsible/FastStorage.php
57+
:language: php
58+
:linenos:
59+
60+
Test
61+
----
62+
63+
Tests/ChainTest.php
64+
65+
.. literalinclude:: Tests/ChainTest.php
66+
:language: php
67+
:linenos:
68+
69+
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/ChainOfResponsibilities
70+
.. __: http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern

Behavioral/ChainOfResponsibilities/Responsible/FastStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use DesignPatterns\Behavioral\ChainOfResponsibilities\Request;
77

88
/**
9-
* Class FastStorage
9+
* Class FastStorage.
1010
*/
1111
class FastStorage extends Handler
1212
{

Behavioral/ChainOfResponsibilities/Responsible/SlowStorage.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
use DesignPatterns\Behavioral\ChainOfResponsibilities\Request;
77

88
/**
9-
* This is mostly the same code as FastStorage but in fact, it may greatly differs
9+
* This is mostly the same code as FastStorage but in fact, it may greatly differs.
1010
*
1111
* One important fact about CoR: each item in the chain MUST NOT assume its position
1212
* in the chain. A CoR is not responsible if the request is not handled UNLESS
13-
* you make an "ExceptionHandler" which throws execption if the request goes there.
13+
* you make an "ExceptionHandler" which throws exception if the request goes there.
1414
*
1515
* To be really extendable, each handler doesn't know if there is something after it.
16-
*
1716
*/
1817
class SlowStorage extends Handler
1918
{

Behavioral/ChainOfResponsibilities/Tests/ChainTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
namespace DesignPatterns\Behavioral\ChainOfResponsibilities\Tests;
44

55
use DesignPatterns\Behavioral\ChainOfResponsibilities\Request;
6+
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible;
67
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage;
78
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage;
8-
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible;
99

1010
/**
11-
* ChainTest tests the CoR
11+
* ChainTest tests the CoR.
1212
*/
1313
class ChainTest extends \PHPUnit_Framework_TestCase
1414
{
15-
1615
/**
1716
* @var FastStorage
1817
*/
@@ -30,7 +29,7 @@ public function makeRequest()
3029
$request->verb = 'get';
3130

3231
return array(
33-
array($request)
32+
array($request),
3433
);
3534
}
3635

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace DesignPatterns\Behavioral\Command;
4+
5+
/**
6+
* This concrete command tweaks receiver to add current date to messages
7+
* invoker just knows that it can call "execute".
8+
*/
9+
class AddMessageDateCommand implements UndoableCommandInterface
10+
{
11+
/**
12+
* @var Receiver
13+
*/
14+
protected $output;
15+
16+
/**
17+
* Each concrete command is built with different receivers.
18+
* There can be one, many or completely no receivers, but there can be other commands in the parameters.
19+
*
20+
* @param Receiver $console
21+
*/
22+
public function __construct(Receiver $console)
23+
{
24+
$this->output = $console;
25+
}
26+
27+
/**
28+
* Execute and make receiver to enable displaying messages date.
29+
*/
30+
public function execute()
31+
{
32+
// sometimes, there is no receiver and this is the command which
33+
// does all the work
34+
$this->output->enableDate();
35+
}
36+
37+
/**
38+
* Undo the command and make receiver to disable displaying messages date.
39+
*/
40+
public function undo()
41+
{
42+
// sometimes, there is no receiver and this is the command which
43+
// does all the work
44+
$this->output->disableDate();
45+
}
46+
}

Behavioral/Command/CommandInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace DesignPatterns\Behavioral\Command;
44

55
/**
6-
* class CommandInterface
6+
* class CommandInterface.
77
*/
88
interface CommandInterface
99
{

0 commit comments

Comments
 (0)