diff --git a/.gitignore b/.gitignore index 57f6f89..c6fa3e1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ /vendor/ _build/ *.mo +.vagrant/ +phpunit.xml +composer.phar diff --git a/.travis.yml b/.travis.yml index 9f10dff..9f379f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +20,11 @@ cache: directories: - $HOME/.composer/cache -before_script: +before_install: - composer self-update + - composer validate + +install: - composer install --prefer-dist --no-interaction script: diff --git a/Behavioral/ChainOfResponsibilities/Handler.php b/Behavioral/ChainOfResponsibilities/Handler.php index f080e23..679734e 100644 --- a/Behavioral/ChainOfResponsibilities/Handler.php +++ b/Behavioral/ChainOfResponsibilities/Handler.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Behavioral\ChainOfResponsibilities; /** - * Handler is a generic handler in the chain of responsibilities + * Handler is a generic handler in the chain of responsibilities. * * Yes you could have a lighter CoR with a simpler handler but if you want your CoR * to be extendable and decoupled, it's a better idea to do things like that in real @@ -18,7 +18,7 @@ abstract class Handler private $successor = null; /** - * Append a responsibility to the end of chain + * Append a responsibility to the end of chain. * * A prepend method could be done with the same spirit * @@ -68,7 +68,7 @@ abstract class Handler } /** - * Each concrete handler has to implement the processing of the request + * Each concrete handler has to implement the processing of the request. * * @param Request $req * diff --git a/Behavioral/ChainOfResponsibilities/Responsible/FastStorage.php b/Behavioral/ChainOfResponsibilities/Responsible/FastStorage.php index 4a74642..8acaad1 100644 --- a/Behavioral/ChainOfResponsibilities/Responsible/FastStorage.php +++ b/Behavioral/ChainOfResponsibilities/Responsible/FastStorage.php @@ -6,7 +6,7 @@ use DesignPatterns\Behavioral\ChainOfResponsibilities\Handler; use DesignPatterns\Behavioral\ChainOfResponsibilities\Request; /** - * Class FastStorage + * Class FastStorage. */ class FastStorage extends Handler { diff --git a/Behavioral/ChainOfResponsibilities/Responsible/SlowStorage.php b/Behavioral/ChainOfResponsibilities/Responsible/SlowStorage.php index bf21088..bd3f825 100644 --- a/Behavioral/ChainOfResponsibilities/Responsible/SlowStorage.php +++ b/Behavioral/ChainOfResponsibilities/Responsible/SlowStorage.php @@ -6,14 +6,13 @@ use DesignPatterns\Behavioral\ChainOfResponsibilities\Handler; use DesignPatterns\Behavioral\ChainOfResponsibilities\Request; /** - * This is mostly the same code as FastStorage but in fact, it may greatly differs + * This is mostly the same code as FastStorage but in fact, it may greatly differs. * * One important fact about CoR: each item in the chain MUST NOT assume its position * in the chain. A CoR is not responsible if the request is not handled UNLESS - * you make an "ExceptionHandler" which throws execption if the request goes there. + * you make an "ExceptionHandler" which throws exception if the request goes there. * * To be really extendable, each handler doesn't know if there is something after it. - * */ class SlowStorage extends Handler { diff --git a/Behavioral/ChainOfResponsibilities/Tests/ChainTest.php b/Behavioral/ChainOfResponsibilities/Tests/ChainTest.php index 0e8357c..62d1172 100644 --- a/Behavioral/ChainOfResponsibilities/Tests/ChainTest.php +++ b/Behavioral/ChainOfResponsibilities/Tests/ChainTest.php @@ -3,16 +3,15 @@ namespace DesignPatterns\Behavioral\ChainOfResponsibilities\Tests; use DesignPatterns\Behavioral\ChainOfResponsibilities\Request; +use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible; use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage; use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage; -use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible; /** - * ChainTest tests the CoR + * ChainTest tests the CoR. */ class ChainTest extends \PHPUnit_Framework_TestCase { - /** * @var FastStorage */ @@ -30,7 +29,7 @@ class ChainTest extends \PHPUnit_Framework_TestCase $request->verb = 'get'; return array( - array($request) + array($request), ); } diff --git a/Behavioral/Command/AddMessageDateCommand.php b/Behavioral/Command/AddMessageDateCommand.php new file mode 100644 index 0000000..11bb9af --- /dev/null +++ b/Behavioral/Command/AddMessageDateCommand.php @@ -0,0 +1,46 @@ +output = $console; + } + + /** + * Execute and make receiver to enable displaying messages date. + */ + public function execute() + { + // sometimes, there is no receiver and this is the command which + // does all the work + $this->output->enableDate(); + } + + /** + * Undo the command and make receiver to disable displaying messages date. + */ + public function undo() + { + // sometimes, there is no receiver and this is the command which + // does all the work + $this->output->disableDate(); + } +} diff --git a/Behavioral/Command/CommandInterface.php b/Behavioral/Command/CommandInterface.php index ad9117b..cd9d9c6 100644 --- a/Behavioral/Command/CommandInterface.php +++ b/Behavioral/Command/CommandInterface.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Behavioral\Command; /** - * class CommandInterface + * class CommandInterface. */ interface CommandInterface { diff --git a/Behavioral/Command/HelloCommand.php b/Behavioral/Command/HelloCommand.php index eb630ed..94d4723 100644 --- a/Behavioral/Command/HelloCommand.php +++ b/Behavioral/Command/HelloCommand.php @@ -4,7 +4,7 @@ namespace DesignPatterns\Behavioral\Command; /** * This concrete command calls "print" on the Receiver, but an external - * invoker just know he can call "execute" + * invoker just knows that it can call "execute". */ class HelloCommand implements CommandInterface { @@ -14,8 +14,8 @@ class HelloCommand implements CommandInterface protected $output; /** - * Each concrete command is builded with different receivers. - * Can be one, many, none or even other Command in parameters + * Each concrete command is built with different receivers. + * There can be one, many or completely no receivers, but there can be other commands in the parameters. * * @param Receiver $console */ @@ -25,7 +25,7 @@ class HelloCommand implements CommandInterface } /** - * execute and output "Hello World" + * execute and output "Hello World". */ public function execute() { diff --git a/Behavioral/Command/Invoker.php b/Behavioral/Command/Invoker.php index 4461ee2..7942adb 100644 --- a/Behavioral/Command/Invoker.php +++ b/Behavioral/Command/Invoker.php @@ -4,7 +4,7 @@ namespace DesignPatterns\Behavioral\Command; /** * Invoker is using the command given to it. - * Example : an Application in SF2 + * Example : an Application in SF2. */ class Invoker { @@ -25,7 +25,7 @@ class Invoker } /** - * executes the command + * executes the command. */ public function run() { diff --git a/Behavioral/Command/Receiver.php b/Behavioral/Command/Receiver.php index 9289369..956ce74 100644 --- a/Behavioral/Command/Receiver.php +++ b/Behavioral/Command/Receiver.php @@ -3,15 +3,44 @@ namespace DesignPatterns\Behavioral\Command; /** - * Receiver is specific service with its own contract and can be only concrete + * Receiver is specific service with its own contract and can be only concrete. */ class Receiver { + private $enableDate = false; + + private $output = array(); + /** * @param string $str */ public function write($str) { - echo $str; + if ($this->enableDate) { + $str .= ' ['.date('Y-m-d').']'; + } + + $this->output[] = $str; + } + + public function getOutput() + { + return implode("\n", $this->output); + } + + /** + * Enable receiver to display message date. + */ + public function enableDate() + { + $this->enableDate = true; + } + + /** + * Disable receiver to display message date. + */ + public function disableDate() + { + $this->enableDate = false; } } diff --git a/Behavioral/Command/Tests/CommandTest.php b/Behavioral/Command/Tests/CommandTest.php index abf7317..3852495 100644 --- a/Behavioral/Command/Tests/CommandTest.php +++ b/Behavioral/Command/Tests/CommandTest.php @@ -2,16 +2,15 @@ namespace DesignPatterns\Behavioral\Command\Tests; +use DesignPatterns\Behavioral\Command\HelloCommand; use DesignPatterns\Behavioral\Command\Invoker; use DesignPatterns\Behavioral\Command\Receiver; -use DesignPatterns\Behavioral\Command\HelloCommand; /** - * CommandTest has the role of the Client in the Command Pattern + * CommandTest has the role of the Client in the Command Pattern. */ class CommandTest extends \PHPUnit_Framework_TestCase { - /** * @var Invoker */ @@ -31,7 +30,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase public function testInvocation() { $this->invoker->setCommand(new HelloCommand($this->receiver)); - $this->expectOutputString('Hello World'); $this->invoker->run(); + $this->assertEquals($this->receiver->getOutput(), 'Hello World'); } } diff --git a/Behavioral/Command/Tests/UndoableCommandTest.php b/Behavioral/Command/Tests/UndoableCommandTest.php new file mode 100644 index 0000000..5302a7b --- /dev/null +++ b/Behavioral/Command/Tests/UndoableCommandTest.php @@ -0,0 +1,49 @@ +invoker = new Invoker(); + $this->receiver = new Receiver(); + } + + public function testInvocation() + { + $this->invoker->setCommand(new HelloCommand($this->receiver)); + $this->invoker->run(); + $this->assertEquals($this->receiver->getOutput(), 'Hello World'); + + $messageDateCommand = new AddMessageDateCommand($this->receiver); + $messageDateCommand->execute(); + + $this->invoker->run(); + $this->assertEquals($this->receiver->getOutput(), "Hello World\nHello World [".date('Y-m-d').']'); + + $messageDateCommand->undo(); + + $this->invoker->run(); + $this->assertEquals($this->receiver->getOutput(), "Hello World\nHello World [".date('Y-m-d')."]\nHello World"); + } +} diff --git a/Behavioral/Command/UndoableCommandInterface.php b/Behavioral/Command/UndoableCommandInterface.php new file mode 100644 index 0000000..f9234ab --- /dev/null +++ b/Behavioral/Command/UndoableCommandInterface.php @@ -0,0 +1,15 @@ +getTitle() . ' by ' . $this->getAuthor(); + return $this->getTitle().' by '.$this->getAuthor(); } } diff --git a/Behavioral/Iterator/BookList.php b/Behavioral/Iterator/BookList.php index 6fcf265..6cc5e5e 100644 --- a/Behavioral/Iterator/BookList.php +++ b/Behavioral/Iterator/BookList.php @@ -4,23 +4,20 @@ namespace DesignPatterns\Behavioral\Iterator; class BookList implements \Countable { - private $books; public function getBook($bookNumberToGet) { - if ((int)$bookNumberToGet <= $this->count()) { + if (isset($this->books[$bookNumberToGet])) { return $this->books[$bookNumberToGet]; } - return null; + return; } public function addBook(Book $book) { $this->books[] = $book; - - return $this->count(); } public function removeBook(Book $bookToRemove) @@ -31,8 +28,6 @@ class BookList implements \Countable unset($this->books[$key]); } } - - return $this->count(); } public function count() diff --git a/Behavioral/Iterator/BookListIterator.php b/Behavioral/Iterator/BookListIterator.php index bc15ffb..ecedba6 100644 --- a/Behavioral/Iterator/BookListIterator.php +++ b/Behavioral/Iterator/BookListIterator.php @@ -4,11 +4,10 @@ namespace DesignPatterns\Behavioral\Iterator; class BookListIterator implements \Iterator { - /** * @var BookList */ - protected $bookList; + private $bookList; /** * @var int @@ -21,8 +20,10 @@ class BookListIterator implements \Iterator } /** - * Return the current book + * Return the current book. + * * @link http://php.net/manual/en/iterator.current.php + * * @return Book Can return any type. */ public function current() @@ -32,8 +33,10 @@ class BookListIterator implements \Iterator /** * (PHP 5 >= 5.0.0)
- * Move forward to next element + * Move forward to next element. + * * @link http://php.net/manual/en/iterator.next.php + * * @return void Any returned value is ignored. */ public function next() @@ -43,8 +46,10 @@ class BookListIterator implements \Iterator /** * (PHP 5 >= 5.0.0)
- * Return the key of the current element + * Return the key of the current element. + * * @link http://php.net/manual/en/iterator.key.php + * * @return mixed scalar on success, or null on failure. */ public function key() @@ -54,20 +59,24 @@ class BookListIterator implements \Iterator /** * (PHP 5 >= 5.0.0)
- * Checks if current position is valid + * Checks if current position is valid. + * * @link http://php.net/manual/en/iterator.valid.php - * @return boolean The return value will be casted to boolean and then evaluated. - * Returns true on success or false on failure. + * + * @return bool The return value will be casted to boolean and then evaluated. + * Returns true on success or false on failure. */ public function valid() { - return $this->currentBook < $this->bookList->count(); + return null !== $this->bookList->getBook($this->currentBook); } /** * (PHP 5 >= 5.0.0)
- * Rewind the Iterator to the first element + * Rewind the Iterator to the first element. + * * @link http://php.net/manual/en/iterator.rewind.php + * * @return void Any returned value is ignored. */ public function rewind() diff --git a/Behavioral/Iterator/BookListReverseIterator.php b/Behavioral/Iterator/BookListReverseIterator.php index 973bd0b..94f34d9 100644 --- a/Behavioral/Iterator/BookListReverseIterator.php +++ b/Behavioral/Iterator/BookListReverseIterator.php @@ -2,8 +2,17 @@ namespace DesignPatterns\Behavioral\Iterator; -class BookListReverseIterator extends BookListIterator +class BookListReverseIterator implements \Iterator { + /** + * @var BookList + */ + private $bookList; + + /** + * @var int + */ + protected $currentBook = 0; public function __construct(BookList $bookList) { @@ -11,13 +20,68 @@ class BookListReverseIterator extends BookListIterator $this->currentBook = $this->bookList->count() - 1; } + /** + * Return the current book. + * + * @link http://php.net/manual/en/iterator.current.php + * + * @return Book Can return any type. + */ + public function current() + { + return $this->bookList->getBook($this->currentBook); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Move forward to next element. + * + * @link http://php.net/manual/en/iterator.next.php + * + * @return void Any returned value is ignored. + */ public function next() { $this->currentBook--; } + /** + * (PHP 5 >= 5.0.0)
+ * Return the key of the current element. + * + * @link http://php.net/manual/en/iterator.key.php + * + * @return mixed scalar on success, or null on failure. + */ + public function key() + { + return $this->currentBook; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Checks if current position is valid. + * + * @link http://php.net/manual/en/iterator.valid.php + * + * @return bool The return value will be casted to boolean and then evaluated. + * Returns true on success or false on failure. + */ public function valid() { - return 0 <= $this->currentBook; + return null !== $this->bookList->getBook($this->currentBook); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Rewind the Iterator to the first element. + * + * @link http://php.net/manual/en/iterator.rewind.php + * + * @return void Any returned value is ignored. + */ + public function rewind() + { + $this->currentBook = $this->bookList->count() - 1; } } diff --git a/Behavioral/Iterator/Tests/IteratorTest.php b/Behavioral/Iterator/Tests/IteratorTest.php index 2c5acd9..db386f0 100644 --- a/Behavioral/Iterator/Tests/IteratorTest.php +++ b/Behavioral/Iterator/Tests/IteratorTest.php @@ -9,7 +9,6 @@ use DesignPatterns\Behavioral\Iterator\BookListReverseIterator; class IteratorTest extends \PHPUnit_Framework_TestCase { - /** * @var BookList */ @@ -30,8 +29,8 @@ class IteratorTest extends \PHPUnit_Framework_TestCase array( 'Learning PHP Design Patterns by William Sanders', 'Professional Php Design Patterns by Aaron Saray', - 'Clean Code by Robert C. Martin' - ) + 'Clean Code by Robert C. Martin', + ), ), ); } @@ -65,7 +64,7 @@ class IteratorTest extends \PHPUnit_Framework_TestCase } /** - * Test BookList Remove + * Test BookList Remove. */ public function testBookRemove() { diff --git a/Behavioral/Mediator/Colleague.php b/Behavioral/Mediator/Colleague.php index c0ff248..c74dee5 100644 --- a/Behavioral/Mediator/Colleague.php +++ b/Behavioral/Mediator/Colleague.php @@ -9,12 +9,12 @@ namespace DesignPatterns\Behavioral\Mediator; abstract class Colleague { /** - * this ensures no change in subclasses + * this ensures no change in subclasses. * * @var MediatorInterface */ private $mediator; - + /** * @param MediatorInterface $medium */ @@ -25,6 +25,7 @@ abstract class Colleague } // for subclasses + protected function getMediator() { return $this->mediator; diff --git a/Behavioral/Mediator/Mediator.php b/Behavioral/Mediator/Mediator.php index ba1407e..98a7890 100644 --- a/Behavioral/Mediator/Mediator.php +++ b/Behavioral/Mediator/Mediator.php @@ -2,15 +2,12 @@ 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 */ @@ -39,7 +36,7 @@ class Mediator implements MediatorInterface } /** - * make request + * make request. */ public function makeRequest() { @@ -47,7 +44,8 @@ class Mediator implements MediatorInterface } /** - * query db + * query db. + * * @return mixed */ public function queryDb() @@ -56,7 +54,7 @@ class Mediator implements MediatorInterface } /** - * send response + * send response. * * @param string $content */ diff --git a/Behavioral/Mediator/MediatorInterface.php b/Behavioral/Mediator/MediatorInterface.php index b289cea..dbdd489 100644 --- a/Behavioral/Mediator/MediatorInterface.php +++ b/Behavioral/Mediator/MediatorInterface.php @@ -4,24 +4,24 @@ namespace DesignPatterns\Behavioral\Mediator; /** * MediatorInterface is a contract for the Mediator - * This interface is not mandatory but it is better for LSP concerns + * This interface is not mandatory but it is better for LSP concerns. */ interface MediatorInterface { /** - * sends the response + * sends the response. * * @param string $content */ public function sendResponse($content); /** - * makes a request + * makes a request. */ public function makeRequest(); /** - * queries the DB + * queries the DB. */ public function queryDb(); } diff --git a/Behavioral/Mediator/README.rst b/Behavioral/Mediator/README.rst index 1a596d7..bc9485a 100644 --- a/Behavioral/Mediator/README.rst +++ b/Behavioral/Mediator/README.rst @@ -4,8 +4,8 @@ Purpose ------- -This pattern provides an easy to decouple many components working -together. It is a good alternative over Observer IF you have a "central +This pattern provides an easy way to decouple many components working +together. It is a good alternative to Observer IF you have a "central intelligence", like a controller (but not in the sense of the MVC). All components (called Colleague) are only coupled to the @@ -70,4 +70,4 @@ Tests/MediatorTest.php :linenos: .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Mediator -.. __: http://en.wikipedia.org/wiki/Mediator_pattern \ No newline at end of file +.. __: http://en.wikipedia.org/wiki/Mediator_pattern diff --git a/Behavioral/Mediator/Subsystem/Client.php b/Behavioral/Mediator/Subsystem/Client.php index cb4b020..f7a21c9 100644 --- a/Behavioral/Mediator/Subsystem/Client.php +++ b/Behavioral/Mediator/Subsystem/Client.php @@ -5,12 +5,12 @@ namespace DesignPatterns\Behavioral\Mediator\Subsystem; use DesignPatterns\Behavioral\Mediator\Colleague; /** - * Client is a client that make request et get response + * Client is a client that make request et get response. */ class Client extends Colleague { /** - * request + * request. */ public function request() { @@ -18,7 +18,7 @@ class Client extends Colleague } /** - * output content + * output content. * * @param string $content */ diff --git a/Behavioral/Mediator/Subsystem/Database.php b/Behavioral/Mediator/Subsystem/Database.php index 7cc9bc4..69ad6cf 100644 --- a/Behavioral/Mediator/Subsystem/Database.php +++ b/Behavioral/Mediator/Subsystem/Database.php @@ -5,7 +5,7 @@ namespace DesignPatterns\Behavioral\Mediator\Subsystem; use DesignPatterns\Behavioral\Mediator\Colleague; /** - * Database is a database service + * Database is a database service. */ class Database extends Colleague { @@ -14,6 +14,6 @@ class Database extends Colleague */ public function getData() { - return "World"; + return 'World'; } } diff --git a/Behavioral/Mediator/Subsystem/Server.php b/Behavioral/Mediator/Subsystem/Server.php index 1638301..1602bcb 100644 --- a/Behavioral/Mediator/Subsystem/Server.php +++ b/Behavioral/Mediator/Subsystem/Server.php @@ -5,12 +5,12 @@ namespace DesignPatterns\Behavioral\Mediator\Subsystem; use DesignPatterns\Behavioral\Mediator\Colleague; /** - * Server serves responses + * Server serves responses. */ class Server extends Colleague { /** - * process on server + * process on server. */ public function process() { diff --git a/Behavioral/Mediator/Tests/MediatorTest.php b/Behavioral/Mediator/Tests/MediatorTest.php index 13abe48..2bce947 100644 --- a/Behavioral/Mediator/Tests/MediatorTest.php +++ b/Behavioral/Mediator/Tests/MediatorTest.php @@ -3,16 +3,15 @@ namespace DesignPatterns\Tests\Mediator\Tests; use DesignPatterns\Behavioral\Mediator\Mediator; -use DesignPatterns\Behavioral\Mediator\Subsystem\Database; use DesignPatterns\Behavioral\Mediator\Subsystem\Client; +use DesignPatterns\Behavioral\Mediator\Subsystem\Database; use DesignPatterns\Behavioral\Mediator\Subsystem\Server; /** - * MediatorTest tests hello world + * MediatorTest tests hello world. */ class MediatorTest extends \PHPUnit_Framework_TestCase { - protected $client; protected function setUp() diff --git a/Behavioral/Memento/Caretaker.php b/Behavioral/Memento/Caretaker.php index 340bb97..d80454a 100644 --- a/Behavioral/Memento/Caretaker.php +++ b/Behavioral/Memento/Caretaker.php @@ -4,30 +4,46 @@ namespace DesignPatterns\Behavioral\Memento; class Caretaker { - public static function run() + protected $history = array(); + + /** + * @return Memento + */ + public function getFromHistory($id) { - /* @var $savedStates Memento[] */ + return $this->history[$id]; + } - $savedStates = array(); + /** + * @param Memento $state + */ + public function saveToHistory(Memento $state) + { + $this->history[] = $state; + } + public function runCustomLogic() + { $originator = new Originator(); //Setting state to State1 - $originator->setState("State1"); + $originator->setState('State1'); //Setting state to State2 - $originator->setState("State2"); + $originator->setState('State2'); //Saving State2 to Memento - $savedStates[] = $originator->saveToMemento(); + $this->saveToHistory($originator->getStateAsMemento()); //Setting state to State3 - $originator->setState("State3"); + $originator->setState('State3'); // We can request multiple mementos, and choose which one to roll back to. // Saving State3 to Memento - $savedStates[] = $originator->saveToMemento(); + $this->saveToHistory($originator->getStateAsMemento()); //Setting state to State4 - $originator->setState("State4"); + $originator->setState('State4'); - $originator->restoreFromMemento($savedStates[1]); + $originator->restoreFromMemento($this->getFromHistory(1)); //State after restoring from Memento: State3 + + return $originator->getStateAsMemento()->getState(); } } diff --git a/Behavioral/Memento/Originator.php b/Behavioral/Memento/Originator.php index fec4e45..3acb0c1 100644 --- a/Behavioral/Memento/Originator.php +++ b/Behavioral/Memento/Originator.php @@ -15,14 +15,17 @@ class Originator */ public function setState($state) { + // you must check type of state inside child of this class + // or use type-hinting for full pattern implementation $this->state = $state; } /** * @return Memento */ - public function saveToMemento() + public function getStateAsMemento() { + // you must save a separate copy in Memento $state = is_object($this->state) ? clone $this->state : $this->state; return new Memento($state); diff --git a/Behavioral/Memento/README.rst b/Behavioral/Memento/README.rst index 6696149..911e30e 100644 --- a/Behavioral/Memento/README.rst +++ b/Behavioral/Memento/README.rst @@ -4,26 +4,43 @@ Purpose ------- -Provide the ability to restore an object to its previous state (undo via -rollback). +It provides the ability to restore an object to it's previous state (undo +via rollback) or to gain access to state of the object, without revealing +it's implementation (i.e., the object is not required to have a functional +for return the current state). -The memento pattern is implemented with three objects: the originator, a -caretaker and a memento. The originator is some object that has an -internal state. The caretaker is going to do something to the -originator, but wants to be able to undo the change. The caretaker first -asks the originator for a memento object. Then it does whatever -operation (or sequence of operations) it was going to do. To roll back -to the state before the operations, it returns the memento object to the -originator. The memento object itself is an opaque object (one which the -caretaker cannot, or should not, change). When using this pattern, care -should be taken if the originator may change other objects or resources -- the memento pattern operates on a single object. +The memento pattern is implemented with three objects: the Originator, a +Caretaker and a Memento. + +Memento – an object that *contains a concrete unique snapshot of state* of +any object or resource: string, number, array, an instance of class and so on. +The uniqueness in this case does not imply the prohibition existence of similar +states in different snapshots. That means the state can be extracted as +the independent clone. Any object stored in the Memento should be +*a full copy of the original object rather than a reference* to the original +object. The Memento object is a "opaque object" (the object that no one can +or should change). + +Originator – it is an object that contains the *actual state of an external +object is strictly specified type*. Originator is able to create a unique +copy of this state and return it wrapped in a Memento. The Originator does +not know the history of changes. You can set a concrete state to Originator +from the outside, which will be considered as actual. The Originator must +make sure that given state corresponds the allowed type of object. Originator +may (but not should) have any methods, but they *they can't make changes to +the saved object state*. + +Caretaker *controls the states history*. He may make changes to an object; +take a decision to save the state of an external object in the Originator; +ask from the Originator snapshot of the current state; or set the Originator +state to equivalence with some snapshot from history. Examples -------- - The seed of a pseudorandom number generator - The state in a finite state machine +- Control for intermediate states of `ORM Model `_ before saving UML Diagram ----------- diff --git a/Behavioral/Memento/Tests/MementoTest.php b/Behavioral/Memento/Tests/MementoTest.php index 88110a6..722dbfa 100644 --- a/Behavioral/Memento/Tests/MementoTest.php +++ b/Behavioral/Memento/Tests/MementoTest.php @@ -2,68 +2,161 @@ namespace DesignPatterns\Behavioral\Memento\Tests; +use DesignPatterns\Behavioral\Memento\Caretaker; +use DesignPatterns\Behavioral\Memento\Memento; use DesignPatterns\Behavioral\Memento\Originator; /** - * MementoTest tests the memento pattern + * MementoTest tests the memento pattern. */ class MementoTest extends \PHPUnit_Framework_TestCase { + public function testUsageExample() + { + $originator = new Originator(); + $caretaker = new Caretaker(); + + $character = new \stdClass(); + // new object + $character->name = 'Gandalf'; + // connect Originator to character object + $originator->setState($character); + + // work on the object + $character->name = 'Gandalf the Grey'; + // still change something + $character->race = 'Maia'; + // time to save state + $snapshot = $originator->getStateAsMemento(); + // put state to log + $caretaker->saveToHistory($snapshot); + + // change something + $character->name = 'Sauron'; + // and again + $character->race = 'Ainur'; + // state inside the Originator was equally changed + $this->assertAttributeEquals($character, 'state', $originator); + + // time to save another state + $snapshot = $originator->getStateAsMemento(); + // put state to log + $caretaker->saveToHistory($snapshot); + + $rollback = $caretaker->getFromHistory(0); + // return to first state + $originator->restoreFromMemento($rollback); + // use character from old state + $character = $rollback->getState(); + + // yes, that what we need + $this->assertEquals('Gandalf the Grey', $character->name); + // make new changes + $character->name = 'Gandalf the White'; + + // and Originator linked to actual object again + $this->assertAttributeEquals($character, 'state', $originator); + } public function testStringState() { $originator = new Originator(); - $originator->setState("State1"); + $originator->setState('State1'); - $this->assertAttributeEquals("State1", "state", $originator); + $this->assertAttributeEquals('State1', 'state', $originator); - $originator->setState("State2"); + $originator->setState('State2'); + $this->assertAttributeEquals('State2', 'state', $originator); - $this->assertAttributeEquals("State2", "state", $originator); + $snapshot = $originator->getStateAsMemento(); + $this->assertAttributeEquals('State2', 'state', $snapshot); - $savedState = $originator->saveToMemento(); + $originator->setState('State3'); + $this->assertAttributeEquals('State3', 'state', $originator); - $this->assertAttributeEquals("State2", "state", $savedState); - - $originator->setState("State3"); - - $this->assertAttributeEquals("State3", "state", $originator); - - $originator->restoreFromMemento($savedState); - - $this->assertAttributeEquals("State2", "state", $originator); + $originator->restoreFromMemento($snapshot); + $this->assertAttributeEquals('State2', 'state', $originator); } - public function testObjectState() + public function testSnapshotIsClone() + { + $originator = new Originator(); + $object = new \stdClass(); + + $originator->setState($object); + $snapshot = $originator->getStateAsMemento(); + $object->new_property = 1; + + $this->assertAttributeEquals($object, 'state', $originator); + $this->assertAttributeNotEquals($object, 'state', $snapshot); + + $originator->restoreFromMemento($snapshot); + $this->assertAttributeNotEquals($object, 'state', $originator); + } + + public function testCanChangeActualState() + { + $originator = new Originator(); + $first_state = new \stdClass(); + + $originator->setState($first_state); + $snapshot = $originator->getStateAsMemento(); + $second_state = $snapshot->getState(); + + // still actual + $first_state->first_property = 1; + // just history + $second_state->second_property = 2; + $this->assertAttributeEquals($first_state, 'state', $originator); + $this->assertAttributeNotEquals($second_state, 'state', $originator); + + $originator->restoreFromMemento($snapshot); + // now it lost state + $first_state->first_property = 11; + // must be actual + $second_state->second_property = 22; + $this->assertAttributeEquals($second_state, 'state', $originator); + $this->assertAttributeNotEquals($first_state, 'state', $originator); + } + + public function testStateWithDifferentObjects() { $originator = new Originator(); - $foo = new \stdClass(); - $foo->data = "foo"; + $first = new \stdClass(); + $first->data = 'foo'; - $originator->setState($foo); + $originator->setState($first); + $this->assertAttributeEquals($first, 'state', $originator); - $this->assertAttributeEquals($foo, "state", $originator); + $first_snapshot = $originator->getStateAsMemento(); + $this->assertAttributeEquals($first, 'state', $first_snapshot); - $savedState = $originator->saveToMemento(); + $second = new \stdClass(); + $second->data = 'bar'; + $originator->setState($second); + $this->assertAttributeEquals($second, 'state', $originator); - $this->assertAttributeEquals($foo, "state", $savedState); + $originator->restoreFromMemento($first_snapshot); + $this->assertAttributeEquals($first, 'state', $originator); + } - $bar = new \stdClass(); - $bar->data = "bar"; + public function testCaretaker() + { + $caretaker = new Caretaker(); + $memento1 = new Memento('foo'); + $memento2 = new Memento('bar'); + $caretaker->saveToHistory($memento1); + $caretaker->saveToHistory($memento2); + $this->assertAttributeEquals(array($memento1, $memento2), 'history', $caretaker); + $this->assertEquals($memento1, $caretaker->getFromHistory(0)); + $this->assertEquals($memento2, $caretaker->getFromHistory(1)); + } - $originator->setState($bar); - - $this->assertAttributeEquals($bar, "state", $originator); - - $originator->restoreFromMemento($savedState); - - $this->assertAttributeEquals($foo, "state", $originator); - - $foo->data = null; - - $this->assertAttributeNotEquals($foo, "state", $savedState); - - $this->assertAttributeNotEquals($foo, "state", $originator); + public function testCaretakerCustomLogic() + { + $caretaker = new Caretaker(); + $result = $caretaker->runCustomLogic(); + $this->assertEquals('State3', $result); } } diff --git a/Behavioral/Memento/uml/uml.png b/Behavioral/Memento/uml/uml.png index e96ea69..0fde074 100644 Binary files a/Behavioral/Memento/uml/uml.png and b/Behavioral/Memento/uml/uml.png differ diff --git a/Behavioral/NullObject/LoggerInterface.php b/Behavioral/NullObject/LoggerInterface.php index 216d838..99a28c7 100644 --- a/Behavioral/NullObject/LoggerInterface.php +++ b/Behavioral/NullObject/LoggerInterface.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Behavioral\NullObject; /** - * LoggerInterface is a contract for logging something + * LoggerInterface is a contract for logging something. * * Key feature: NullLogger MUST inherit from this interface like any other Loggers */ diff --git a/Behavioral/NullObject/PrintLogger.php b/Behavioral/NullObject/PrintLogger.php index a088145..371c1ab 100644 --- a/Behavioral/NullObject/PrintLogger.php +++ b/Behavioral/NullObject/PrintLogger.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Behavioral\NullObject; /** - * PrintLogger is a logger that prints the log entry to standard output + * PrintLogger is a logger that prints the log entry to standard output. */ class PrintLogger implements LoggerInterface { diff --git a/Behavioral/NullObject/Service.php b/Behavioral/NullObject/Service.php index ae6d96d..56a3847 100644 --- a/Behavioral/NullObject/Service.php +++ b/Behavioral/NullObject/Service.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Behavioral\NullObject; /** - * Service is dummy service that uses a logger + * Service is dummy service that uses a logger. */ class Service { @@ -13,7 +13,7 @@ class Service protected $logger; /** - * we inject the logger in ctor and it is mandatory + * we inject the logger in ctor and it is mandatory. * * @param LoggerInterface $log */ @@ -28,7 +28,7 @@ class Service public function doSomething() { // no more check "if (!is_null($this->logger))..." with the NullObject pattern - $this->logger->log('We are in ' . __METHOD__); + $this->logger->log('We are in '.__METHOD__); // something to do... } } diff --git a/Behavioral/NullObject/Tests/LoggerTest.php b/Behavioral/NullObject/Tests/LoggerTest.php index a8e7bf5..034b577 100644 --- a/Behavioral/NullObject/Tests/LoggerTest.php +++ b/Behavioral/NullObject/Tests/LoggerTest.php @@ -3,15 +3,14 @@ namespace DesignPatterns\Behavioral\NullObject\Tests; use DesignPatterns\Behavioral\NullObject\NullLogger; -use DesignPatterns\Behavioral\NullObject\Service; use DesignPatterns\Behavioral\NullObject\PrintLogger; +use DesignPatterns\Behavioral\NullObject\Service; /** - * LoggerTest tests for different loggers + * LoggerTest tests for different loggers. */ class LoggerTest extends \PHPUnit_Framework_TestCase { - public function testNullObject() { // one can use a singleton for NullObjet : I don't think it's a good idea diff --git a/Behavioral/Observer/Tests/ObserverTest.php b/Behavioral/Observer/Tests/ObserverTest.php index 75490cc..d9dacec 100644 --- a/Behavioral/Observer/Tests/ObserverTest.php +++ b/Behavioral/Observer/Tests/ObserverTest.php @@ -2,15 +2,14 @@ namespace DesignPatterns\Behavioral\Observer\Tests; -use DesignPatterns\Behavioral\Observer\UserObserver; use DesignPatterns\Behavioral\Observer\User; +use DesignPatterns\Behavioral\Observer\UserObserver; /** - * ObserverTest tests the Observer pattern + * ObserverTest tests the Observer pattern. */ class ObserverTest extends \PHPUnit_Framework_TestCase { - protected $observer; protected function setUp() @@ -19,7 +18,7 @@ class ObserverTest extends \PHPUnit_Framework_TestCase } /** - * Tests the notification + * Tests the notification. */ public function testNotify() { @@ -31,7 +30,7 @@ class ObserverTest extends \PHPUnit_Framework_TestCase } /** - * Tests the subscribing + * Tests the subscribing. */ public function testAttachDetach() { @@ -53,7 +52,7 @@ class ObserverTest extends \PHPUnit_Framework_TestCase } /** - * Tests the update() invocation on a mockup + * Tests the update() invocation on a mockup. */ public function testUpdateCalling() { diff --git a/Behavioral/Observer/User.php b/Behavioral/Observer/User.php index 213f229..0d2a817 100644 --- a/Behavioral/Observer/User.php +++ b/Behavioral/Observer/User.php @@ -3,34 +3,33 @@ namespace DesignPatterns\Behavioral\Observer; /** - * Observer pattern : The observed object (the subject) + * Observer pattern : The observed object (the subject). * * The subject maintains a list of Observers and sends notifications. - * */ class User implements \SplSubject { /** - * user data + * user data. * * @var array */ protected $data = array(); /** - * observers + * observers. * * @var \SplObjectStorage */ protected $observers; - + public function __construct() { $this->observers = new \SplObjectStorage(); } /** - * attach a new observer + * attach a new observer. * * @param \SplObserver $observer * @@ -42,7 +41,7 @@ class User implements \SplSubject } /** - * detach an observer + * detach an observer. * * @param \SplObserver $observer * @@ -54,7 +53,7 @@ class User implements \SplSubject } /** - * notify observers + * notify observers. * * @return void */ @@ -68,7 +67,7 @@ class User implements \SplSubject /** * Ideally one would better write setter/getter for all valid attributes and only call notify() - * on attributes that matter when changed + * on attributes that matter when changed. * * @param string $name * @param mixed $value diff --git a/Behavioral/Observer/UserObserver.php b/Behavioral/Observer/UserObserver.php index f444604..f2673ba 100644 --- a/Behavioral/Observer/UserObserver.php +++ b/Behavioral/Observer/UserObserver.php @@ -3,18 +3,18 @@ namespace DesignPatterns\Behavioral\Observer; /** - * class UserObserver + * class UserObserver. */ class UserObserver implements \SplObserver { /** * This is the only method to implement as an observer. - * It is called by the Subject (usually by SplSubject::notify() ) + * It is called by the Subject (usually by SplSubject::notify() ). * * @param \SplSubject $subject */ public function update(\SplSubject $subject) { - echo get_class($subject) . ' has been updated'; + echo get_class($subject).' has been updated'; } } diff --git a/Behavioral/README.md b/Behavioral/README.md index bdf7316..b98202b 100644 --- a/Behavioral/README.md +++ b/Behavioral/README.md @@ -9,7 +9,7 @@ communication. * [Command](Command) [:notebook:](http://en.wikipedia.org/wiki/Command_pattern) * [Iterator](Iterator) [:notebook:](http://en.wikipedia.org/wiki/Iterator_pattern) * [Mediator](Mediator) [:notebook:](http://en.wikipedia.org/wiki/Mediator_pattern) -* [Memento](Behavioral/Memento) [:notebook:](http://en.wikipedia.org/wiki/Memento_pattern) +* [Memento](Memento) [:notebook:](http://en.wikipedia.org/wiki/Memento_pattern) * [NullObject](NullObject) [:notebook:](http://en.wikipedia.org/wiki/Null_Object_pattern) * [Observer](Observer) [:notebook:](http://en.wikipedia.org/wiki/Observer_pattern) * [Specification](Specification) [:notebook:](http://en.wikipedia.org/wiki/Specification_pattern) diff --git a/Behavioral/Specification/AbstractSpecification.php b/Behavioral/Specification/AbstractSpecification.php index f297539..66d61b8 100644 --- a/Behavioral/Specification/AbstractSpecification.php +++ b/Behavioral/Specification/AbstractSpecification.php @@ -1,13 +1,14 @@ comparator) { - throw new \LogicException("Comparator is not set"); + throw new \LogicException('Comparator is not set'); } $callback = array($this->comparator, 'compare'); diff --git a/Behavioral/Strategy/Tests/StrategyTest.php b/Behavioral/Strategy/Tests/StrategyTest.php index 4831b18..1911ba4 100644 --- a/Behavioral/Strategy/Tests/StrategyTest.php +++ b/Behavioral/Strategy/Tests/StrategyTest.php @@ -8,21 +8,20 @@ use DesignPatterns\Behavioral\Strategy\ObjectCollection; use DesignPatterns\Behavioral\Strategy\Strategy; /** - * Tests for Strategy pattern + * Tests for Strategy pattern. */ class StrategyTest extends \PHPUnit_Framework_TestCase { - public function getIdCollection() { return array( array( array(array('id' => 2), array('id' => 1), array('id' => 3)), - array('id' => 1) + array('id' => 1), ), array( array(array('id' => 3), array('id' => 2), array('id' => 1)), - array('id' => 1) + array('id' => 1), ), ); } @@ -32,11 +31,11 @@ class StrategyTest extends \PHPUnit_Framework_TestCase return array( array( array(array('date' => '2014-03-03'), array('date' => '2015-03-02'), array('date' => '2013-03-01')), - array('date' => '2013-03-01') + array('date' => '2013-03-01'), ), array( array(array('date' => '2014-02-03'), array('date' => '2013-02-01'), array('date' => '2015-02-02')), - array('date' => '2013-02-01') + array('date' => '2013-02-01'), ), ); } diff --git a/Behavioral/TemplateMethod/BeachJourney.php b/Behavioral/TemplateMethod/BeachJourney.php index 94018f3..d19845c 100644 --- a/Behavioral/TemplateMethod/BeachJourney.php +++ b/Behavioral/TemplateMethod/BeachJourney.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Behavioral\TemplateMethod; /** - * BeachJourney is vacation at the beach + * BeachJourney is vacation at the beach. */ class BeachJourney extends Journey { /** - * prints what to do to enjoy your vacation + * prints what to do to enjoy your vacation. */ protected function enjoyVacation() { diff --git a/Behavioral/TemplateMethod/CityJourney.php b/Behavioral/TemplateMethod/CityJourney.php index 89c2ef0..3f36b61 100644 --- a/Behavioral/TemplateMethod/CityJourney.php +++ b/Behavioral/TemplateMethod/CityJourney.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Behavioral\TemplateMethod; /** - * CityJourney is a journey in a city + * CityJourney is a journey in a city. */ class CityJourney extends Journey { /** - * prints what to do in your journey to enjoy vacation + * prints what to do in your journey to enjoy vacation. */ protected function enjoyVacation() { diff --git a/Behavioral/TemplateMethod/Journey.php b/Behavioral/TemplateMethod/Journey.php index cec9a7d..6309e7f 100644 --- a/Behavioral/TemplateMethod/Journey.php +++ b/Behavioral/TemplateMethod/Journey.php @@ -23,7 +23,7 @@ abstract class Journey } /** - * This method must be implemented, this is the key-feature of this pattern + * This method must be implemented, this is the key-feature of this pattern. */ abstract protected function enjoyVacation(); @@ -37,7 +37,7 @@ abstract class Journey } /** - * This method will be unknown by subclasses (better) + * This method will be unknown by subclasses (better). */ private function buyAFlight() { @@ -46,7 +46,7 @@ abstract class Journey /** * Subclasses will get access to this method but cannot override it and - * compromise this algorithm (warning : cause of cyclic dependencies) + * compromise this algorithm (warning : cause of cyclic dependencies). */ final protected function takePlane() { diff --git a/Behavioral/TemplateMethod/Tests/JourneyTest.php b/Behavioral/TemplateMethod/Tests/JourneyTest.php index d0b134c..82acef3 100644 --- a/Behavioral/TemplateMethod/Tests/JourneyTest.php +++ b/Behavioral/TemplateMethod/Tests/JourneyTest.php @@ -5,11 +5,10 @@ namespace DesignPatterns\Behavioral\TemplateMethod\Tests; use DesignPatterns\Behavioral\TemplateMethod; /** - * JourneyTest tests all journeys + * JourneyTest tests all journeys. */ class JourneyTest extends \PHPUnit_Framework_TestCase { - public function testBeach() { $journey = new TemplateMethod\BeachJourney(); @@ -25,7 +24,7 @@ class JourneyTest extends \PHPUnit_Framework_TestCase } /** - * How to test an abstract template method with PHPUnit + * How to test an abstract template method with PHPUnit. */ public function testLasVegas() { diff --git a/Behavioral/Visitor/Group.php b/Behavioral/Visitor/Group.php index 3990f9c..b2c9d90 100644 --- a/Behavioral/Visitor/Group.php +++ b/Behavioral/Visitor/Group.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Behavioral\Visitor; /** - * An example of a Visitor: Group + * An example of a Visitor: Group. */ class Group extends Role { @@ -25,6 +25,6 @@ class Group extends Role */ public function getName() { - return "Group: " . $this->name; + return 'Group: '.$this->name; } } diff --git a/Behavioral/Visitor/Role.php b/Behavioral/Visitor/Role.php index fd0d0a4..011a0fb 100644 --- a/Behavioral/Visitor/Role.php +++ b/Behavioral/Visitor/Role.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Behavioral\Visitor; /** - * class Role + * class Role. */ abstract class Role { /** - * This method handles a double dispatch based on the short name of the Visitor + * This method handles a double dispatch based on the short name of the Visitor. * * Feel free to override it if your object must call another visiting behavior * @@ -21,10 +21,10 @@ abstract class Role // this trick to simulate double-dispatch based on type-hinting $klass = get_called_class(); preg_match('#([^\\\\]+)$#', $klass, $extract); - $visitingMethod = 'visit' . $extract[1]; + $visitingMethod = 'visit'.$extract[1]; // this ensures strong typing with visitor interface, not some visitor objects - if (!method_exists(__NAMESPACE__ . '\RoleVisitorInterface', $visitingMethod)) { + if (!method_exists(__NAMESPACE__.'\RoleVisitorInterface', $visitingMethod)) { throw new \InvalidArgumentException("The visitor you provide cannot visit a $klass instance"); } diff --git a/Behavioral/Visitor/RolePrintVisitor.php b/Behavioral/Visitor/RolePrintVisitor.php index 5f07d5c..49777cf 100644 --- a/Behavioral/Visitor/RolePrintVisitor.php +++ b/Behavioral/Visitor/RolePrintVisitor.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Behavioral\Visitor; /** - * Visitor Pattern + * Visitor Pattern. * * An implementation of a concrete Visitor */ @@ -14,7 +14,7 @@ class RolePrintVisitor implements RoleVisitorInterface */ public function visitGroup(Group $role) { - echo "Role: " . $role->getName(); + echo 'Role: '.$role->getName(); } /** @@ -22,6 +22,6 @@ class RolePrintVisitor implements RoleVisitorInterface */ public function visitUser(User $role) { - echo "Role: " . $role->getName(); + echo 'Role: '.$role->getName(); } } diff --git a/Behavioral/Visitor/RoleVisitorInterface.php b/Behavioral/Visitor/RoleVisitorInterface.php index b007b13..e8ba0ec 100644 --- a/Behavioral/Visitor/RoleVisitorInterface.php +++ b/Behavioral/Visitor/RoleVisitorInterface.php @@ -3,11 +3,11 @@ namespace DesignPatterns\Behavioral\Visitor; /** - * Visitor Pattern + * Visitor Pattern. * * The contract for the visitor. * - * Note 1 : in C++ or java, with method polymorphism based on type-hint, there are many + * Note 1 : in C++ or Java, with method polymorphism based on type-hint, there are many * methods visit() with different type for the 'role' parameter. * * Note 2 : the visitor must not choose itself which method to @@ -16,14 +16,14 @@ namespace DesignPatterns\Behavioral\Visitor; interface RoleVisitorInterface { /** - * Visit a User object + * Visit a User object. * * @param \DesignPatterns\Behavioral\Visitor\User $role */ public function visitUser(User $role); /** - * Visit a Group object + * Visit a Group object. * * @param \DesignPatterns\Behavioral\Visitor\Group $role */ diff --git a/Behavioral/Visitor/Tests/VisitorTest.php b/Behavioral/Visitor/Tests/VisitorTest.php index 6d71658..f3b5bc7 100644 --- a/Behavioral/Visitor/Tests/VisitorTest.php +++ b/Behavioral/Visitor/Tests/VisitorTest.php @@ -5,11 +5,10 @@ namespace DesignPatterns\Tests\Visitor\Tests; use DesignPatterns\Behavioral\Visitor; /** - * VisitorTest tests the visitor pattern + * VisitorTest tests the visitor pattern. */ class VisitorTest extends \PHPUnit_Framework_TestCase { - protected $visitor; protected function setUp() @@ -20,8 +19,8 @@ class VisitorTest extends \PHPUnit_Framework_TestCase public function getRole() { return array( - array(new Visitor\User("Dominik"), 'Role: User Dominik'), - array(new Visitor\Group("Administrators"), 'Role: Group: Administrators') + array(new Visitor\User('Dominik'), 'Role: User Dominik'), + array(new Visitor\Group('Administrators'), 'Role: Group: Administrators'), ); } diff --git a/Behavioral/Visitor/User.php b/Behavioral/Visitor/User.php index e0cc4c7..5a95fbe 100644 --- a/Behavioral/Visitor/User.php +++ b/Behavioral/Visitor/User.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Behavioral\Visitor; /** - * Visitor Pattern + * Visitor Pattern. * * One example for a visitee. Each visitee has to extends Role */ @@ -27,6 +27,6 @@ class User extends Role */ public function getName() { - return "User " . $this->name; + return 'User '.$this->name; } } diff --git a/Creational/AbstractFactory/AbstractFactory.php b/Creational/AbstractFactory/AbstractFactory.php index 49982e5..6529ff6 100644 --- a/Creational/AbstractFactory/AbstractFactory.php +++ b/Creational/AbstractFactory/AbstractFactory.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\AbstractFactory; /** - * class AbstractFactory + * class AbstractFactory. * * Sometimes also known as "Kit" in a GUI libraries. * @@ -20,7 +20,7 @@ namespace DesignPatterns\Creational\AbstractFactory; abstract class AbstractFactory { /** - * Creates a text component + * Creates a text component. * * @param string $content * @@ -29,7 +29,7 @@ abstract class AbstractFactory abstract public function createText($content); /** - * Creates a picture component + * Creates a picture component. * * @param string $path * @param string $name diff --git a/Creational/AbstractFactory/Html/Picture.php b/Creational/AbstractFactory/Html/Picture.php index 9d7f440..3abacb4 100644 --- a/Creational/AbstractFactory/Html/Picture.php +++ b/Creational/AbstractFactory/Html/Picture.php @@ -5,14 +5,14 @@ namespace DesignPatterns\Creational\AbstractFactory\Html; use DesignPatterns\Creational\AbstractFactory\Picture as BasePicture; /** - * Class Picture + * Class Picture. * * Picture is a concrete image for HTML rendering */ class Picture extends BasePicture { /** - * some crude rendering from HTML output + * some crude rendering from HTML output. * * @return string */ diff --git a/Creational/AbstractFactory/Html/Text.php b/Creational/AbstractFactory/Html/Text.php index 120c043..8c33da6 100644 --- a/Creational/AbstractFactory/Html/Text.php +++ b/Creational/AbstractFactory/Html/Text.php @@ -5,19 +5,19 @@ namespace DesignPatterns\Creational\AbstractFactory\Html; use DesignPatterns\Creational\AbstractFactory\Text as BaseText; /** - * Class Text + * Class Text. * * Text is a concrete text for HTML rendering */ class Text extends BaseText { /** - * some crude rendering from HTML output + * some crude rendering from HTML output. * * @return string */ public function render() { - return '
' . htmlspecialchars($this->text) . '
'; + return '
'.htmlspecialchars($this->text).'
'; } } diff --git a/Creational/AbstractFactory/HtmlFactory.php b/Creational/AbstractFactory/HtmlFactory.php index 7982a24..5c22859 100644 --- a/Creational/AbstractFactory/HtmlFactory.php +++ b/Creational/AbstractFactory/HtmlFactory.php @@ -3,14 +3,14 @@ namespace DesignPatterns\Creational\AbstractFactory; /** - * Class HtmlFactory + * Class HtmlFactory. * * HtmlFactory is a concrete factory for HTML component */ class HtmlFactory extends AbstractFactory { /** - * Creates a picture component + * Creates a picture component. * * @param string $path * @param string $name @@ -23,7 +23,7 @@ class HtmlFactory extends AbstractFactory } /** - * Creates a text component + * Creates a text component. * * @param string $content * diff --git a/Creational/AbstractFactory/Json/Picture.php b/Creational/AbstractFactory/Json/Picture.php index 13d191b..77bb150 100644 --- a/Creational/AbstractFactory/Json/Picture.php +++ b/Creational/AbstractFactory/Json/Picture.php @@ -5,14 +5,14 @@ namespace DesignPatterns\Creational\AbstractFactory\Json; use DesignPatterns\Creational\AbstractFactory\Picture as BasePicture; /** - * Class Picture + * Class Picture. * * Picture is a concrete image for JSON rendering */ class Picture extends BasePicture { /** - * some crude rendering from JSON output + * some crude rendering from JSON output. * * @return string */ diff --git a/Creational/AbstractFactory/Json/Text.php b/Creational/AbstractFactory/Json/Text.php index 699fff3..4c51785 100644 --- a/Creational/AbstractFactory/Json/Text.php +++ b/Creational/AbstractFactory/Json/Text.php @@ -5,14 +5,14 @@ namespace DesignPatterns\Creational\AbstractFactory\Json; use DesignPatterns\Creational\AbstractFactory\Text as BaseText; /** - * Class Text + * Class Text. * * Text is a text component with a JSON rendering */ class Text extends BaseText { /** - * some crude rendering from JSON output + * some crude rendering from JSON output. * * @return string */ diff --git a/Creational/AbstractFactory/JsonFactory.php b/Creational/AbstractFactory/JsonFactory.php index ab2bb6f..63a9979 100644 --- a/Creational/AbstractFactory/JsonFactory.php +++ b/Creational/AbstractFactory/JsonFactory.php @@ -3,16 +3,15 @@ namespace DesignPatterns\Creational\AbstractFactory; /** - * Class JsonFactory + * Class JsonFactory. * * JsonFactory is a factory for creating a family of JSON component * (example for ajax) */ class JsonFactory extends AbstractFactory { - /** - * Creates a picture component + * Creates a picture component. * * @param string $path * @param string $name @@ -25,7 +24,7 @@ class JsonFactory extends AbstractFactory } /** - * Creates a text component + * Creates a text component. * * @param string $content * diff --git a/Creational/AbstractFactory/MediaInterface.php b/Creational/AbstractFactory/MediaInterface.php index 6bb5d3a..aa73f1b 100644 --- a/Creational/AbstractFactory/MediaInterface.php +++ b/Creational/AbstractFactory/MediaInterface.php @@ -3,16 +3,15 @@ namespace DesignPatterns\Creational\AbstractFactory; /** - * Interface MediaInterface + * Interface MediaInterface. * * This contract is not part of the pattern, in general case, each component * are not related */ interface MediaInterface { - /** - * some crude rendering from JSON or html output (depended on concrete class) + * some crude rendering from JSON or html output (depended on concrete class). * * @return string */ diff --git a/Creational/AbstractFactory/Picture.php b/Creational/AbstractFactory/Picture.php index 8a4f720..89fd66f 100644 --- a/Creational/AbstractFactory/Picture.php +++ b/Creational/AbstractFactory/Picture.php @@ -3,11 +3,10 @@ namespace DesignPatterns\Creational\AbstractFactory; /** - * Class Picture + * Class Picture. */ abstract class Picture implements MediaInterface { - /** * @var string */ diff --git a/Creational/AbstractFactory/Tests/AbstractFactoryTest.php b/Creational/AbstractFactory/Tests/AbstractFactoryTest.php index b51394a..97f4417 100644 --- a/Creational/AbstractFactory/Tests/AbstractFactoryTest.php +++ b/Creational/AbstractFactory/Tests/AbstractFactoryTest.php @@ -7,7 +7,7 @@ use DesignPatterns\Creational\AbstractFactory\HtmlFactory; use DesignPatterns\Creational\AbstractFactory\JsonFactory; /** - * AbstractFactoryTest tests concrete factories + * AbstractFactoryTest tests concrete factories. */ class AbstractFactoryTest extends \PHPUnit_Framework_TestCase { @@ -15,7 +15,7 @@ class AbstractFactoryTest extends \PHPUnit_Framework_TestCase { return array( array(new JsonFactory()), - array(new HtmlFactory()) + array(new HtmlFactory()), ); } @@ -31,7 +31,7 @@ class AbstractFactoryTest extends \PHPUnit_Framework_TestCase $article = array( $factory->createText('Lorem Ipsum'), $factory->createPicture('/image.jpg', 'caption'), - $factory->createText('footnotes') + $factory->createText('footnotes'), ); $this->assertContainsOnly('DesignPatterns\Creational\AbstractFactory\MediaInterface', $article); diff --git a/Creational/AbstractFactory/Text.php b/Creational/AbstractFactory/Text.php index 5d2da89..30984f3 100644 --- a/Creational/AbstractFactory/Text.php +++ b/Creational/AbstractFactory/Text.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\AbstractFactory; /** - * Class Text + * Class Text. */ abstract class Text implements MediaInterface { diff --git a/Creational/Builder/BikeBuilder.php b/Creational/Builder/BikeBuilder.php index 53d53d3..f83c5db 100644 --- a/Creational/Builder/BikeBuilder.php +++ b/Creational/Builder/BikeBuilder.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Builder; /** - * BikeBuilder builds bike + * BikeBuilder builds bike. */ class BikeBuilder implements BuilderInterface { diff --git a/Creational/Builder/CarBuilder.php b/Creational/Builder/CarBuilder.php index 7725176..a0693d0 100644 --- a/Creational/Builder/CarBuilder.php +++ b/Creational/Builder/CarBuilder.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Builder; /** - * CarBuilder builds car + * CarBuilder builds car. */ class CarBuilder implements BuilderInterface { diff --git a/Creational/Builder/Director.php b/Creational/Builder/Director.php index d7f3aa3..642cd1b 100644 --- a/Creational/Builder/Director.php +++ b/Creational/Builder/Director.php @@ -10,9 +10,8 @@ namespace DesignPatterns\Creational\Builder; */ class Director { - /** - * The director don't know 'bout concrete part + * The director don't know about concrete part. * * @param BuilderInterface $builder * diff --git a/Creational/Builder/Parts/Bike.php b/Creational/Builder/Parts/Bike.php index 6efefe9..e5adbba 100644 --- a/Creational/Builder/Parts/Bike.php +++ b/Creational/Builder/Parts/Bike.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Builder\Parts; /** - * Bike is a bike + * Bike is a bike. */ class Bike extends Vehicle { diff --git a/Creational/Builder/Parts/Car.php b/Creational/Builder/Parts/Car.php index 1d4496c..e345ea9 100644 --- a/Creational/Builder/Parts/Car.php +++ b/Creational/Builder/Parts/Car.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Builder\Parts; /** - * Car is a car + * Car is a car. */ class Car extends Vehicle { diff --git a/Creational/Builder/Parts/Door.php b/Creational/Builder/Parts/Door.php index 526d41b..fc12608 100644 --- a/Creational/Builder/Parts/Door.php +++ b/Creational/Builder/Parts/Door.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Builder\Parts; /** - * Class Door + * Class Door. */ class Door { diff --git a/Creational/Builder/Parts/Engine.php b/Creational/Builder/Parts/Engine.php index 0b2fad0..5232ab3 100644 --- a/Creational/Builder/Parts/Engine.php +++ b/Creational/Builder/Parts/Engine.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Builder\Parts; /** - * Class Engine + * Class Engine. */ class Engine { diff --git a/Creational/Builder/Parts/Vehicle.php b/Creational/Builder/Parts/Vehicle.php index 492eade..18c47ba 100644 --- a/Creational/Builder/Parts/Vehicle.php +++ b/Creational/Builder/Parts/Vehicle.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Builder\Parts; /** - * VehicleInterface is a contract for a vehicle + * Vehicle class is an abstraction for a vehicle. */ abstract class Vehicle { diff --git a/Creational/Builder/Parts/Wheel.php b/Creational/Builder/Parts/Wheel.php index 7fb60fd..0a1afbd 100644 --- a/Creational/Builder/Parts/Wheel.php +++ b/Creational/Builder/Parts/Wheel.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Builder\Parts; /** - * Class Wheel + * Class Wheel. */ class Wheel { diff --git a/Creational/Builder/Tests/DirectorTest.php b/Creational/Builder/Tests/DirectorTest.php index 0520bfe..9f07b83 100644 --- a/Creational/Builder/Tests/DirectorTest.php +++ b/Creational/Builder/Tests/DirectorTest.php @@ -2,17 +2,16 @@ namespace DesignPatterns\Creational\Builder\Tests; -use DesignPatterns\Creational\Builder\Director; -use DesignPatterns\Creational\Builder\CarBuilder; use DesignPatterns\Creational\Builder\BikeBuilder; use DesignPatterns\Creational\Builder\BuilderInterface; +use DesignPatterns\Creational\Builder\CarBuilder; +use DesignPatterns\Creational\Builder\Director; /** - * DirectorTest tests the builder pattern + * DirectorTest tests the builder pattern. */ class DirectorTest extends \PHPUnit_Framework_TestCase { - protected $director; protected function setUp() @@ -24,7 +23,7 @@ class DirectorTest extends \PHPUnit_Framework_TestCase { return array( array(new CarBuilder()), - array(new BikeBuilder()) + array(new BikeBuilder()), ); } diff --git a/Creational/FactoryMethod/Bicycle.php b/Creational/FactoryMethod/Bicycle.php index 01fa8a0..8e41f88 100644 --- a/Creational/FactoryMethod/Bicycle.php +++ b/Creational/FactoryMethod/Bicycle.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\FactoryMethod; /** - * Bicycle is a bicycle + * Bicycle is a bicycle. */ class Bicycle implements VehicleInterface { @@ -13,7 +13,7 @@ class Bicycle implements VehicleInterface protected $color; /** - * sets the color of the bicycle + * sets the color of the bicycle. * * @param string $rgb */ diff --git a/Creational/FactoryMethod/FactoryMethod.php b/Creational/FactoryMethod/FactoryMethod.php index dd24b15..fa3d4a3 100644 --- a/Creational/FactoryMethod/FactoryMethod.php +++ b/Creational/FactoryMethod/FactoryMethod.php @@ -3,16 +3,15 @@ namespace DesignPatterns\Creational\FactoryMethod; /** - * class FactoryMethod + * class FactoryMethod. */ abstract class FactoryMethod { - const CHEAP = 1; const FAST = 2; /** - * The children of the class must implement this method + * The children of the class must implement this method. * * Sometimes this method can be public to get "raw" object * @@ -23,7 +22,7 @@ abstract class FactoryMethod abstract protected function createVehicle($type); /** - * Creates a new vehicle + * Creates a new vehicle. * * @param int $type * @@ -32,7 +31,7 @@ abstract class FactoryMethod public function create($type) { $obj = $this->createVehicle($type); - $obj->setColor("#f00"); + $obj->setColor('#f00'); return $obj; } diff --git a/Creational/FactoryMethod/Ferrari.php b/Creational/FactoryMethod/Ferrari.php index c905f91..9434e3d 100644 --- a/Creational/FactoryMethod/Ferrari.php +++ b/Creational/FactoryMethod/Ferrari.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\FactoryMethod; /** - * Ferrari is a italian car + * Ferrari is a italian car. */ class Ferrari implements VehicleInterface { diff --git a/Creational/FactoryMethod/GermanFactory.php b/Creational/FactoryMethod/GermanFactory.php index 67306e9..1f65eb4 100644 --- a/Creational/FactoryMethod/GermanFactory.php +++ b/Creational/FactoryMethod/GermanFactory.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\FactoryMethod; /** - * GermanFactory is a vehicle factory in Germany + * GermanFactory is a vehicle factory in Germany. */ class GermanFactory extends FactoryMethod { diff --git a/Creational/FactoryMethod/ItalianFactory.php b/Creational/FactoryMethod/ItalianFactory.php index c7010e0..25eeaf1 100644 --- a/Creational/FactoryMethod/ItalianFactory.php +++ b/Creational/FactoryMethod/ItalianFactory.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\FactoryMethod; /** - * ItalianFactory is vehicle factory in Italy + * ItalianFactory is vehicle factory in Italy. */ class ItalianFactory extends FactoryMethod { diff --git a/Creational/FactoryMethod/Porsche.php b/Creational/FactoryMethod/Porsche.php index cba25ce..bdabb87 100644 --- a/Creational/FactoryMethod/Porsche.php +++ b/Creational/FactoryMethod/Porsche.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\FactoryMethod; /** - * Porsche is a german car + * Porsche is a german car. */ class Porsche implements VehicleInterface { diff --git a/Creational/FactoryMethod/Tests/FactoryMethodTest.php b/Creational/FactoryMethod/Tests/FactoryMethodTest.php index acbe0c6..6b1c4d2 100644 --- a/Creational/FactoryMethod/Tests/FactoryMethodTest.php +++ b/Creational/FactoryMethod/Tests/FactoryMethodTest.php @@ -7,21 +7,20 @@ use DesignPatterns\Creational\FactoryMethod\GermanFactory; use DesignPatterns\Creational\FactoryMethod\ItalianFactory; /** - * FactoryMethodTest tests the factory method pattern + * FactoryMethodTest tests the factory method pattern. */ class FactoryMethodTest extends \PHPUnit_Framework_TestCase { - protected $type = array( FactoryMethod::CHEAP, - FactoryMethod::FAST + FactoryMethod::FAST, ); public function getShop() { return array( array(new GermanFactory()), - array(new ItalianFactory()) + array(new ItalianFactory()), ); } diff --git a/Creational/FactoryMethod/VehicleInterface.php b/Creational/FactoryMethod/VehicleInterface.php index a734b61..ccb05ee 100644 --- a/Creational/FactoryMethod/VehicleInterface.php +++ b/Creational/FactoryMethod/VehicleInterface.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Creational\FactoryMethod; /** - * VehicleInterface is a contract for a vehicle + * VehicleInterface is a contract for a vehicle. */ interface VehicleInterface { /** - * sets the color of the vehicle + * sets the color of the vehicle. * * @param string $rgb */ diff --git a/Creational/Multiton/Multiton.php b/Creational/Multiton/Multiton.php index 44f1ef0..5338e62 100644 --- a/Creational/Multiton/Multiton.php +++ b/Creational/Multiton/Multiton.php @@ -3,24 +3,22 @@ namespace DesignPatterns\Creational\Multiton; /** - * class Multiton + * class Multiton. */ class Multiton { /** - * - * the first instance + * the first instance. */ const INSTANCE_1 = '1'; /** - * - * the second instance + * the second instance. */ const INSTANCE_2 = '2'; /** - * holds the named instances + * holds the named instances. * * @var array */ @@ -28,7 +26,6 @@ class Multiton /** * should not be called from outside: private! - * */ private function __construct() { @@ -36,7 +33,7 @@ class Multiton /** * gets the instance with the given name, e.g. Multiton::INSTANCE_1 - * uses lazy initialization + * uses lazy initialization. * * @param string $instanceName * @@ -52,7 +49,7 @@ class Multiton } /** - * prevent instance from being cloned + * prevent instance from being cloned. * * @return void */ @@ -61,7 +58,7 @@ class Multiton } /** - * prevent instance from being unserialized + * prevent instance from being unserialized. * * @return void */ diff --git a/Creational/Pool/Pool.php b/Creational/Pool/Pool.php index e3a809b..7dcc6e3 100644 --- a/Creational/Pool/Pool.php +++ b/Creational/Pool/Pool.php @@ -4,7 +4,6 @@ namespace DesignPatterns\Creational\Pool; class Pool { - private $instances = array(); private $class; diff --git a/Creational/Pool/Processor.php b/Creational/Pool/Processor.php index 957e91f..89179b9 100644 --- a/Creational/Pool/Processor.php +++ b/Creational/Pool/Processor.php @@ -4,11 +4,10 @@ namespace DesignPatterns\Creational\Pool; class Processor { - private $pool; private $processing = 0; private $maxProcesses = 3; - private $waitingQueue = []; + private $waitingQueue = array(); public function __construct(Pool $pool) { diff --git a/Creational/Pool/Worker.php b/Creational/Pool/Worker.php index acdc1ba..08d76b8 100644 --- a/Creational/Pool/Worker.php +++ b/Creational/Pool/Worker.php @@ -4,7 +4,6 @@ namespace DesignPatterns\Creational\Pool; class Worker { - public function __construct() { // let's say that constuctor does really expensive work... diff --git a/Creational/Prototype/BarBookPrototype.php b/Creational/Prototype/BarBookPrototype.php index 4354a60..7c9b72b 100644 --- a/Creational/Prototype/BarBookPrototype.php +++ b/Creational/Prototype/BarBookPrototype.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Prototype; /** - * Class BarBookPrototype + * Class BarBookPrototype. */ class BarBookPrototype extends BookPrototype { @@ -13,7 +13,7 @@ class BarBookPrototype extends BookPrototype protected $category = 'Bar'; /** - * empty clone + * empty clone. */ public function __clone() { diff --git a/Creational/Prototype/BookPrototype.php b/Creational/Prototype/BookPrototype.php index 18d4871..e0fafa6 100644 --- a/Creational/Prototype/BookPrototype.php +++ b/Creational/Prototype/BookPrototype.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Prototype; /** - * class BookPrototype + * class BookPrototype. */ abstract class BookPrototype { @@ -19,6 +19,7 @@ abstract class BookPrototype /** * @abstract + * * @return void */ abstract public function __clone(); diff --git a/Creational/Prototype/FooBookPrototype.php b/Creational/Prototype/FooBookPrototype.php index 9707bfd..95ea9e6 100644 --- a/Creational/Prototype/FooBookPrototype.php +++ b/Creational/Prototype/FooBookPrototype.php @@ -3,14 +3,14 @@ namespace DesignPatterns\Creational\Prototype; /** - * Class FooBookPrototype + * Class FooBookPrototype. */ class FooBookPrototype extends BookPrototype { protected $category = 'Foo'; /** - * empty clone + * empty clone. */ public function __clone() { diff --git a/Creational/Prototype/index.php b/Creational/Prototype/index.php index f268e5c..d0f6e94 100644 --- a/Creational/Prototype/index.php +++ b/Creational/Prototype/index.php @@ -8,10 +8,10 @@ $barPrototype = new BarBookPrototype(); // now lets say we need 10,000 books of foo and 5,000 of bar ... for ($i = 0; $i < 10000; $i++) { $book = clone $fooPrototype; - $book->setTitle('Foo Book No ' . $i); + $book->setTitle('Foo Book No '.$i); } for ($i = 0; $i < 5000; $i++) { $book = clone $barPrototype; - $book->setTitle('Bar Book No ' . $i); + $book->setTitle('Bar Book No '.$i); } diff --git a/Creational/SimpleFactory/Bicycle.php b/Creational/SimpleFactory/Bicycle.php index 67215f1..defa801 100644 --- a/Creational/SimpleFactory/Bicycle.php +++ b/Creational/SimpleFactory/Bicycle.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\SimpleFactory; /** - * Bicycle is a bicycle + * Bicycle is a bicycle. */ class Bicycle implements VehicleInterface { diff --git a/Creational/SimpleFactory/README.rst b/Creational/SimpleFactory/README.rst index 364947f..8f6ce81 100644 --- a/Creational/SimpleFactory/README.rst +++ b/Creational/SimpleFactory/README.rst @@ -4,7 +4,7 @@ Simple Factory Purpose ------- -ConcreteFactory is a simple factory pattern. +SimpleFactory is a simple factory pattern. It differs from the static factory because it is NOT static and as you know: static => global => evil! @@ -24,9 +24,9 @@ Code You can also find these code on `GitHub`_ -ConcreteFactory.php +SimpleFactory.php -.. literalinclude:: ConcreteFactory.php +.. literalinclude:: SimpleFactory.php :language: php :linenos: @@ -48,6 +48,15 @@ Scooter.php :language: php :linenos: +Usage +----- + +.. code:: php + + $factory = new SimpleFactory(); + $bicycle = $factory->createVehicle('bicycle'); + $bicycle->driveTo('Paris'); + Test ---- diff --git a/Creational/SimpleFactory/Scooter.php b/Creational/SimpleFactory/Scooter.php index 81fa505..e1db734 100644 --- a/Creational/SimpleFactory/Scooter.php +++ b/Creational/SimpleFactory/Scooter.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\SimpleFactory; /** - * Scooter is a Scooter + * Scooter is a Scooter. */ class Scooter implements VehicleInterface { diff --git a/Creational/SimpleFactory/ConcreteFactory.php b/Creational/SimpleFactory/SimpleFactory.php similarity index 81% rename from Creational/SimpleFactory/ConcreteFactory.php rename to Creational/SimpleFactory/SimpleFactory.php index dd8acf8..7de17a1 100644 --- a/Creational/SimpleFactory/ConcreteFactory.php +++ b/Creational/SimpleFactory/SimpleFactory.php @@ -3,9 +3,9 @@ namespace DesignPatterns\Creational\SimpleFactory; /** - * class ConcreteFactory + * class SimpleFactory. */ -class ConcreteFactory +class SimpleFactory { /** * @var array @@ -19,18 +19,19 @@ class ConcreteFactory public function __construct() { $this->typeList = array( - 'bicycle' => __NAMESPACE__ . '\Bicycle', - 'other' => __NAMESPACE__ . '\Scooter' + 'bicycle' => __NAMESPACE__.'\Bicycle', + 'other' => __NAMESPACE__.'\Scooter', ); } /** - * Creates a vehicle + * Creates a vehicle. * * @param string $type a known type key * - * @return VehicleInterface a new instance of VehicleInterface * @throws \InvalidArgumentException + * + * @return VehicleInterface a new instance of VehicleInterface */ public function createVehicle($type) { diff --git a/Creational/SimpleFactory/Tests/SimpleFactoryTest.php b/Creational/SimpleFactory/Tests/SimpleFactoryTest.php index 1fffda3..c2f5379 100644 --- a/Creational/SimpleFactory/Tests/SimpleFactoryTest.php +++ b/Creational/SimpleFactory/Tests/SimpleFactoryTest.php @@ -2,26 +2,25 @@ namespace DesignPatterns\Creational\SimpleFactory\Tests; -use DesignPatterns\Creational\SimpleFactory\ConcreteFactory; +use DesignPatterns\Creational\SimpleFactory\SimpleFactory; /** - * SimpleFactoryTest tests the Simple Factory pattern + * SimpleFactoryTest tests the Simple Factory pattern. */ class SimpleFactoryTest extends \PHPUnit_Framework_TestCase { - protected $factory; protected function setUp() { - $this->factory = new ConcreteFactory(); + $this->factory = new SimpleFactory(); } public function getType() { return array( array('bicycle'), - array('other') + array('other'), ); } diff --git a/Creational/SimpleFactory/VehicleInterface.php b/Creational/SimpleFactory/VehicleInterface.php index eb13a66..f2c8d3f 100644 --- a/Creational/SimpleFactory/VehicleInterface.php +++ b/Creational/SimpleFactory/VehicleInterface.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\SimpleFactory; /** - * VehicleInterface is a contract for a vehicle + * VehicleInterface is a contract for a vehicle. */ interface VehicleInterface { diff --git a/Creational/SimpleFactory/uml/SimpleFactory.uml b/Creational/SimpleFactory/uml/SimpleFactory.uml index f51ce6c..5a586a5 100644 --- a/Creational/SimpleFactory/uml/SimpleFactory.uml +++ b/Creational/SimpleFactory/uml/SimpleFactory.uml @@ -1,10 +1,10 @@ PHP - \DesignPatterns\Creational\SimpleFactory\ConcreteFactory + \DesignPatterns\Creational\SimpleFactory\SimpleFactory \DesignPatterns\Creational\SimpleFactory\Scooter - \DesignPatterns\Creational\SimpleFactory\ConcreteFactory + \DesignPatterns\Creational\SimpleFactory\SimpleFactory \DesignPatterns\Creational\SimpleFactory\VehicleInterface \DesignPatterns\Creational\SimpleFactory\Bicycle diff --git a/Creational/SimpleFactory/uml/uml.svg b/Creational/SimpleFactory/uml/uml.svg index 7c966c2..7da8077 100644 --- a/Creational/SimpleFactory/uml/uml.svg +++ b/Creational/SimpleFactory/uml/uml.svg @@ -201,10 +201,10 @@ - ConcreteFactory + SimpleFactory - ConcreteFactory + SimpleFactory diff --git a/Creational/Singleton/Singleton.php b/Creational/Singleton/Singleton.php index 41a4569..650810e 100644 --- a/Creational/Singleton/Singleton.php +++ b/Creational/Singleton/Singleton.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\Singleton; /** - * class Singleton + * class Singleton. */ class Singleton { @@ -11,16 +11,16 @@ class Singleton * @var Singleton reference to singleton instance */ private static $instance; - + /** - * gets the instance via lazy initialization (created on first usage) + * gets the instance via lazy initialization (created on first usage). * * @return self */ public static function getInstance() { if (null === static::$instance) { - static::$instance = new static; + static::$instance = new static(); } return static::$instance; @@ -28,27 +28,32 @@ class Singleton /** * is not allowed to call from outside: private! - * */ private function __construct() { } /** - * prevent the instance from being cloned + * prevent the instance from being cloned. + * + * @throws SingletonPatternViolationException * * @return void */ - private function __clone() + final public function __clone() { + throw new SingletonPatternViolationException('This is a Singleton. Clone is forbidden'); } /** - * prevent from being unserialized + * prevent from being unserialized. + * + * @throws SingletonPatternViolationException * * @return void */ - private function __wakeup() + final public function __wakeup() { + throw new SingletonPatternViolationException('This is a Singleton. __wakeup usage is forbidden'); } } diff --git a/Creational/Singleton/SingletonPatternViolationException.php b/Creational/Singleton/SingletonPatternViolationException.php new file mode 100644 index 0000000..b025b4a --- /dev/null +++ b/Creational/Singleton/SingletonPatternViolationException.php @@ -0,0 +1,7 @@ +getMethod('__construct'); $this->assertTrue($meth->isPrivate()); } + + /** + * @expectedException \DesignPatterns\Creational\Singleton\SingletonPatternViolationException + * + * @return void + */ + public function testNoCloneAllowed() + { + $obj1 = Singleton::getInstance(); + $obj2 = clone $obj1; + } + + /** + * @expectedException \DesignPatterns\Creational\Singleton\SingletonPatternViolationException + * + * @return void + */ + public function testNoSerializationAllowed() + { + $obj1 = Singleton::getInstance(); + $serialized = serialize($obj1); + $obj2 = unserialize($serialized); + } } diff --git a/Creational/StaticFactory/FormatNumber.php b/Creational/StaticFactory/FormatNumber.php index 8f382f7..e577ab2 100644 --- a/Creational/StaticFactory/FormatNumber.php +++ b/Creational/StaticFactory/FormatNumber.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\StaticFactory; /** - * Class FormatNumber + * Class FormatNumber. */ class FormatNumber implements FormatterInterface { diff --git a/Creational/StaticFactory/FormatString.php b/Creational/StaticFactory/FormatString.php index a0d174d..5cb9e28 100644 --- a/Creational/StaticFactory/FormatString.php +++ b/Creational/StaticFactory/FormatString.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\StaticFactory; /** - * Class FormatString + * Class FormatString. */ class FormatString implements FormatterInterface { diff --git a/Creational/StaticFactory/FormatterInterface.php b/Creational/StaticFactory/FormatterInterface.php index 81b9149..349f8b6 100644 --- a/Creational/StaticFactory/FormatterInterface.php +++ b/Creational/StaticFactory/FormatterInterface.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Creational\StaticFactory; /** - * Class FormatterInterface + * Class FormatterInterface. */ interface FormatterInterface { diff --git a/Creational/StaticFactory/StaticFactory.php b/Creational/StaticFactory/StaticFactory.php index e4f2f96..e4c4f4b 100644 --- a/Creational/StaticFactory/StaticFactory.php +++ b/Creational/StaticFactory/StaticFactory.php @@ -4,23 +4,24 @@ namespace DesignPatterns\Creational\StaticFactory; /** * Note1: Remember, static => global => evil - * Note2: Cannot be subclassed or mock-upped or have multiple different instances + * Note2: Cannot be subclassed or mock-upped or have multiple different instances. */ class StaticFactory { /** - * the parametrized function to get create an instance + * the parametrized function to get create an instance. * * @param string $type * * @static * * @throws \InvalidArgumentException + * * @return FormatterInterface */ public static function factory($type) { - $className = __NAMESPACE__ . '\Format' . ucfirst($type); + $className = __NAMESPACE__.'\Format'.ucfirst($type); if (!class_exists($className)) { throw new \InvalidArgumentException('Missing format class.'); diff --git a/Creational/StaticFactory/Tests/StaticFactoryTest.php b/Creational/StaticFactory/Tests/StaticFactoryTest.php index f0304ca..61f65af 100644 --- a/Creational/StaticFactory/Tests/StaticFactoryTest.php +++ b/Creational/StaticFactory/Tests/StaticFactoryTest.php @@ -5,17 +5,15 @@ namespace DesignPatterns\Creational\StaticFactory\Tests; use DesignPatterns\Creational\StaticFactory\StaticFactory; /** - * Tests for Static Factory pattern - * + * Tests for Static Factory pattern. */ class StaticFactoryTest extends \PHPUnit_Framework_TestCase { - public function getTypeList() { return array( array('string'), - array('number') + array('number'), ); } @@ -33,6 +31,6 @@ class StaticFactoryTest extends \PHPUnit_Framework_TestCase */ public function testException() { - StaticFactory::factory(""); + StaticFactory::factory(''); } } diff --git a/More/Delegation/JuniorDeveloper.php b/More/Delegation/JuniorDeveloper.php index 7506181..0946dad 100644 --- a/More/Delegation/JuniorDeveloper.php +++ b/More/Delegation/JuniorDeveloper.php @@ -3,13 +3,12 @@ namespace DesignPatterns\More\Delegation; /** - * Class JuniorDeveloper - * @package DesignPatterns\Delegation + * Class JuniorDeveloper. */ class JuniorDeveloper { public function writeBadCode() { - return "Some junior developer generated code..."; + return 'Some junior developer generated code...'; } } diff --git a/More/Delegation/README.rst b/More/Delegation/README.rst index b6172c6..69306ad 100644 --- a/More/Delegation/README.rst +++ b/More/Delegation/README.rst @@ -4,12 +4,12 @@ Purpose ------- -... +Demonstrate the Delegator pattern, where an object, instead of performing one of its stated tasks, delegates that task to an associated helper object. In this case TeamLead professes to writeCode and Usage uses this, while TeamLead delegates writeCode to JuniorDeveloper's writeBadCode function. This inverts the responsibility so that Usage is unknowingly executing writeBadCode. Examples -------- -... +Please review JuniorDeveloper.php, TeamLead.php, and then Usage.php to see it all tied together. UML Diagram ----------- diff --git a/More/Delegation/TeamLead.php b/More/Delegation/TeamLead.php index 315bd3b..9b75190 100644 --- a/More/Delegation/TeamLead.php +++ b/More/Delegation/TeamLead.php @@ -3,9 +3,7 @@ namespace DesignPatterns\More\Delegation; /** - * Class TeamLead - * @package DesignPatterns\Delegation - * The `TeamLead` class, he delegate work to `JuniorDeveloper` + * Class TeamLead. */ class TeamLead { @@ -13,7 +11,8 @@ class TeamLead protected $slave; /** - * Give junior developer into teamlead submission + * Give junior developer into teamlead submission. + * * @param JuniorDeveloper $junior */ public function __construct(JuniorDeveloper $junior) @@ -22,7 +21,8 @@ class TeamLead } /** - * TeamLead drink coffee, junior work + * TeamLead drink coffee, junior work. + * * @return mixed */ public function writeCode() diff --git a/More/Delegation/Tests/DelegationTest.php b/More/Delegation/Tests/DelegationTest.php index b19f871..7d0a33b 100644 --- a/More/Delegation/Tests/DelegationTest.php +++ b/More/Delegation/Tests/DelegationTest.php @@ -5,7 +5,7 @@ namespace DesignPatterns\More\Delegation\Tests; use DesignPatterns\More\Delegation; /** - * DelegationTest tests the delegation pattern + * DelegationTest tests the delegation pattern. */ class DelegationTest extends \PHPUnit_Framework_TestCase { diff --git a/More/EAV/Attribute.php b/More/EAV/Attribute.php new file mode 100644 index 0000000..3874360 --- /dev/null +++ b/More/EAV/Attribute.php @@ -0,0 +1,82 @@ +values = new SplObjectStorage(); + } + + /** + * @return SplObjectStorage + */ + public function getValues() + { + return $this->values; + } + + /** + * @param ValueInterface $value + * + * @return $this + */ + public function addValue(ValueInterface $value) + { + if (!$this->values->contains($value)) { + $this->values->attach($value); + } + + return $this; + } + + /** + * @param ValueInterface $value + * + * @return $this + */ + public function removeValue(ValueInterface $value) + { + if ($this->values->contains($value)) { + $this->values->detach($value); + } + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } +} diff --git a/More/EAV/Entity.php b/More/EAV/Entity.php new file mode 100644 index 0000000..ff26589 --- /dev/null +++ b/More/EAV/Entity.php @@ -0,0 +1,82 @@ +values = new SplObjectStorage(); + } + + /** + * @return SplObjectStorage + */ + public function getValues() + { + return $this->values; + } + + /** + * @param ValueInterface $value + * + * @return $this + */ + public function addValue(ValueInterface $value) + { + if (!$this->values->contains($value)) { + $this->values->attach($value); + } + + return $this; + } + + /** + * @param ValueInterface $value + * + * @return $this + */ + public function removeValue(ValueInterface $value) + { + if ($this->values->contains($value)) { + $this->values->detach($value); + } + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } +} diff --git a/More/EAV/README.rst b/More/EAV/README.rst new file mode 100644 index 0000000..b8a8fbe --- /dev/null +++ b/More/EAV/README.rst @@ -0,0 +1,125 @@ +`Entity-Attribute-Value (EAV)`__ +================================ + +The Entity–attribute–value (EAV) pattern in order to implement EAV model with PHP. + +Purpose +------- + +The Entity–attribute–value (EAV) model is a data model to describe entities +where the number of attributes (properties, parameters) that can be used +to describe them is potentially vast, but the number that will actually apply +to a given entity is relatively modest. + +Examples +-------- + +Check full work example in `example.php`_ file. + +.. code-block:: php + + use DesignPatterns\More\EAV\Entity; + use DesignPatterns\More\EAV\Attribute; + use DesignPatterns\More\EAV\Value; + + // Create color attribute + $color = (new Attribute())->setName('Color'); + // Create color values + $colorSilver = (new Value($color))->setName('Silver'); + $colorGold = (new Value($color))->setName('Gold'); + $colorSpaceGrey = (new Value($color))->setName('Space Grey'); + + // Create memory attribute + $memory = (new Attribute())->setName('Memory'); + // Create memory values + $memory4Gb = (new Value($memory))->setName('4GB'); + $memory8Gb = (new Value($memory))->setName('8GB'); + $memory16Gb = (new Value($memory))->setName('16GB'); + + // Create storage attribute + $storage = (new Attribute())->setName('Storage'); + // Create storage values + $storage128Gb = (new Value($storage))->setName('128GB'); + $storage256Gb = (new Value($storage))->setName('256GB'); + $storage512Gb = (new Value($storage))->setName('512GB'); + $storage1Tb = (new Value($storage))->setName('1TB'); + + // Create entities with specific values + $mac = (new Entity()) + ->setName('MacBook') + // colors + ->addValue($colorSilver) + ->addValue($colorGold) + ->addValue($colorSpaceGrey) + // memories + ->addValue($memory8Gb) + // storages + ->addValue($storage256Gb) + ->addValue($storage512Gb) + ; + + $macAir = (new Entity()) + ->setName('MacBook Air') + // colors + ->addValue($colorSilver) + // memories + ->addValue($memory4Gb) + ->addValue($memory8Gb) + // storages + ->addValue($storage128Gb) + ->addValue($storage256Gb) + ->addValue($storage512Gb) + ; + + $macPro = (new Entity()) + ->setName('MacBook Pro') + // colors + ->addValue($colorSilver) + // memories + ->addValue($memory8Gb) + ->addValue($memory16Gb) + // storages + ->addValue($storage128Gb) + ->addValue($storage256Gb) + ->addValue($storage512Gb) + ->addValue($storage1Tb) + ; + + +UML Diagram +----------- + +.. image:: uml/uml.png + :alt: EAV UML Diagram + :align: center + +Code +---- + +You can also find these code on `GitHub`_ + +Test +---- + +Tests/EntityTest.php + +.. literalinclude:: Tests/EntityTest.php + :language: php + :linenos: + +Tests/AttributeTest.php + +.. literalinclude:: Tests/AttributeTest.php + :language: php + :linenos: + +Tests/ValueTest.php + +.. literalinclude:: Tests/ValueTest.php + :language: php + :linenos: + + +.. _`example.php`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV/example.php +.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV +.. __: https://en.wikipedia.org/wiki/Entity–attribute–value_model diff --git a/More/EAV/Tests/AttributeTest.php b/More/EAV/Tests/AttributeTest.php new file mode 100644 index 0000000..4affe41 --- /dev/null +++ b/More/EAV/Tests/AttributeTest.php @@ -0,0 +1,66 @@ +assertInstanceOf('\DesignPatterns\More\EAV\Attribute', $attribute); + } + + /** + * @depends testCreationSuccess + */ + public function testSetGetName() + { + $attribute = new Attribute(); + $attribute->setName('Color'); + + $this->assertEquals('Color', $attribute->getName()); + } + + /** + * @depends testCreationSuccess + */ + public function testAddValue() + { + $attribute = new Attribute(); + $attribute->setName('Color'); + + $colorSilver = new Value($attribute); + $colorSilver->setName('Silver'); + $colorGold = new Value($attribute); + $colorGold->setName('Gold'); + + $this->assertTrue($attribute->getValues()->contains($colorSilver)); + $this->assertTrue($attribute->getValues()->contains($colorGold)); + } + + /** + * @depends testAddValue + */ + public function testRemoveValue() + { + $attribute = new Attribute(); + $attribute->setName('Color'); + + $colorSilver = new Value($attribute); + $colorSilver->setName('Silver'); + $colorGold = new Value($attribute); + $colorGold->setName('Gold'); + + $attribute->removeValue($colorSilver); + + $this->assertFalse($attribute->getValues()->contains($colorSilver)); + $this->assertTrue($attribute->getValues()->contains($colorGold)); + } +} diff --git a/More/EAV/Tests/EntityTest.php b/More/EAV/Tests/EntityTest.php new file mode 100644 index 0000000..ecd6c40 --- /dev/null +++ b/More/EAV/Tests/EntityTest.php @@ -0,0 +1,145 @@ +setName($name); + + $this->assertEquals($name, $macBook->getName()); + } + + /** + * @dataProvider valueProvider + * + * @var string + * @var Value[] $values + */ + public function testAddValue($name, array $values) + { + $macBook = new Entity(); + $macBook->setName($name); + + foreach ($values as $value) { + $macBook->addValue($value); + $this->assertTrue($macBook->getValues()->contains($value)); + } + + $this->assertCount(count($values), $macBook->getValues()); + } + + /** + * @depends testAddValue + * @dataProvider valueProvider + * + * @var string + * @var Value[] $values + */ + public function testRemoveValue($name, array $values) + { + $macBook = new Entity(); + $macBook->setName($name); + + foreach ($values as $value) { + $macBook->addValue($value); + } + $macBook->removeValue($values[0]); + + $this->assertFalse($macBook->getValues()->contains($values[0])); + unset($values[0]); + $this->assertCount(count($values), $macBook->getValues()); + } + + /** + * @return array + */ + public function valueProvider() + { + // color attribute + $color = new Attribute(); + $color->setName('Color'); + // color values + $colorSilver = new Value($color); + $colorSilver->setName('Silver'); + $colorGold = new Value($color); + $colorGold->setName('Gold'); + $colorSpaceGrey = new Value($color); + $colorSpaceGrey->setName('Space Grey'); + + // memory attribute + $memory = new Attribute(); + $memory->setName('Memory'); + // memory values + $memory4Gb = new Value($memory); + $memory4Gb->setName('4GB'); + $memory8Gb = new Value($memory); + $memory8Gb->setName('8GB'); + $memory16Gb = new Value($memory); + $memory16Gb->setName('16GB'); + + // storage attribute + $storage = new Attribute(); + $storage->setName('Storage'); + // storage values + $storage128Gb = new Value($storage); + $storage128Gb->setName('128GB'); + $storage256Gb = new Value($storage); + $storage256Gb->setName('256GB'); + $storage512Gb = new Value($storage); + $storage512Gb->setName('512GB'); + $storage1Tb = new Value($storage); + $storage1Tb->setName('1TB'); + + return array( + array( + 'MacBook', + array( + $colorSilver, + $colorGold, + $colorSpaceGrey, + $memory8Gb, + $storage256Gb, + $storage512Gb, + ), + ), + array( + 'MacBook Air', + array( + $colorSilver, + $memory4Gb, + $memory8Gb, + $storage128Gb, + $storage256Gb, + $storage512Gb, + ), + ), + array( + 'MacBook Pro', + array( + $colorSilver, + $memory8Gb, + $memory16Gb, + $storage128Gb, + $storage256Gb, + $storage512Gb, + $storage1Tb, + ), + ), + ); + } +} diff --git a/More/EAV/Tests/ValueTest.php b/More/EAV/Tests/ValueTest.php new file mode 100644 index 0000000..f80f070 --- /dev/null +++ b/More/EAV/Tests/ValueTest.php @@ -0,0 +1,46 @@ +setName('Color'); + + $value = new Value($attribute); + + $this->assertInstanceOf('\DesignPatterns\More\EAV\Value', $value); + } + + public function testSetGetName() + { + $attribute = new Attribute(); + $attribute->setName('Color'); + + $value = new Value($attribute); + $value->setName('Silver'); + + $this->assertEquals('Silver', $value->getName()); + } + + public function testSetGetAttribute() + { + $attribute = new Attribute(); + $attribute->setName('Color'); + + $value = new Value($attribute); + $value->setName('Silver'); + $this->assertSame($attribute, $value->getAttribute()); + + $value->setAttribute($attribute); + $this->assertSame($attribute, $value->getAttribute()); + } +} diff --git a/More/EAV/Value.php b/More/EAV/Value.php new file mode 100644 index 0000000..2c156a9 --- /dev/null +++ b/More/EAV/Value.php @@ -0,0 +1,70 @@ +addValue($this); + $this->attribute = $attribute; + } + + /** + * @param Attribute $attribute + * + * @return $this + */ + public function setAttribute(Attribute $attribute) + { + $this->attribute->removeValue($this); // Remove value from current attribute + $attribute->addValue($this); // Add value to new attribute + $this->attribute = $attribute; + + return $this; + } + + /** + * @return Attribute + */ + public function getAttribute() + { + return $this->attribute; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } +} diff --git a/More/EAV/ValueAccessInterface.php b/More/EAV/ValueAccessInterface.php new file mode 100644 index 0000000..dde67b2 --- /dev/null +++ b/More/EAV/ValueAccessInterface.php @@ -0,0 +1,24 @@ +setName('Color'); +// Create color values +$colorSilver = (new Value($color))->setName('Silver'); +$colorGold = (new Value($color))->setName('Gold'); +$colorSpaceGrey = (new Value($color))->setName('Space Grey'); + +// Create memory attribute +$memory = (new Attribute())->setName('Memory'); +// Create memory values +$memory4Gb = (new Value($memory))->setName('4GB'); +$memory8Gb = (new Value($memory))->setName('8GB'); +$memory16Gb = (new Value($memory))->setName('16GB'); + +// Create storage attribute +$storage = (new Attribute())->setName('Storage'); +// Create storage values +$storage128Gb = (new Value($storage))->setName('128GB'); +$storage256Gb = (new Value($storage))->setName('256GB'); +$storage512Gb = (new Value($storage))->setName('512GB'); +$storage1Tb = (new Value($storage))->setName('1TB'); + +// Create entities with specific values +$mac = (new Entity()) + ->setName('MacBook') + // colors + ->addValue($colorSilver) + ->addValue($colorGold) + ->addValue($colorSpaceGrey) + // memories + ->addValue($memory8Gb) + // storages + ->addValue($storage256Gb) + ->addValue($storage512Gb); + +$macAir = (new Entity()) + ->setName('MacBook Air') + // colors + ->addValue($colorSilver) + // memories + ->addValue($memory4Gb) + ->addValue($memory8Gb) + // storages + ->addValue($storage128Gb) + ->addValue($storage256Gb) + ->addValue($storage512Gb); + +$macPro = (new Entity()) + ->setName('MacBook Pro') + // colors + ->addValue($colorSilver) + // memories + ->addValue($memory8Gb) + ->addValue($memory16Gb) + // storages + ->addValue($storage128Gb) + ->addValue($storage256Gb) + ->addValue($storage512Gb) + ->addValue($storage1Tb); diff --git a/More/EAV/uml/EAV.uml b/More/EAV/uml/EAV.uml new file mode 100644 index 0000000..1b08466 --- /dev/null +++ b/More/EAV/uml/EAV.uml @@ -0,0 +1,43 @@ + + + PHP + \DesignPatterns\More\Delegation\JuniorDeveloper + + \DesignPatterns\More\EAV\Entity + \DesignPatterns\More\EAV\Value + \DesignPatterns\More\EAV\Attribute + \DesignPatterns\More\EAV\ValueAccessInterface + \DesignPatterns\More\EAV\ValueInterface + + + + + + + + + + + + + + + + + + + + + + + \DesignPatterns\More\EAV\ValueAccessInterface + + + Fields + Constants + Constructors + Methods + + private + + diff --git a/More/EAV/uml/uml.png b/More/EAV/uml/uml.png new file mode 100644 index 0000000..22e9b77 Binary files /dev/null and b/More/EAV/uml/uml.png differ diff --git a/More/EAV/uml/uml.svg b/More/EAV/uml/uml.svg new file mode 100644 index 0000000..26ff3cc --- /dev/null +++ b/More/EAV/uml/uml.svg @@ -0,0 +1,668 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + getValues() + + + + + + + + + + addValue(value) + + + + + + + + + + removeValue(value) + + + + + + + + + + + + + ValueAccessInterface + + + ValueAccessInterface + + + + + + + + + + + + + + + + + + + values + + + + + + + + + + name + + + + + + + + + + + + + getValues() + + + + + + + + + + addValue(value) + + + + + + + + + + removeValue(value) + + + + + + + + + + getName() + + + + + + + + + + setName(name) + + + + + + + + + + + + + Attribute + + + Attribute + + + + + + + + + + + + + + + + + + + values + + + + + + + + + + name + + + + + + + + + + + + + getValues() + + + + + + + + + + addValue(value) + + + + + + + + + + removeValue(value) + + + + + + + + + + getName() + + + + + + + + + + setName(name) + + + + + + + + + + + + + Entity + + + Entity + + + + + + + + + + + + + + + + + + + __construct(attribute) + + + + + + + + + + + + + setAttribute(attribute) + + + + + + + + + + getAttribute() + + + + + + + + + + + + + ValueInterface + + + ValueInterface + + + + + + + + + + + + + + + + + + + attribute + + + + + + + + + + name + + + + + + + + + + + + + __construct(attribute) + + + + + + + + + + + + + setAttribute(attribute) + + + + + + + + + + getAttribute() + + + + + + + + + + getName() + + + + + + + + + + setName(name) + + + + + + + + + + + + + Value + + + Value + + + + + + + + + + + + + diff --git a/More/README.md b/More/README.md index 7667a62..cba33e7 100644 --- a/More/README.md +++ b/More/README.md @@ -3,3 +3,4 @@ * [Delegation](Delegation) [:notebook:](http://en.wikipedia.org/wiki/Delegation_pattern) * [ServiceLocator](ServiceLocator) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) * [Repository](Repository) +* [EAV](EAV) [:notebook:](https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model) diff --git a/More/Repository/MemoryStorage.php b/More/Repository/MemoryStorage.php index 3021e96..44276d5 100644 --- a/More/Repository/MemoryStorage.php +++ b/More/Repository/MemoryStorage.php @@ -1,14 +1,12 @@ data[++$this->lastId] = $data; + return $this->lastId; } diff --git a/More/Repository/Post.php b/More/Repository/Post.php index 227daaf..e9990b4 100644 --- a/More/Repository/Post.php +++ b/More/Repository/Post.php @@ -1,12 +1,11 @@ persistence->retrieve($id); if (is_null($arrayData)) { - return null; + return; } $post = new Post(); @@ -48,9 +48,10 @@ class PostRepository } /** - * Save post object and populate it with id + * Save post object and populate it with id. * * @param Post $post + * * @return Post */ public function save(Post $post) @@ -59,17 +60,19 @@ class PostRepository 'author' => $post->getAuthor(), 'created' => $post->getCreated(), 'text' => $post->getText(), - 'title' => $post->getTitle() + 'title' => $post->getTitle(), )); $post->setId($id); + return $post; } /** - * Deletes specified Post object + * Deletes specified Post object. * * @param Post $post + * * @return bool */ public function delete(Post $post) diff --git a/More/Repository/Storage.php b/More/Repository/Storage.php index 58313b0..a730f09 100644 --- a/More/Repository/Storage.php +++ b/More/Repository/Storage.php @@ -1,40 +1,41 @@ - - PHP - \DesignPatterns\Repository\PostRepository - - \DesignPatterns\Repository\Storage - \DesignPatterns\Repository\MemoryStorage - \DesignPatterns\Repository\Post - \DesignPatterns\Repository\PostRepository - - - - - - - - - - - - Fields - Constants - Constructors - Methods - - private - - + + + PHP + \DesignPatterns\More\Repository\PostRepository + + \DesignPatterns\More\Repository\Storage + \DesignPatterns\More\Repository\MemoryStorage + \DesignPatterns\More\Repository\Post + \DesignPatterns\More\Repository\PostRepository + + + + + + + + + + + + Fields + Constants + Constructors + Methods + + private + + diff --git a/More/ServiceLocator/ServiceLocator.php b/More/ServiceLocator/ServiceLocator.php index 6699eca..b631479 100644 --- a/More/ServiceLocator/ServiceLocator.php +++ b/More/ServiceLocator/ServiceLocator.php @@ -27,21 +27,21 @@ class ServiceLocator implements ServiceLocatorInterface public function __construct() { - $this->services = array(); + $this->services = array(); $this->instantiated = array(); - $this->shared = array(); + $this->shared = array(); } /** * Registers a service with specific interface. * - * @param string $interface + * @param string $interface * @param string|object $service - * @param bool $share + * @param bool $share */ public function add($interface, $service, $share = true) { - /** + /* * When you add a service, you should register it * with its interface or with a string that you can use * in the future even if you will change the service implementation. @@ -51,7 +51,7 @@ class ServiceLocator implements ServiceLocatorInterface $this->instantiated[$interface] = $service; } $this->services[$interface] = (is_object($service) ? get_class($service) : $service); - $this->shared[$interface] = $share; + $this->shared[$interface] = $share; } /** @@ -63,7 +63,7 @@ class ServiceLocator implements ServiceLocatorInterface */ public function has($interface) { - return (isset($this->services[$interface]) || isset($this->instantiated[$interface])); + return isset($this->services[$interface]) || isset($this->instantiated[$interface]); } /** @@ -101,6 +101,7 @@ class ServiceLocator implements ServiceLocatorInterface if ($this->shared[$interface]) { $this->instantiated[$interface] = $object; } + return $object; } } diff --git a/More/ServiceLocator/Tests/ServiceLocatorTest.php b/More/ServiceLocator/Tests/ServiceLocatorTest.php index d6b7ef6..72f8607 100644 --- a/More/ServiceLocator/Tests/ServiceLocatorTest.php +++ b/More/ServiceLocator/Tests/ServiceLocatorTest.php @@ -5,7 +5,7 @@ namespace DesignPatterns\More\ServiceLocator\Tests; use DesignPatterns\More\ServiceLocator\DatabaseService; use DesignPatterns\More\ServiceLocator\LogService; use DesignPatterns\More\ServiceLocator\ServiceLocator; -use \PHPUnit_Framework_TestCase as TestCase; +use PHPUnit_Framework_TestCase as TestCase; class ServiceLocatorTest extends TestCase { @@ -26,8 +26,8 @@ class ServiceLocatorTest extends TestCase public function setUp() { - $this->serviceLocator = new ServiceLocator(); - $this->logService = new LogService(); + $this->serviceLocator = new ServiceLocator(); + $this->logService = new LogService(); $this->databaseService = new DatabaseService(); } diff --git a/README.md b/README.md index 0d9e054..440185f 100755 --- a/README.md +++ b/README.md @@ -13,12 +13,32 @@ I think the problem with patterns is that often people do know them but don't kn You should look at and run the tests to see what happens in the example. To do this, you should install dependencies with `Composer` first: +### [optional] Using a Virtual Machine (VM) + +If you wish to use a ready made VM environment, you can easily create one with Vagrant and Ansible. + +```bash +$ vagrant up +``` + +Then `vagrant ssh` and `cd /vagrant` + +More information on [vagrant](https://www.vagrantup.com) + +### Install dependencies + ```bash $ composer install ``` Read more about how to install and use `Composer` on your local machine [here](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx). +### Running test suite + +```bash +$ ./vendor/bin/phpunit +``` + ## Patterns The patterns can be structured in roughly three different categories. Please click on the [:notebook:](http://en.wikipedia.org/wiki/Software_design_pattern) for a full explanation of the pattern on Wikipedia. @@ -67,6 +87,7 @@ The patterns can be structured in roughly three different categories. Please cli * [Delegation](More/Delegation) [:notebook:](http://en.wikipedia.org/wiki/Delegation_pattern) * [ServiceLocator](More/ServiceLocator) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) * [Repository](More/Repository) +* [EAV](More/EAV) [:notebook:](https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model) ## Contribute diff --git a/Structural/Adapter/Book.php b/Structural/Adapter/Book.php index ae3c6dc..6458beb 100644 --- a/Structural/Adapter/Book.php +++ b/Structural/Adapter/Book.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\Adapter; /** - * Book is a concrete and standard paper book + * Book is a concrete and standard paper book. */ class Book implements PaperBookInterface { diff --git a/Structural/Adapter/EBookAdapter.php b/Structural/Adapter/EBookAdapter.php index a6c6476..3e4564a 100644 --- a/Structural/Adapter/EBookAdapter.php +++ b/Structural/Adapter/EBookAdapter.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\Adapter; /** - * EBookAdapter is an adapter to fit an e-book like a paper book + * EBookAdapter is an adapter to fit an e-book like a paper book. * * This is the adapter here. Notice it implements PaperBookInterface, * therefore you don't have to change the code of the client which using paper book. @@ -16,7 +16,7 @@ class EBookAdapter implements PaperBookInterface protected $eBook; /** - * Notice the constructor, it "wraps" an electronic book + * Notice the constructor, it "wraps" an electronic book. * * @param EBookInterface $ebook */ @@ -26,7 +26,7 @@ class EBookAdapter implements PaperBookInterface } /** - * This class makes the proper translation from one interface to another + * This class makes the proper translation from one interface to another. */ public function open() { @@ -34,7 +34,7 @@ class EBookAdapter implements PaperBookInterface } /** - * turns pages + * turns pages. */ public function turnPage() { diff --git a/Structural/Adapter/EBookInterface.php b/Structural/Adapter/EBookInterface.php index 15e0222..bd3dc26 100644 --- a/Structural/Adapter/EBookInterface.php +++ b/Structural/Adapter/EBookInterface.php @@ -3,19 +3,19 @@ namespace DesignPatterns\Structural\Adapter; /** - * EBookInterface is a contract for an electronic book + * EBookInterface is a contract for an electronic book. */ interface EBookInterface { /** - * go to next page + * go to next page. * * @return mixed */ public function pressNext(); /** - * start the book + * start the book. * * @return mixed */ diff --git a/Structural/Adapter/Kindle.php b/Structural/Adapter/Kindle.php index 14dc485..06d4489 100644 --- a/Structural/Adapter/Kindle.php +++ b/Structural/Adapter/Kindle.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\Adapter; /** - * Kindle is a concrete electronic book + * Kindle is a concrete electronic book. */ class Kindle implements EBookInterface { diff --git a/Structural/Adapter/PaperBookInterface.php b/Structural/Adapter/PaperBookInterface.php index 12f3103..4b62149 100644 --- a/Structural/Adapter/PaperBookInterface.php +++ b/Structural/Adapter/PaperBookInterface.php @@ -3,19 +3,19 @@ namespace DesignPatterns\Structural\Adapter; /** - * PaperBookInterface is a contract for a book + * PaperBookInterface is a contract for a book. */ interface PaperBookInterface { /** - * method to turn pages + * method to turn pages. * * @return mixed */ public function turnPage(); /** - * method to open the book + * method to open the book. * * @return mixed */ diff --git a/Structural/Adapter/Tests/AdapterTest.php b/Structural/Adapter/Tests/AdapterTest.php index 258e755..fd7713b 100644 --- a/Structural/Adapter/Tests/AdapterTest.php +++ b/Structural/Adapter/Tests/AdapterTest.php @@ -2,14 +2,14 @@ namespace DesignPatterns\Structural\Adapter\Tests; +use DesignPatterns\Structural\Adapter\Book; use DesignPatterns\Structural\Adapter\EBookAdapter; use DesignPatterns\Structural\Adapter\Kindle; use DesignPatterns\Structural\Adapter\PaperBookInterface; -use DesignPatterns\Structural\Adapter\Book; /** * AdapterTest shows the use of an adapted e-book that behave like a book - * You don't have to change the code of your client + * You don't have to change the code of your client. */ class AdapterTest extends \PHPUnit_Framework_TestCase { @@ -21,13 +21,13 @@ class AdapterTest extends \PHPUnit_Framework_TestCase return array( array(new Book()), // we build a "wrapped" electronic book in the adapter - array(new EBookAdapter(new Kindle())) + array(new EBookAdapter(new Kindle())), ); } /** * This client only knows paper book but surprise, surprise, the second book - * is in fact an electronic book, but both work the same way + * is in fact an electronic book, but both work the same way. * * @param PaperBookInterface $book * @@ -35,7 +35,7 @@ class AdapterTest extends \PHPUnit_Framework_TestCase */ public function testIAmAnOldClient(PaperBookInterface $book) { - $book->open(); - $book->turnPage(); + $this->assertTrue(method_exists($book, 'open')); + $this->assertTrue(method_exists($book, 'turnPage')); } } diff --git a/Structural/Bridge/Assemble.php b/Structural/Bridge/Assemble.php index 2b60889..9b9d114 100644 --- a/Structural/Bridge/Assemble.php +++ b/Structural/Bridge/Assemble.php @@ -4,9 +4,8 @@ namespace DesignPatterns\Structural\Bridge; class Assemble implements Workshop { - public function work() { - print 'Assembled'; + echo 'Assembled'; } } diff --git a/Structural/Bridge/Car.php b/Structural/Bridge/Car.php index 2754199..89be431 100644 --- a/Structural/Bridge/Car.php +++ b/Structural/Bridge/Car.php @@ -3,11 +3,10 @@ namespace DesignPatterns\Structural\Bridge; /** - * Refined Abstraction + * Refined Abstraction. */ class Car extends Vehicle { - public function __construct(Workshop $workShop1, Workshop $workShop2) { parent::__construct($workShop1, $workShop2); @@ -15,7 +14,7 @@ class Car extends Vehicle public function manufacture() { - print 'Car '; + echo 'Car '; $this->workShop1->work(); $this->workShop2->work(); } diff --git a/Structural/Bridge/Motorcycle.php b/Structural/Bridge/Motorcycle.php index b021ce6..f008785 100644 --- a/Structural/Bridge/Motorcycle.php +++ b/Structural/Bridge/Motorcycle.php @@ -3,11 +3,10 @@ namespace DesignPatterns\Structural\Bridge; /** - * Refined Abstraction + * Refined Abstraction. */ class Motorcycle extends Vehicle { - public function __construct(Workshop $workShop1, Workshop $workShop2) { parent::__construct($workShop1, $workShop2); @@ -15,7 +14,7 @@ class Motorcycle extends Vehicle public function manufacture() { - print 'Motorcycle '; + echo 'Motorcycle '; $this->workShop1->work(); $this->workShop2->work(); } diff --git a/Structural/Bridge/Produce.php b/Structural/Bridge/Produce.php index b2b0505..a382f2d 100644 --- a/Structural/Bridge/Produce.php +++ b/Structural/Bridge/Produce.php @@ -3,13 +3,12 @@ namespace DesignPatterns\Structural\Bridge; /** - * Concrete Implementation + * Concrete Implementation. */ class Produce implements Workshop { - public function work() { - print 'Produced '; + echo 'Produced '; } } diff --git a/Structural/Bridge/Tests/BridgeTest.php b/Structural/Bridge/Tests/BridgeTest.php index e07afe9..0a89a86 100644 --- a/Structural/Bridge/Tests/BridgeTest.php +++ b/Structural/Bridge/Tests/BridgeTest.php @@ -9,7 +9,6 @@ use DesignPatterns\Structural\Bridge\Produce; class BridgeTest extends \PHPUnit_Framework_TestCase { - public function testCar() { $vehicle = new Car(new Produce(), new Assemble()); diff --git a/Structural/Bridge/Vehicle.php b/Structural/Bridge/Vehicle.php index 10b0d03..f519d70 100644 --- a/Structural/Bridge/Vehicle.php +++ b/Structural/Bridge/Vehicle.php @@ -3,11 +3,10 @@ namespace DesignPatterns\Structural\Bridge; /** - * Abstraction + * Abstraction. */ abstract class Vehicle { - protected $workShop1; protected $workShop2; diff --git a/Structural/Bridge/Workshop.php b/Structural/Bridge/Workshop.php index dc62886..9cb26c5 100644 --- a/Structural/Bridge/Workshop.php +++ b/Structural/Bridge/Workshop.php @@ -3,10 +3,9 @@ namespace DesignPatterns\Structural\Bridge; /** - * Implementer + * Implementer. */ interface Workshop { - public function work(); } diff --git a/Structural/Composite/Form.php b/Structural/Composite/Form.php index fbf3b50..42f1bc1 100644 --- a/Structural/Composite/Form.php +++ b/Structural/Composite/Form.php @@ -15,7 +15,7 @@ class Form extends FormElement /** * runs through all elements and calls render() on them, then returns the complete representation - * of the form + * of the form. * * from the outside, one will not see this and the form will act like a single object instance * @@ -28,7 +28,7 @@ class Form extends FormElement $formCode = ''; foreach ($this->elements as $element) { - $formCode .= $element->render($indent + 1) . PHP_EOL; + $formCode .= $element->render($indent + 1).PHP_EOL; } return $formCode; diff --git a/Structural/Composite/FormElement.php b/Structural/Composite/FormElement.php index 8063c89..0055aee 100644 --- a/Structural/Composite/FormElement.php +++ b/Structural/Composite/FormElement.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Structural\Composite; /** - * Class FormElement + * Class FormElement. */ abstract class FormElement { /** - * renders the elements' code + * renders the elements' code. * * @param int $indent * diff --git a/Structural/Composite/InputElement.php b/Structural/Composite/InputElement.php index 30d8615..19786d5 100644 --- a/Structural/Composite/InputElement.php +++ b/Structural/Composite/InputElement.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Structural\Composite; /** - * Class InputElement + * Class InputElement. */ class InputElement extends FormElement { /** - * renders the input element HTML + * renders the input element HTML. * * @param int $indent * @@ -16,6 +16,6 @@ class InputElement extends FormElement */ public function render($indent = 0) { - return str_repeat(' ', $indent) . ''; + return str_repeat(' ', $indent).''; } } diff --git a/Structural/Composite/Tests/CompositeTest.php b/Structural/Composite/Tests/CompositeTest.php index 71aa98e..510a06b 100644 --- a/Structural/Composite/Tests/CompositeTest.php +++ b/Structural/Composite/Tests/CompositeTest.php @@ -1,15 +1,14 @@ 1, + 'userid' => 1, 'username' => 'Odysseus', - 'email' => 'Odysseus@ithaca.gr' + 'email' => 'Odysseus@ithaca.gr', ); $rows = new \ArrayIterator(array($row)); $this->dbal->expects($this->once()) diff --git a/Structural/DataMapper/User.php b/Structural/DataMapper/User.php index 78e60a8..8d8d2b2 100644 --- a/Structural/DataMapper/User.php +++ b/Structural/DataMapper/User.php @@ -3,12 +3,11 @@ namespace DesignPatterns\Structural\DataMapper; /** - * DataMapper pattern + * DataMapper pattern. * * This is our representation of a DataBase record in the memory (Entity) * * Validation would also go in this object - * */ class User { diff --git a/Structural/DataMapper/UserMapper.php b/Structural/DataMapper/UserMapper.php index 0ee5352..f147063 100644 --- a/Structural/DataMapper/UserMapper.php +++ b/Structural/DataMapper/UserMapper.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\DataMapper; /** - * class UserMapper + * class UserMapper. */ class UserMapper { @@ -21,19 +21,19 @@ class UserMapper } /** - * saves a user object from memory to Database + * saves a user object from memory to Database. * * @param User $user * - * @return boolean + * @return bool */ public function save(User $user) { /* $data keys should correspond to valid Table columns on the Database */ $data = array( - 'userid' => $user->getUserId(), + 'userid' => $user->getUserId(), 'username' => $user->getUsername(), - 'email' => $user->getEmail(), + 'email' => $user->getEmail(), ); /* if no ID specified create new user else update the one in the Database */ @@ -51,11 +51,12 @@ class UserMapper /** * finds a user from Database based on ID and returns a User object located - * in memory + * in memory. * * @param int $id * * @throws \InvalidArgumentException + * * @return User */ public function findById($id) @@ -72,14 +73,14 @@ class UserMapper /** * fetches an array from Database and returns an array of User objects - * located in memory + * located in memory. * * @return array */ public function findAll() { $resultSet = $this->adapter->findAll(); - $entries = array(); + $entries = array(); foreach ($resultSet as $row) { $entries[] = $this->mapObject($row); @@ -89,7 +90,7 @@ class UserMapper } /** - * Maps a table row to an object + * Maps a table row to an object. * * @param array $row * diff --git a/Structural/Decorator/Decorator.php b/Structural/Decorator/Decorator.php index 182c07a..0b8fde3 100644 --- a/Structural/Decorator/Decorator.php +++ b/Structural/Decorator/Decorator.php @@ -9,7 +9,7 @@ namespace DesignPatterns\Structural\Decorator; */ /** - * class Decorator + * class Decorator. */ abstract class Decorator implements RendererInterface { diff --git a/Structural/Decorator/RenderInJson.php b/Structural/Decorator/RenderInJson.php index ebcc577..71943bd 100644 --- a/Structural/Decorator/RenderInJson.php +++ b/Structural/Decorator/RenderInJson.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Structural\Decorator; /** - * Class RenderInJson + * Class RenderInJson. */ class RenderInJson extends Decorator { /** - * render data as JSON + * render data as JSON. * * @return mixed|string */ diff --git a/Structural/Decorator/RenderInXml.php b/Structural/Decorator/RenderInXml.php index f8e92a0..2eab7ca 100644 --- a/Structural/Decorator/RenderInXml.php +++ b/Structural/Decorator/RenderInXml.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Structural\Decorator; /** - * Class RenderInXml + * Class RenderInXml. */ class RenderInXml extends Decorator { /** - * render data as XML + * render data as XML. * * @return mixed|string */ diff --git a/Structural/Decorator/RendererInterface.php b/Structural/Decorator/RendererInterface.php index 2957970..92b00ef 100644 --- a/Structural/Decorator/RendererInterface.php +++ b/Structural/Decorator/RendererInterface.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Structural\Decorator; /** - * Class RendererInterface + * Class RendererInterface. */ interface RendererInterface { /** - * render data + * render data. * * @return mixed */ diff --git a/Structural/Decorator/Tests/DecoratorTest.php b/Structural/Decorator/Tests/DecoratorTest.php index 1789870..689caf2 100644 --- a/Structural/Decorator/Tests/DecoratorTest.php +++ b/Structural/Decorator/Tests/DecoratorTest.php @@ -5,11 +5,10 @@ namespace DesignPatterns\Structural\Decorator\Tests; use DesignPatterns\Structural\Decorator; /** - * DecoratorTest tests the decorator pattern + * DecoratorTest tests the decorator pattern. */ class DecoratorTest extends \PHPUnit_Framework_TestCase { - protected $service; protected function setUp() @@ -27,7 +26,7 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase public function testXmlDecorator() { - // Wrap service with a JSON decorator for renderers + // Wrap service with a XML decorator for renderers $service = new Decorator\RenderInXml($this->service); // Our Renderer will now output XML instead of an array $xml = 'bar'; @@ -35,7 +34,7 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase } /** - * The first key-point of this pattern : + * The first key-point of this pattern :. */ public function testDecoratorMustImplementsRenderer() { @@ -45,17 +44,32 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase } /** - * Second key-point of this pattern : the decorator is type-hinted + * Second key-point of this pattern : the decorator is type-hinted. * * @expectedException \PHPUnit_Framework_Error */ public function testDecoratorTypeHinted() { + if (version_compare(PHP_VERSION, '7', '>=')) { + throw new \PHPUnit_Framework_Error('Skip test for PHP 7', 0, __FILE__, __LINE__); + } + $this->getMockForAbstractClass('DesignPatterns\Structural\Decorator\Decorator', array(new \stdClass())); } /** - * The decorator implements and wraps the same interface + * Second key-point of this pattern : the decorator is type-hinted. + * + * @requires PHP 7 + * @expectedException TypeError + */ + public function testDecoratorTypeHintedForPhp7() + { + $this->getMockForAbstractClass('DesignPatterns\Structural\Decorator\Decorator', array(new \stdClass())); + } + + /** + * The decorator implements and wraps the same interface. */ public function testDecoratorOnlyAcceptRenderer() { diff --git a/Structural/Decorator/Webservice.php b/Structural/Decorator/Webservice.php index e6bf306..e2bcc69 100644 --- a/Structural/Decorator/Webservice.php +++ b/Structural/Decorator/Webservice.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\Decorator; /** - * Class Webservice + * Class Webservice. */ class Webservice implements RendererInterface { diff --git a/Structural/DependencyInjection/AbstractConfig.php b/Structural/DependencyInjection/AbstractConfig.php index 85e5245..f2da4dc 100644 --- a/Structural/DependencyInjection/AbstractConfig.php +++ b/Structural/DependencyInjection/AbstractConfig.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\DependencyInjection; /** - * class AbstractConfig + * class AbstractConfig. */ abstract class AbstractConfig { diff --git a/Structural/DependencyInjection/ArrayConfig.php b/Structural/DependencyInjection/ArrayConfig.php index 91bca33..f26c089 100644 --- a/Structural/DependencyInjection/ArrayConfig.php +++ b/Structural/DependencyInjection/ArrayConfig.php @@ -3,17 +3,18 @@ namespace DesignPatterns\Structural\DependencyInjection; /** - * class ArrayConfig + * class ArrayConfig. * * uses array as data source */ class ArrayConfig extends AbstractConfig implements Parameters { /** - * Get parameter + * Get parameter. * * @param string|int $key - * @param null $default + * @param null $default + * * @return mixed */ public function get($key, $default = null) @@ -21,14 +22,15 @@ class ArrayConfig extends AbstractConfig implements Parameters if (isset($this->storage[$key])) { return $this->storage[$key]; } + return $default; } /** - * Set parameter + * Set parameter. * * @param string|int $key - * @param mixed $value + * @param mixed $value */ public function set($key, $value) { diff --git a/Structural/DependencyInjection/Connection.php b/Structural/DependencyInjection/Connection.php index 9e131c2..d389089 100644 --- a/Structural/DependencyInjection/Connection.php +++ b/Structural/DependencyInjection/Connection.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\DependencyInjection; /** - * Class Connection + * Class Connection. */ class Connection { @@ -26,7 +26,7 @@ class Connection } /** - * connection using the injected config + * connection using the injected config. */ public function connect() { @@ -42,6 +42,7 @@ class Connection * * @return string */ + public function getHost() { return $this->host; diff --git a/Structural/DependencyInjection/Parameters.php b/Structural/DependencyInjection/Parameters.php index dabe895..c49f4c7 100644 --- a/Structural/DependencyInjection/Parameters.php +++ b/Structural/DependencyInjection/Parameters.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Structural\DependencyInjection; /** - * Parameters interface + * Parameters interface. */ interface Parameters { /** - * Get parameter + * Get parameter. * * @param string|int $key * @@ -17,7 +17,7 @@ interface Parameters public function get($key); /** - * Set parameter + * Set parameter. * * @param string|int $key * @param mixed $value diff --git a/Structural/Facade/BiosInterface.php b/Structural/Facade/BiosInterface.php index 869dcd9..823af04 100644 --- a/Structural/Facade/BiosInterface.php +++ b/Structural/Facade/BiosInterface.php @@ -3,29 +3,29 @@ namespace DesignPatterns\Structural\Facade; /** - * Class BiosInterface + * Class BiosInterface. */ interface BiosInterface { /** - * execute the BIOS + * execute the BIOS. */ public function execute(); /** - * wait for halt + * wait for halt. */ public function waitForKeyPress(); /** - * launches the OS + * launches the OS. * * @param OsInterface $os */ public function launch(OsInterface $os); /** - * power down BIOS + * power down BIOS. */ public function powerDown(); } diff --git a/Structural/Facade/Facade.php b/Structural/Facade/Facade.php index c0048b4..50c665d 100644 --- a/Structural/Facade/Facade.php +++ b/Structural/Facade/Facade.php @@ -3,7 +3,6 @@ namespace DesignPatterns\Structural\Facade; /** - * * */ class Facade @@ -20,7 +19,7 @@ class Facade /** * This is the perfect time to use a dependency injection container - * to create an instance of this class + * to create an instance of this class. * * @param BiosInterface $bios * @param OsInterface $os @@ -32,7 +31,7 @@ class Facade } /** - * turn on the system + * turn on the system. */ public function turnOn() { @@ -42,7 +41,7 @@ class Facade } /** - * turn off the system + * turn off the system. */ public function turnOff() { diff --git a/Structural/Facade/OsInterface.php b/Structural/Facade/OsInterface.php index 3b09eb1..8394fd4 100644 --- a/Structural/Facade/OsInterface.php +++ b/Structural/Facade/OsInterface.php @@ -3,12 +3,12 @@ namespace DesignPatterns\Structural\Facade; /** - * Class OsInterface + * Class OsInterface. */ interface OsInterface { /** - * halt the OS + * halt the OS. */ public function halt(); } diff --git a/Structural/Facade/Tests/FacadeTest.php b/Structural/Facade/Tests/FacadeTest.php index eccb9be..e6038a0 100644 --- a/Structural/Facade/Tests/FacadeTest.php +++ b/Structural/Facade/Tests/FacadeTest.php @@ -3,13 +3,13 @@ namespace DesignPatterns\Structural\Facade\Tests; use DesignPatterns\Structural\Facade\Facade as Computer; +use DesignPatterns\Structural\Facade\OsInterface; /** - * FacadeTest shows example of facades + * FacadeTest shows example of facades. */ class FacadeTest extends \PHPUnit_Framework_TestCase { - public function getComputer() { $bios = $this->getMockBuilder('DesignPatterns\Structural\Facade\BiosInterface') @@ -29,13 +29,14 @@ class FacadeTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue('Linux')); $facade = new Computer($bios, $operatingSys); + return array(array($facade, $operatingSys)); } /** * @dataProvider getComputer */ - public function testComputerOn(Computer $facade, $os) + public function testComputerOn(Computer $facade, OsInterface $os) { // interface is simpler : $facade->turnOn(); diff --git a/Structural/FluentInterface/Sql.php b/Structural/FluentInterface/Sql.php index 35af3ef..58ba491 100644 --- a/Structural/FluentInterface/Sql.php +++ b/Structural/FluentInterface/Sql.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\FluentInterface; /** - * class SQL + * class SQL. */ class Sql { @@ -23,7 +23,7 @@ class Sql protected $where = array(); /** - * adds select fields + * adds select fields. * * @param array $fields * @@ -37,7 +37,7 @@ class Sql } /** - * adds a FROM clause + * adds a FROM clause. * * @param string $table * @param string $alias @@ -46,13 +46,13 @@ class Sql */ public function from($table, $alias) { - $this->from[] = $table . ' AS ' . $alias; + $this->from[] = $table.' AS '.$alias; return $this; } /** - * adds a WHERE condition + * adds a WHERE condition. * * @param string $condition * @@ -67,14 +67,14 @@ class Sql /** * Gets the query, just an example of building a query, - * no check on consistency + * no check on consistency. * * @return string */ public function getQuery() { - return 'SELECT ' . implode(',', $this->fields) - . ' FROM ' . implode(',', $this->from) - . ' WHERE ' . implode(' AND ', $this->where); + return 'SELECT '.implode(',', $this->fields) + .' FROM '.implode(',', $this->from) + .' WHERE '.implode(' AND ', $this->where); } } diff --git a/Structural/FluentInterface/Tests/FluentInterfaceTest.php b/Structural/FluentInterface/Tests/FluentInterfaceTest.php index 98ea99d..ae4e656 100644 --- a/Structural/FluentInterface/Tests/FluentInterfaceTest.php +++ b/Structural/FluentInterface/Tests/FluentInterfaceTest.php @@ -5,11 +5,10 @@ namespace DesignPatterns\Structural\FluentInterface\Tests; use DesignPatterns\Structural\FluentInterface\Sql; /** - * FluentInterfaceTest tests the fluent interface SQL + * FluentInterfaceTest tests the fluent interface SQL. */ class FluentInterfaceTest extends \PHPUnit_Framework_TestCase { - public function testBuildSQL() { $instance = new Sql(); diff --git a/Structural/Proxy/Record.php b/Structural/Proxy/Record.php index 38481aa..7ae4a3c 100644 --- a/Structural/Proxy/Record.php +++ b/Structural/Proxy/Record.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\Proxy; /** - * class Record + * class Record. */ class Record { @@ -21,7 +21,7 @@ class Record } /** - * magic setter + * magic setter. * * @param string $name * @param mixed $value @@ -34,7 +34,7 @@ class Record } /** - * magic getter + * magic getter. * * @param string $name * @@ -45,7 +45,7 @@ class Record if (array_key_exists($name, $this->data)) { return $this->data[(string) $name]; } else { - return null; + return; } } } diff --git a/Structural/Proxy/RecordProxy.php b/Structural/Proxy/RecordProxy.php index 1f68cff..f8c78a8 100644 --- a/Structural/Proxy/RecordProxy.php +++ b/Structural/Proxy/RecordProxy.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\Proxy; /** - * Class RecordProxy + * Class RecordProxy. */ class RecordProxy extends Record { @@ -35,7 +35,7 @@ class RecordProxy extends Record } /** - * magic setter + * magic setter. * * @param string $name * @param mixed $value diff --git a/Structural/Registry/Registry.php b/Structural/Registry/Registry.php index d1c6b13..e40d0c3 100644 --- a/Structural/Registry/Registry.php +++ b/Structural/Registry/Registry.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Structural\Registry; /** - * class Registry + * class Registry. */ abstract class Registry { @@ -15,12 +15,13 @@ abstract class Registry protected static $storedValues = array(); /** - * sets a value + * sets a value. * * @param string $key * @param mixed $value * * @static + * * @return void */ public static function set($key, $value) @@ -29,11 +30,12 @@ abstract class Registry } /** - * gets a value from the registry + * gets a value from the registry. * * @param string $key * * @static + * * @return mixed */ public static function get($key) diff --git a/Structural/Registry/Tests/RegistryTest.php b/Structural/Registry/Tests/RegistryTest.php index 64685d4..9561abe 100644 --- a/Structural/Registry/Tests/RegistryTest.php +++ b/Structural/Registry/Tests/RegistryTest.php @@ -6,12 +6,15 @@ use DesignPatterns\Structural\Registry\Registry; class RegistryTest extends \PHPUnit_Framework_TestCase { - public function testSetAndGetLogger() { - Registry::set(Registry::LOGGER, new \StdClass()); + $key = Registry::LOGGER; + $object = new \StdClass(); - $logger = Registry::get(Registry::LOGGER); - $this->assertInstanceOf('StdClass', $logger); + Registry::set($key, $object); + $actual = Registry::get($key); + + $this->assertEquals($object, $actual); + $this->assertInstanceOf('StdClass', $actual); } } diff --git a/Vagrantfile b/Vagrantfile new file mode 100755 index 0000000..30f924c --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,59 @@ +################################################## +# Generated by phansible.com +################################################## + +#If your Vagrant version is lower than 1.5, you can still use this provisioning +#by commenting or removing the line below and providing the config.vm.box_url parameter, +#if it's not already defined in this Vagrantfile. Keep in mind that you won't be able +#to use the Vagrant Cloud and other newer Vagrant features. +Vagrant.require_version ">= 1.5" + +# Check to determine whether we're on a windows or linux/os-x host, +# later on we use this to launch ansible in the supported way +# source: https://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby +def which(cmd) + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + exts.each { |ext| + exe = File.join(path, "#{cmd}#{ext}") + return exe if File.executable? exe + } + end + return nil +end +Vagrant.configure("2") do |config| + + config.vm.provider :virtualbox do |v| + v.name = "design-patterns" + v.customize [ + "modifyvm", :id, + "--name", "design-patterns", + "--memory", 512, + "--natdnshostresolver1", "on", + "--cpus", 1, + ] + end + + config.vm.box = "ubuntu/trusty64" + + config.vm.network :private_network, ip: "192.168.11.2" + config.ssh.forward_agent = true + + ############################################################# + # Ansible provisioning (you need to have ansible installed) + ############################################################# + + + if which('ansible-playbook') + config.vm.provision "ansible" do |ansible| + ansible.playbook = "ansible/playbook.yml" + ansible.inventory_path = "ansible/inventories/dev" + ansible.limit = 'all' + end + else + config.vm.provision :shell, path: "ansible/windows.sh", args: ["default"] + end + + + config.vm.synced_folder "./", "/vagrant", type: "nfs" +end diff --git a/ansible/inventories/dev b/ansible/inventories/dev new file mode 100755 index 0000000..86d8f3b --- /dev/null +++ b/ansible/inventories/dev @@ -0,0 +1,2 @@ +[phansible-web] +192.168.11.2 diff --git a/ansible/playbook.yml b/ansible/playbook.yml new file mode 100755 index 0000000..33e3fda --- /dev/null +++ b/ansible/playbook.yml @@ -0,0 +1,11 @@ +--- +- hosts: all + sudo: true + vars_files: + - vars/all.yml + roles: + - server + - vagrant_local + - php + - xdebug + - app diff --git a/ansible/roles/app/tasks/main.yml b/ansible/roles/app/tasks/main.yml new file mode 100755 index 0000000..c330e48 --- /dev/null +++ b/ansible/roles/app/tasks/main.yml @@ -0,0 +1,5 @@ +--- +# application tasks to be customized and to run after the main provision +- name: update file db + sudo: yes + shell: updatedb diff --git a/ansible/roles/php/tasks/configure.yml b/ansible/roles/php/tasks/configure.yml new file mode 100755 index 0000000..1b093e7 --- /dev/null +++ b/ansible/roles/php/tasks/configure.yml @@ -0,0 +1,6 @@ +--- +- stat: path=/etc/php5/cli/php.ini + register: phpcli + +- include: php-cli.yml + when: phpcli.stat.exists diff --git a/ansible/roles/php/tasks/main.yml b/ansible/roles/php/tasks/main.yml new file mode 100755 index 0000000..38f2f78 --- /dev/null +++ b/ansible/roles/php/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- name: Add ppa Repository + sudo: yes + apt_repository: repo=ppa:ondrej/{{ php.ppa }} + +- name: Update apt + sudo: yes + apt: update_cache=yes + +- name: Install php5 + sudo: yes + apt: pkg=php5 state=latest + +- name: Install PHP Packages + sudo: yes + apt: pkg={{ item }} state=latest + with_items: php.packages + when: php.packages is defined + +- include: configure.yml diff --git a/ansible/roles/php/tasks/php-cli.yml b/ansible/roles/php/tasks/php-cli.yml new file mode 100755 index 0000000..e1cfffa --- /dev/null +++ b/ansible/roles/php/tasks/php-cli.yml @@ -0,0 +1,10 @@ +--- +- name: ensure timezone is set in cli php.ini + lineinfile: dest=/etc/php5/cli/php.ini + regexp='date.timezone =' + line='date.timezone = {{ server.timezone }}' + +- name: enabling opcache cli + lineinfile: dest=/etc/php5/cli/php.ini + regexp=';opcache.enable_cli=0' + line='opcache.enable_cli=1' diff --git a/ansible/roles/server/tasks/main.yml b/ansible/roles/server/tasks/main.yml new file mode 100755 index 0000000..f1ffc08 --- /dev/null +++ b/ansible/roles/server/tasks/main.yml @@ -0,0 +1,31 @@ +--- +- name: Update apt + sudo: yes + apt: update_cache=yes + +- name: Install System Packages + sudo: yes + apt: pkg={{ item }} state=latest + with_items: + - curl + - wget + - python-software-properties + +- name: Install Extra Packages + sudo: yes + apt: pkg={{ item }} state=latest + with_items: server.packages + when: server.packages is defined + +- name: Configure the timezone + sudo: yes + template: src=timezone.tpl dest=/etc/timezone + +- name: More Configure the timezone + sudo: yes + file: src=/usr/share/zoneinfo/{{server.timezone}} dest=/etc/localtime state=link force=yes backup=yes + +- name: Set default system language pack + shell: locale-gen {{server.locale}} + sudo: yes + diff --git a/ansible/roles/server/templates/timezone.tpl b/ansible/roles/server/templates/timezone.tpl new file mode 100755 index 0000000..cca2365 --- /dev/null +++ b/ansible/roles/server/templates/timezone.tpl @@ -0,0 +1 @@ +{{server.timezone}} diff --git a/ansible/roles/vagrant_local/tasks/main.yml b/ansible/roles/vagrant_local/tasks/main.yml new file mode 100755 index 0000000..cd53609 --- /dev/null +++ b/ansible/roles/vagrant_local/tasks/main.yml @@ -0,0 +1,11 @@ +--- +- name: Set the hostname in /etc/hostname + shell: echo {{ vagrant_local.vm.hostname }} > /etc/hostname + when: vagrant_local.vm.hostname is defined + +- name: Set the hostname + shell: hostname {{ vagrant_local.vm.hostname }} + when: vagrant_local.vm.hostname is defined + +- name: Update /etc/hosts + lineinfile: dest=/etc/hosts regexp='^127\.0\.0\.1' line='127.0.0.1 localhost {{ vagrant_local.vm.hostname }}' owner=root group=root mode=0644 diff --git a/ansible/roles/xdebug/defaults/main.yml b/ansible/roles/xdebug/defaults/main.yml new file mode 100755 index 0000000..f2d917e --- /dev/null +++ b/ansible/roles/xdebug/defaults/main.yml @@ -0,0 +1,7 @@ +--- +xdebug: + settings: + - xdebug.remote_enable=1 + - xdebug.idekey=PHPSTORM + - xdebug.remote_connect_back=1 + - xdebug.remote_port=9000 diff --git a/ansible/roles/xdebug/tasks/main.yml b/ansible/roles/xdebug/tasks/main.yml new file mode 100755 index 0000000..e38815d --- /dev/null +++ b/ansible/roles/xdebug/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: Install xDebug + sudo: yes + apt: pkg=php5-xdebug state=latest diff --git a/ansible/vars/all.yml b/ansible/vars/all.yml new file mode 100755 index 0000000..b5559e6 --- /dev/null +++ b/ansible/vars/all.yml @@ -0,0 +1,15 @@ +--- +server: + install: '1' + packages: [vim, htop, iotop, bwm-ng] + timezone: UTC + locale: en_US.UTF-8 +vagrant_local: + install: '1' + vm: { base_box: trusty64, hostname: design-patterns, ip: 192.168.11.2, sharedfolder: ./, enableWindows: '1', useVagrantCloud: '1', syncType: nfs } +php: + install: '1' + ppa: php5-5.6 + packages: [php5-cli, php5-intl, php5-mcrypt, php5-mysql, php5-curl, php5-json] +xdebug: + install: '1' diff --git a/ansible/windows.sh b/ansible/windows.sh new file mode 100755 index 0000000..eab5d9a --- /dev/null +++ b/ansible/windows.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Update Repositories +sudo apt-get update + +# Determine Ubuntu Version +. /etc/lsb-release + +# Decide on package to install for `add-apt-repository` command +# +# USE_COMMON=1 when using a distribution over 12.04 +# USE_COMMON=0 when using a distribution at 12.04 or older +USE_COMMON=$(echo "$DISTRIB_RELEASE > 12.04" | bc) + +if [ "$USE_COMMON" -eq "1" ]; +then + sudo apt-get install -y software-properties-common +else + sudo apt-get install -y python-software-properties +fi + +# Add Ansible Repository & Install Ansible +sudo add-apt-repository -y ppa:ansible/ansible +sudo apt-get update +sudo apt-get install -y ansible + +# Setup Ansible for Local Use and Run +cp /vagrant/ansible/inventories/dev /etc/ansible/hosts -f +chmod 666 /etc/ansible/hosts +cat /vagrant/ansible/files/authorized_keys >> /home/vagrant/.ssh/authorized_keys +sudo ansible-playbook /vagrant/ansible/playbook.yml -e hostname=$1 --connection=local \ No newline at end of file diff --git a/composer.json b/composer.json index a754501..71610e4 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ ], "minimum-stability": "stable", "require-dev": { - "phpunit/phpunit": "4.6.*", + "phpunit/phpunit": "^4.6", "squizlabs/php_codesniffer": "1.5.*" }, "autoload": { diff --git a/composer.lock b/composer.lock index 3d44d0c..202b73e 100644 --- a/composer.lock +++ b/composer.lock @@ -1,55 +1,219 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" - ], - "hash": "5fb4edd1df6d1229395f973b68675bfe", - "packages": [ - + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" ], + "hash": "ccc9bc820717ca4dc310248ad4a69f21", + "content-hash": "f9ca7d34db86fa55e8dc649f84d8b4c7", + "packages": [], "packages-dev": [ { - "name": "phpunit/php-code-coverage", - "version": "1.2.13", + "name": "doctrine/instantiator", + "version": "1.0.5", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "466e7cd2554b4e264c9e3f31216d25ac0e5f3d94" + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/466e7cd2554b4e264c9e3f31216d25ac0e5f3d94", - "reference": "466e7cd2554b4e264c9e3f31216d25ac0e5f3d94", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", "shasum": "" }, "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": ">=1.3.0@stable", - "phpunit/php-text-template": ">=1.1.1@stable", - "phpunit/php-token-stream": ">=1.1.3@stable" + "php": ">=5.3,<8.0-DEV" }, "require-dev": { - "phpunit/phpunit": "3.7.*@dev" - }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.0.5" + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14 21:17:01" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "phpDocumentor": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" + } + ], + "time": "2015-02-03 12:10:50" + }, + { + "name": "phpspec/prophecy", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7", + "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-08-13 10:07:40" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "^1.3.2", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2.x-dev" } }, "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -67,35 +231,37 @@ "testing", "xunit" ], - "time": "2013-09-10 08:14:32" + "time": "2015-10-06 15:47:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.3.4", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", "shasum": "" }, "require": { "php": ">=5.3.3" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, "autoload": { "classmap": [ - "File/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -112,20 +278,20 @@ "filesystem", "iterator" ], - "time": "2013-10-10 15:34:57" + "time": "2015-06-21 13:08:43" }, { "name": "phpunit/php-text-template", - "version": "1.1.4", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "5180896f51c5b3648ac946b05f9ec02be78a0b23" + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5180896f51c5b3648ac946b05f9ec02be78a0b23", - "reference": "5180896f51c5b3648ac946b05f9ec02be78a0b23", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", "shasum": "" }, "require": { @@ -134,20 +300,17 @@ "type": "library", "autoload": { "classmap": [ - "Text/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -156,20 +319,20 @@ "keywords": [ "template" ], - "time": "2012-10-31 18:15:28" + "time": "2015-06-21 13:50:34" }, { "name": "phpunit/php-timer", - "version": "1.0.5", + "version": "1.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", "shasum": "" }, "require": { @@ -178,13 +341,10 @@ "type": "library", "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -200,49 +360,48 @@ "keywords": [ "timer" ], - "time": "2013-08-02 07:42:54" + "time": "2015-06-21 08:01:12" }, { "name": "phpunit/php-token-stream", - "version": "1.2.1", + "version": "1.4.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e" + "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/5220af2a7929aa35cf663d97c89ad3d50cf5fa3e", - "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", + "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", "shasum": "" }, "require": { "ext-tokenizer": "*", "php": ">=5.3.3" }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "1.4-dev" } }, "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" + "email": "sebastian@phpunit.de" } ], "description": "Wrapper around PHP's tokenizer extension.", @@ -250,63 +409,61 @@ "keywords": [ "tokenizer" ], - "time": "2013-09-13 04:58:23" + "time": "2015-09-15 10:49:45" }, { "name": "phpunit/phpunit", - "version": "3.7.28", + "version": "4.8.18", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d" + "reference": "fa33d4ad96481b91df343d83e8c8aabed6b1dfd3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d", - "reference": "3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fa33d4ad96481b91df343d83e8c8aabed6b1dfd3", + "reference": "fa33d4ad96481b91df343d83e8c8aabed6b1dfd3", "shasum": "" }, "require": { "ext-dom": "*", + "ext-json": "*", "ext-pcre": "*", "ext-reflection": "*", "ext-spl": "*", "php": ">=5.3.3", - "phpunit/php-code-coverage": "~1.2.1", - "phpunit/php-file-iterator": ">=1.3.1", - "phpunit/php-text-template": ">=1.1.1", - "phpunit/php-timer": ">=1.0.4", - "phpunit/phpunit-mock-objects": "~1.2.0", - "symfony/yaml": "~2.0" - }, - "require-dev": { - "pear-pear/pear": "1.9.4" + "phpspec/prophecy": "^1.3.1", + "phpunit/php-code-coverage": "~2.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": ">=1.0.6", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.3", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" }, "suggest": { - "ext-json": "*", - "ext-simplexml": "*", - "ext-tokenizer": "*", - "phpunit/php-invoker": ">=1.1.0,<1.2.0" + "phpunit/php-invoker": "~1.1" }, "bin": [ - "composer/bin/phpunit" + "phpunit" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "3.7.x-dev" + "dev-master": "4.8.x-dev" } }, "autoload": { "classmap": [ - "PHPUnit/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "", - "../../symfony/yaml/" - ], "license": [ "BSD-3-Clause" ], @@ -318,45 +475,52 @@ } ], "description": "The PHP Unit Testing framework.", - "homepage": "http://www.phpunit.de/", + "homepage": "https://phpunit.de/", "keywords": [ "phpunit", "testing", "xunit" ], - "time": "2013-10-17 07:27:40" + "time": "2015-11-11 11:32:49" }, { "name": "phpunit/phpunit-mock-objects", - "version": "1.2.3", + "version": "2.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875" + "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5794e3c5c5ba0fb037b11d8151add2a07fa82875", - "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", + "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", "shasum": "" }, "require": { + "doctrine/instantiator": "^1.0.2", "php": ">=5.3.3", - "phpunit/php-text-template": ">=1.1.1@stable" + "phpunit/php-text-template": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" }, "suggest": { "ext-soap": "*" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, "autoload": { "classmap": [ - "PHPUnit/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -373,20 +537,391 @@ "mock", "xunit" ], - "time": "2013-01-13 10:24:48" + "time": "2015-10-02 06:51:40" }, { - "name": "squizlabs/php_codesniffer", - "version": "1.5.1", + "name": "sebastian/comparator", + "version": "1.2.0", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "bd1e50b8c252c914881dba1dcef089219e430dbd" + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/bd1e50b8c252c914881dba1dcef089219e430dbd", - "reference": "bd1e50b8c252c914881dba1dcef089219e430dbd", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", + "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-07-26 15:48:44" + }, + { + "name": "sebastian/diff", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "1.3.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6324c907ce7a52478eeeaede764f48733ef5ae44", + "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-08-03 06:14:51" + }, + { + "name": "sebastian/exporter", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "7ae5513327cb536431847bcc0c10edba2701064e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", + "reference": "7ae5513327cb536431847bcc0c10edba2701064e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-06-21 07:55:53" + }, + { + "name": "sebastian/global-state", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2015-10-12 03:26:01" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-06-21 08:04:50" + }, + { + "name": "sebastian/version", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-06-21 13:59:46" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "1.5.6", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "6f3e42d311b882b25b4d409d23a289f4d3b803d5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6f3e42d311b882b25b4d409d23a289f4d3b803d5", + "reference": "6f3e42d311b882b25b4d409d23a289f4d3b803d5", "shasum": "" }, "require": { @@ -400,6 +935,11 @@ "scripts/phpcs" ], "type": "library", + "extra": { + "branch-alias": { + "dev-phpcs-fixer": "2.0.x-dev" + } + }, "autoload": { "classmap": [ "CodeSniffer.php", @@ -443,34 +983,33 @@ "phpcs", "standards" ], - "time": "2013-12-12 03:08:49" + "time": "2014-12-04 22:32:15" }, { "name": "symfony/yaml", - "version": "v2.4.1", - "target-dir": "Symfony/Component/Yaml", + "version": "v2.7.6", "source": { "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "4e1a237fc48145fae114b96458d799746ad89aa0" + "url": "https://github.com/symfony/yaml.git", + "reference": "eca9019c88fbe250164affd107bc8057771f3f4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/4e1a237fc48145fae114b96458d799746ad89aa0", - "reference": "4e1a237fc48145fae114b96458d799746ad89aa0", + "url": "https://api.github.com/repos/symfony/yaml/zipball/eca9019c88fbe250164affd107bc8057771f3f4d", + "reference": "eca9019c88fbe250164affd107bc8057771f3f4d", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "2.7-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\Yaml\\": "" } }, @@ -485,25 +1024,19 @@ }, { "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2013-12-28 08:12:03" + "homepage": "https://symfony.com", + "time": "2015-10-11 09:39:48" } ], - "aliases": [ - - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": [ - - ], - "platform": [ - - ], - "platform-dev": [ - - ] + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] } diff --git a/locale/ca/LC_MESSAGES/Creational/SimpleFactory/README.po b/locale/ca/LC_MESSAGES/Creational/SimpleFactory/README.po index d011ad6..74e85d4 100644 --- a/locale/ca/LC_MESSAGES/Creational/SimpleFactory/README.po +++ b/locale/ca/LC_MESSAGES/Creational/SimpleFactory/README.po @@ -20,7 +20,7 @@ msgid "Purpose" msgstr "" #: ../../Creational/SimpleFactory/README.rst:7 -msgid "ConcreteFactory is a simple factory pattern." +msgid "SimpleFactory is a simple factory pattern." msgstr "" #: ../../Creational/SimpleFactory/README.rst:9 @@ -48,7 +48,7 @@ msgid "You can also find these code on `GitHub`_" msgstr "" #: ../../Creational/SimpleFactory/README.rst:27 -msgid "ConcreteFactory.php" +msgid "SimpleFactory.php" msgstr "" #: ../../Creational/SimpleFactory/README.rst:33 diff --git a/locale/es/LC_MESSAGES/Creational/AbstractFactory/README.po b/locale/es/LC_MESSAGES/Creational/AbstractFactory/README.po index 04a383e..8c9340b 100644 --- a/locale/es/LC_MESSAGES/Creational/AbstractFactory/README.po +++ b/locale/es/LC_MESSAGES/Creational/AbstractFactory/README.po @@ -1,23 +1,24 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Language: es\n" +"Last-Translator: Daniel González \n" +"Language-Team: \n" +"X-Generator: Poedit 1.5.4\n" #: ../../Creational/AbstractFactory/README.rst:2 msgid "`Abstract Factory`__" -msgstr "" +msgstr "`Factoria Abstracta`__" #: ../../Creational/AbstractFactory/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "Proposito" #: ../../Creational/AbstractFactory/README.rst:7 msgid "" @@ -26,63 +27,68 @@ msgid "" "interface. The client of the abstract factory does not care about how these " "objects are created, he just knows how they go together." msgstr "" +"Para crear una serie de objetos relacionados o dependientes sin especificar " +"a que clase concreta pertenecen. Normalmente las clases creadas implementan " +"las mismas interfaces. El cliente de la factoría abstracta no necesita " +"preocupase por como estos objetos son creados, el solo sabe que tiene que " +"hacer con ellos." #: ../../Creational/AbstractFactory/README.rst:13 msgid "UML Diagram" -msgstr "" +msgstr "Diagrama UML" #: ../../Creational/AbstractFactory/README.rst:20 msgid "Code" -msgstr "" +msgstr "Código" #: ../../Creational/AbstractFactory/README.rst:22 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Puedes encontrar el código en `GitHub`_" #: ../../Creational/AbstractFactory/README.rst:24 msgid "AbstractFactory.php" -msgstr "" +msgstr "AbstractFactory.php" #: ../../Creational/AbstractFactory/README.rst:30 msgid "JsonFactory.php" -msgstr "" +msgstr "JsonFactory.php" #: ../../Creational/AbstractFactory/README.rst:36 msgid "HtmlFactory.php" -msgstr "" +msgstr "HtmlFactory.php" #: ../../Creational/AbstractFactory/README.rst:42 msgid "MediaInterface.php" -msgstr "" +msgstr "MediaInterface.php" #: ../../Creational/AbstractFactory/README.rst:48 msgid "Picture.php" -msgstr "" +msgstr "Picture.php" #: ../../Creational/AbstractFactory/README.rst:54 msgid "Text.php" -msgstr "" +msgstr "Text.php" #: ../../Creational/AbstractFactory/README.rst:60 msgid "Json/Picture.php" -msgstr "" +msgstr "Json/Picture.php" #: ../../Creational/AbstractFactory/README.rst:66 msgid "Json/Text.php" -msgstr "" +msgstr "Json/Text.php" #: ../../Creational/AbstractFactory/README.rst:72 msgid "Html/Picture.php" -msgstr "" +msgstr "Html/Picture.php" #: ../../Creational/AbstractFactory/README.rst:78 msgid "Html/Text.php" -msgstr "" +msgstr "Html/Text.php" #: ../../Creational/AbstractFactory/README.rst:85 msgid "Test" -msgstr "" +msgstr "Test" #: ../../Creational/AbstractFactory/README.rst:87 msgid "Tests/AbstractFactoryTest.php" -msgstr "" +msgstr "Tests/AbstractFactoryTest.php" diff --git a/locale/es/LC_MESSAGES/Creational/Builder/README.po b/locale/es/LC_MESSAGES/Creational/Builder/README.po index 79d4fe3..0cbdd58 100644 --- a/locale/es/LC_MESSAGES/Creational/Builder/README.po +++ b/locale/es/LC_MESSAGES/Creational/Builder/README.po @@ -1,110 +1,121 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-09-11 11:42+0100\n" +"Last-Translator: Daniel González \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Language: es\n" +"Language-Team: \n" +"X-Generator: Poedit 1.5.4\n" #: ../../Creational/Builder/README.rst:2 msgid "`Builder`__" -msgstr "" +msgstr "`Constructor`__" #: ../../Creational/Builder/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "Propósito" #: ../../Creational/Builder/README.rst:7 msgid "Builder is an interface that build parts of a complex object." msgstr "" +"El constructor es una interfaz que construye parte de un objeto complejo." #: ../../Creational/Builder/README.rst:9 msgid "" "Sometimes, if the builder has a better knowledge of what it builds, this " "interface could be an abstract class with default methods (aka adapter)." msgstr "" +"A veces, si el constructor conoce bien lo que está construyendo, esta " +"interfaz podría ser una clase abstracta con métodos por defecto ( también " +"conocido como Adaptador )" #: ../../Creational/Builder/README.rst:12 msgid "" "If you have a complex inheritance tree for objects, it is logical to have a " "complex inheritance tree for builders too." msgstr "" +"Si tienes una herencia compleja de tu árbol de objetos, es lógico tener " +"también una herencia compleja en el árbol de constructores." #: ../../Creational/Builder/README.rst:15 msgid "" "Note: Builders have often a fluent interface, see the mock builder of " "PHPUnit for example." msgstr "" +"Nota: Los constructores suelen tener una interfaz fluida, fíjate en el mock " +"builder de PHPUnit por ejemplo." #: ../../Creational/Builder/README.rst:19 msgid "Examples" -msgstr "" +msgstr "Ejemplos" #: ../../Creational/Builder/README.rst:21 msgid "PHPUnit: Mock Builder" -msgstr "" +msgstr "PHPUnit: Mock Builder" #: ../../Creational/Builder/README.rst:24 msgid "UML Diagram" -msgstr "" +msgstr "Diagrama UML" #: ../../Creational/Builder/README.rst:31 msgid "Code" -msgstr "" +msgstr "Código" #: ../../Creational/Builder/README.rst:33 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Puedes encontrar el código en `GitHub`_" #: ../../Creational/Builder/README.rst:35 msgid "Director.php" -msgstr "" +msgstr "Director.php" #: ../../Creational/Builder/README.rst:41 msgid "BuilderInterface.php" -msgstr "" +msgstr "BuilderInterface.php" #: ../../Creational/Builder/README.rst:47 msgid "BikeBuilder.php" -msgstr "" +msgstr "BikeBuilder.php" #: ../../Creational/Builder/README.rst:53 msgid "CarBuilder.php" -msgstr "" +msgstr "CarBuilder.php" #: ../../Creational/Builder/README.rst:59 msgid "Parts/Vehicle.php" -msgstr "" +msgstr "Parts/Vehicle.php" #: ../../Creational/Builder/README.rst:65 msgid "Parts/Bike.php" -msgstr "" +msgstr "Parts/Bike.php" #: ../../Creational/Builder/README.rst:71 msgid "Parts/Car.php" -msgstr "" +msgstr "Parts/Car.php" #: ../../Creational/Builder/README.rst:77 msgid "Parts/Engine.php" -msgstr "" +msgstr "Parts/Engine.php" #: ../../Creational/Builder/README.rst:83 msgid "Parts/Wheel.php" -msgstr "" +msgstr "Parts/Wheel.php" #: ../../Creational/Builder/README.rst:89 msgid "Parts/Door.php" -msgstr "" +msgstr "Parts/Door.php" #: ../../Creational/Builder/README.rst:96 msgid "Test" -msgstr "" +msgstr "Test" #: ../../Creational/Builder/README.rst:98 msgid "Tests/DirectorTest.php" -msgstr "" +msgstr "Tests/DirectorTest.php" diff --git a/locale/es/LC_MESSAGES/Creational/FactoryMethod/README.po b/locale/es/LC_MESSAGES/Creational/FactoryMethod/README.po index b65c56b..550573a 100644 --- a/locale/es/LC_MESSAGES/Creational/FactoryMethod/README.po +++ b/locale/es/LC_MESSAGES/Creational/FactoryMethod/README.po @@ -1,29 +1,33 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-09-15 17:15+0100\n" +"Last-Translator: Daniel González \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Language: es\n" +"Language-Team: \n" +"X-Generator: Poedit 1.5.4\n" #: ../../Creational/FactoryMethod/README.rst:2 msgid "`Factory Method`__" -msgstr "" +msgstr "`Factory Method`__" #: ../../Creational/FactoryMethod/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "Proposito" #: ../../Creational/FactoryMethod/README.rst:7 msgid "" "The good point over the SimpleFactory is you can subclass it to implement " "different ways to create objects" msgstr "" +"La principal ventaja de SimpleFactory es que puedes extender la clase para " +"implementar diferentes formas" #: ../../Creational/FactoryMethod/README.rst:10 msgid "For simple case, this abstract class could be just an interface" @@ -40,51 +44,54 @@ msgid "" "It means the FactoryMethod class depends on abstractions, not concrete " "classes. This is the real trick compared to SimpleFactory or StaticFactory." msgstr "" +"Esto significa que la clase FactoryMethod depende de abstraciones, no de " +"clases concretas. Esto es el truco con respecto a SimpleFactory o " +"StaticFactory" #: ../../Creational/FactoryMethod/README.rst:20 msgid "UML Diagram" -msgstr "" +msgstr "Diagrama UML" #: ../../Creational/FactoryMethod/README.rst:27 msgid "Code" -msgstr "" +msgstr "Código" #: ../../Creational/FactoryMethod/README.rst:29 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Puedes encontrar el código en `GitHub`_" #: ../../Creational/FactoryMethod/README.rst:31 msgid "FactoryMethod.php" -msgstr "" +msgstr "FactoryMethod.php" #: ../../Creational/FactoryMethod/README.rst:37 msgid "ItalianFactory.php" -msgstr "" +msgstr "ItalianFactory.php" #: ../../Creational/FactoryMethod/README.rst:43 msgid "GermanFactory.php" -msgstr "" +msgstr "GermanFactory.php" #: ../../Creational/FactoryMethod/README.rst:49 msgid "VehicleInterface.php" -msgstr "" +msgstr "VehicleInterface.php" #: ../../Creational/FactoryMethod/README.rst:55 msgid "Porsche.php" -msgstr "" +msgstr "Porsche.php" #: ../../Creational/FactoryMethod/README.rst:61 msgid "Bicycle.php" -msgstr "" +msgstr "Bicycle.php" #: ../../Creational/FactoryMethod/README.rst:67 msgid "Ferrari.php" -msgstr "" +msgstr "Ferrari.php" #: ../../Creational/FactoryMethod/README.rst:74 msgid "Test" -msgstr "" +msgstr "Test" #: ../../Creational/FactoryMethod/README.rst:76 msgid "Tests/FactoryMethodTest.php" -msgstr "" +msgstr "Tests/FactoryMethodTest.php" diff --git a/locale/es/LC_MESSAGES/Creational/Multiton/README.po b/locale/es/LC_MESSAGES/Creational/Multiton/README.po index 702271d..c32fbaa 100644 --- a/locale/es/LC_MESSAGES/Creational/Multiton/README.po +++ b/locale/es/LC_MESSAGES/Creational/Multiton/README.po @@ -1,64 +1,71 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-09-11 11:31+0100\n" +"Last-Translator: Daniel González \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Language: es\n" +"Language-Team: \n" +"X-Generator: Poedit 1.5.4\n" #: ../../Creational/Multiton/README.rst:2 msgid "Multiton" -msgstr "" +msgstr "Multiton" #: ../../Creational/Multiton/README.rst:4 msgid "" "**THIS IS CONSIDERED TO BE AN ANTI-PATTERN! FOR BETTER TESTABILITY AND " "MAINTAINABILITY USE DEPENDENCY INJECTION!**" msgstr "" +"**ESTO ES CONSIDERADO UN ANTI-PATRÓN. PARA MEJOR TESTEABILIDAD Y " +"MANTENIBILIDAD USA INYECCIÓN DE DEPENDENCIAS**" #: ../../Creational/Multiton/README.rst:8 msgid "Purpose" -msgstr "" +msgstr "Propósito" #: ../../Creational/Multiton/README.rst:10 msgid "" "To have only a list of named instances that are used, like a singleton but " "with n instances." msgstr "" +"Tener una única lista de los nombres de las instancias que has usando, como " +"en el singleton pero con varias instancias." #: ../../Creational/Multiton/README.rst:14 msgid "Examples" -msgstr "" +msgstr "Ejemplos" #: ../../Creational/Multiton/README.rst:16 msgid "2 DB Connectors, e.g. one for MySQL, the other for SQLite" -msgstr "" +msgstr "2 Conectores de base de datos, Ej. uno para MySQL el otro para SQLite." #: ../../Creational/Multiton/README.rst:17 msgid "multiple Loggers (one for debug messages, one for errors)" msgstr "" +"Múltiples sistemas de log ( no para mensajes de debug, uno para errores )." #: ../../Creational/Multiton/README.rst:20 msgid "UML Diagram" -msgstr "" +msgstr "Diagrama UML" #: ../../Creational/Multiton/README.rst:27 msgid "Code" -msgstr "" +msgstr "Código" #: ../../Creational/Multiton/README.rst:29 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Puedes encontrar el código en `GitHub`_" #: ../../Creational/Multiton/README.rst:31 msgid "Multiton.php" -msgstr "" +msgstr "Multiton.php" #: ../../Creational/Multiton/README.rst:38 msgid "Test" -msgstr "" +msgstr "Test" diff --git a/locale/es/LC_MESSAGES/Creational/Pool/README.po b/locale/es/LC_MESSAGES/Creational/Pool/README.po index 8defedd..99fbef8 100644 --- a/locale/es/LC_MESSAGES/Creational/Pool/README.po +++ b/locale/es/LC_MESSAGES/Creational/Pool/README.po @@ -1,19 +1,21 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" +"PO-Revision-Date: 2015-09-10 10:03+0100\n" +"Last-Translator: Daniel González \n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"MIME-Version: 1.0\n" +"Language: es\n" +"Language-Team: \n" +"X-Generator: Poedit 1.5.4\n" #: ../../Creational/Pool/README.rst:2 msgid "`Pool`__" -msgstr "" +msgstr "`Pila`__" #: ../../Creational/Pool/README.rst:4 msgid "" @@ -24,16 +26,27 @@ msgid "" "object. When the client has finished, it returns the object, which is a " "specific type of factory object, to the pool rather than destroying it." msgstr "" +"El **Patrón Pila** es un patrón de diseño creacional que utiliza un conjunto " +"de objetos inicializados y los mantiene listos para usar el la \"pila\" en " +"lugar de crearlos y destruirlos bajo demanda. Un cliente puede pedirle a la " +"pila un objeto, realizar las operaciones necesarias sobre el. Cuando el " +"cliente ha terminado devuelve el objeto a la pila en lugar de destruirlo." #: ../../Creational/Pool/README.rst:11 msgid "" -"Object pooling can offer a significant performance boost in situations where" -" the cost of initializing a class instance is high, the rate of " -"instantiation of a class is high, and the number of instances in use at any " -"one time is low. The pooled object is obtained in predictable time when " -"creation of the new objects (especially over network) may take variable " -"time." +"Object pooling can offer a significant performance boost in situations where " +"the cost of initializing a class instance is high, the rate of instantiation " +"of a class is high, and the number of instances in use at any one time is " +"low. The pooled object is obtained in predictable time when creation of the " +"new objects (especially over network) may take variable time." msgstr "" +"Mantener los objetos en una pila puede ofrecer mejoras significativas de " +"rendimiento en aquellas situaciones donde el coste de inicializar las " +"instancias es alto, el volumen de veces que se instancia la clase es alto y " +"el número de instancias que se mantienen en uso a la vez es bajo. El objeto " +"puede recuperase de la pila en una cantidad de tiempo predecible, cuando la " +"creación de nuevos objetos ( especialmente cuando se realiza a través de una " +"red ) puede variar." #: ../../Creational/Pool/README.rst:18 msgid "" @@ -42,19 +55,19 @@ msgid "" "and large graphic objects like fonts or bitmaps. In certain situations, " "simple object pooling (that hold no external resources, but only occupy " "memory) may not be efficient and could decrease performance." -msgstr "" +msgstr "Sin embargo estos beneficios " #: ../../Creational/Pool/README.rst:25 msgid "UML Diagram" -msgstr "" +msgstr "Diagrama UML" #: ../../Creational/Pool/README.rst:32 msgid "Code" -msgstr "" +msgstr "Código" #: ../../Creational/Pool/README.rst:34 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Puedes encontrar el código en `GitHub`_" #: ../../Creational/Pool/README.rst:36 msgid "Pool.php" diff --git a/locale/es/LC_MESSAGES/Creational/Prototype/README.po b/locale/es/LC_MESSAGES/Creational/Prototype/README.po index fac09ef..dfd8b5e 100644 --- a/locale/es/LC_MESSAGES/Creational/Prototype/README.po +++ b/locale/es/LC_MESSAGES/Creational/Prototype/README.po @@ -1,68 +1,74 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-09-09 16:26+0100\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Language: es\n" +"Last-Translator: Daniel González \n" +"Language-Team: \n" +"X-Generator: Poedit 1.5.4\n" #: ../../Creational/Prototype/README.rst:2 msgid "`Prototype`__" -msgstr "" +msgstr "`Prototype`__" #: ../../Creational/Prototype/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "Proposito" #: ../../Creational/Prototype/README.rst:7 msgid "" "To avoid the cost of creating objects the standard way (new Foo()) and " "instead create a prototype and clone it." msgstr "" +"Evitar el cote de crear objetos de la forma estandar (new Foo()). En su " +"lugar crear una instancia y clonarla." #: ../../Creational/Prototype/README.rst:11 msgid "Examples" -msgstr "" +msgstr "Ejemplos" #: ../../Creational/Prototype/README.rst:13 msgid "" "Large amounts of data (e.g. create 1,000,000 rows in a database at once via " "a ORM)." msgstr "" +"Grandes cantidades de datos ( ej. crear 1.000.000 de registros en la base de " +"datos a través del ORM )." #: ../../Creational/Prototype/README.rst:17 msgid "UML Diagram" -msgstr "" +msgstr "Diagrama UML" #: ../../Creational/Prototype/README.rst:24 msgid "Code" -msgstr "" +msgstr "Código" #: ../../Creational/Prototype/README.rst:26 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Puedes encontrar el código en `GitHub`_" #: ../../Creational/Prototype/README.rst:28 msgid "index.php" -msgstr "" +msgstr "index.php" #: ../../Creational/Prototype/README.rst:34 msgid "BookPrototype.php" -msgstr "" +msgstr "BookPrototype.php" #: ../../Creational/Prototype/README.rst:40 msgid "BarBookPrototype.php" -msgstr "" +msgstr "BarBookPrototype.php" #: ../../Creational/Prototype/README.rst:46 msgid "FooBookPrototype.php" -msgstr "" +msgstr "FooBookPrototype.php" #: ../../Creational/Prototype/README.rst:53 msgid "Test" -msgstr "" +msgstr "Test" diff --git a/locale/es/LC_MESSAGES/Creational/README.po b/locale/es/LC_MESSAGES/Creational/README.po index 72f543b..7a5db3c 100644 --- a/locale/es/LC_MESSAGES/Creational/README.po +++ b/locale/es/LC_MESSAGES/Creational/README.po @@ -1,25 +1,32 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-09-08 17:17+0100\n" +"Last-Translator: Daniel González \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" +"Language: es\n" #: ../../Creational/README.rst:2 msgid "`Creational`__" -msgstr "" +msgstr "`Creacionales`__" #: ../../Creational/README.rst:4 msgid "" -"In software engineering, creational design patterns are design patterns that" -" deal with object creation mechanisms, trying to create objects in a manner " -"suitable to the situation. The basic form of object creation could result in" -" design problems or added complexity to the design. Creational design " +"In software engineering, creational design patterns are design patterns that " +"deal with object creation mechanisms, trying to create objects in a manner " +"suitable to the situation. The basic form of object creation could result in " +"design problems or added complexity to the design. Creational design " "patterns solve this problem by somehow controlling this object creation." msgstr "" +"En ingeniería del software, los patrones de diseño creacionales son patrones " +"que se encargan del los mecanismos de creación de los objetos, intentando " +"crear objetos de una manera adecuada a cada situación. La forma básica de " +"creación de objetos podría generar un problemas de diseño o añadir " +"complejidad al diseño. Los patrones de diseño creacionales resuelven este " +"problema controlando de alguna forma la creación de objetos." diff --git a/locale/es/LC_MESSAGES/Creational/SimpleFactory/README.po b/locale/es/LC_MESSAGES/Creational/SimpleFactory/README.po index d011ad6..0b517cd 100644 --- a/locale/es/LC_MESSAGES/Creational/SimpleFactory/README.po +++ b/locale/es/LC_MESSAGES/Creational/SimpleFactory/README.po @@ -6,10 +6,10 @@ msgstr "" "POT-Creation-Date: 2015-05-29 12:18+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Language: es\n" #: ../../Creational/SimpleFactory/README.rst:2 msgid "Simple Factory" @@ -20,7 +20,7 @@ msgid "Purpose" msgstr "" #: ../../Creational/SimpleFactory/README.rst:7 -msgid "ConcreteFactory is a simple factory pattern." +msgid "SimpleFactory is a simple factory pattern." msgstr "" #: ../../Creational/SimpleFactory/README.rst:9 @@ -48,7 +48,7 @@ msgid "You can also find these code on `GitHub`_" msgstr "" #: ../../Creational/SimpleFactory/README.rst:27 -msgid "ConcreteFactory.php" +msgid "SimpleFactory.php" msgstr "" #: ../../Creational/SimpleFactory/README.rst:33 diff --git a/locale/es/LC_MESSAGES/Creational/Singleton/README.po b/locale/es/LC_MESSAGES/Creational/Singleton/README.po index 5d108ca..0bb78f3 100644 --- a/locale/es/LC_MESSAGES/Creational/Singleton/README.po +++ b/locale/es/LC_MESSAGES/Creational/Singleton/README.po @@ -1,75 +1,84 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-09-08 17:34+0100\n" +"Last-Translator: Daniel González \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" +"Language: es\n" +"Language-Team: \n" #: ../../Creational/Singleton/README.rst:2 msgid "`Singleton`__" -msgstr "" +msgstr "`Singleton`__" #: ../../Creational/Singleton/README.rst:4 msgid "" "**THIS IS CONSIDERED TO BE AN ANTI-PATTERN! FOR BETTER TESTABILITY AND " "MAINTAINABILITY USE DEPENDENCY INJECTION!**" msgstr "" +"**ESTO ES CONSIDERADO UN ANTI-PATRÓN. PARA MEJOR TESTEABILIDAD Y " +"MANTENIBILIDAD USA INYECCIÓN DE DEPENDENCIAS**" #: ../../Creational/Singleton/README.rst:8 msgid "Purpose" -msgstr "" +msgstr "Proposito" #: ../../Creational/Singleton/README.rst:10 msgid "" -"To have only one instance of this object in the application that will handle" -" all calls." +"To have only one instance of this object in the application that will handle " +"all calls." msgstr "" +"Tener una única instancia de este objeto en la aplicación que pueda " +"encargarse de todas las llamadas." #: ../../Creational/Singleton/README.rst:14 msgid "Examples" -msgstr "" +msgstr "Ejemplos" #: ../../Creational/Singleton/README.rst:16 msgid "DB Connector" -msgstr "" +msgstr "Conexión a la base de datos" #: ../../Creational/Singleton/README.rst:17 msgid "" "Logger (may also be a Multiton if there are many log files for several " "purposes)" msgstr "" +"Logger ( también podría ser un Multiton si hay varios ficheros de log para " +"diferentes propósitos )" #: ../../Creational/Singleton/README.rst:19 -msgid "" -"Lock file for the application (there is only one in the filesystem ...)" +msgid "Lock file for the application (there is only one in the filesystem ...)" msgstr "" +"Bloqueo de ficheros para la aplicación ( Solo hay uno en el sistema de " +"ficheros )" #: ../../Creational/Singleton/README.rst:23 msgid "UML Diagram" -msgstr "" +msgstr "Diagrama UML" #: ../../Creational/Singleton/README.rst:30 msgid "Code" -msgstr "" +msgstr "Código" #: ../../Creational/Singleton/README.rst:32 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Puedes ver este código en `GitHub`_" #: ../../Creational/Singleton/README.rst:34 msgid "Singleton.php" -msgstr "" +msgstr "Singleton.php" #: ../../Creational/Singleton/README.rst:41 msgid "Test" -msgstr "" +msgstr "Test" #: ../../Creational/Singleton/README.rst:43 msgid "Tests/SingletonTest.php" -msgstr "" +msgstr "Tests/SingletonTest.php" diff --git a/locale/es/LC_MESSAGES/Creational/StaticFactory/README.po b/locale/es/LC_MESSAGES/Creational/StaticFactory/README.po index 4a6f64e..7005abb 100644 --- a/locale/es/LC_MESSAGES/Creational/StaticFactory/README.po +++ b/locale/es/LC_MESSAGES/Creational/StaticFactory/README.po @@ -1,23 +1,25 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-09-08 17:47+0100\n" +"Last-Translator: Daniel González \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Language: es\n" +"Language-Team: \n" +"X-Generator: Poedit 1.5.4\n" #: ../../Creational/StaticFactory/README.rst:2 msgid "Static Factory" -msgstr "" +msgstr "Static Factory" #: ../../Creational/StaticFactory/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "Proposito" #: ../../Creational/StaticFactory/README.rst:7 msgid "" @@ -27,49 +29,56 @@ msgid "" "method to create all types of objects it can create. It is usually named " "``factory`` or ``build``." msgstr "" +"Parecido a AbstractFactory, este patrón es usado para crear conjuntos de " +"objetos relacionados o dependientes. La diferencia entre este y la factoría " +"abstracta es que el patrón factoría estática usa un sólo método estático " +"para crear todos los tipos de objetos que puede crear. Este método " +"normalmente se llama ``factory`` or ``build``." #: ../../Creational/StaticFactory/README.rst:14 msgid "Examples" -msgstr "" +msgstr "Ejemplos" #: ../../Creational/StaticFactory/README.rst:16 msgid "" -"Zend Framework: ``Zend_Cache_Backend`` or ``_Frontend`` use a factory method" -" create cache backends or frontends" +"Zend Framework: ``Zend_Cache_Backend`` or ``_Frontend`` use a factory method " +"create cache backends or frontends" msgstr "" +"Zend Framework: ``Zend_Cache_Backend`` or ``_Frontend`` usa un método " +"factoría para crear la cache de las aplicaciones." #: ../../Creational/StaticFactory/README.rst:20 msgid "UML Diagram" -msgstr "" +msgstr "Diagrama UML" #: ../../Creational/StaticFactory/README.rst:27 msgid "Code" -msgstr "" +msgstr "Código" #: ../../Creational/StaticFactory/README.rst:29 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Puedes encontrar el código en `GitHub`_" #: ../../Creational/StaticFactory/README.rst:31 msgid "StaticFactory.php" -msgstr "" +msgstr "StaticFactory.php" #: ../../Creational/StaticFactory/README.rst:37 msgid "FormatterInterface.php" -msgstr "" +msgstr "FormatterInterface.php" #: ../../Creational/StaticFactory/README.rst:43 msgid "FormatString.php" -msgstr "" +msgstr "FormatString.php" #: ../../Creational/StaticFactory/README.rst:49 msgid "FormatNumber.php" -msgstr "" +msgstr "FormatNumber.php" #: ../../Creational/StaticFactory/README.rst:56 msgid "Test" -msgstr "" +msgstr "Test" #: ../../Creational/StaticFactory/README.rst:58 msgid "Tests/StaticFactoryTest.php" -msgstr "" +msgstr "Tests/StaticFactoryTest.php" diff --git a/locale/es/LC_MESSAGES/README.po b/locale/es/LC_MESSAGES/README.po index 3a26db2..ddebaed 100644 --- a/locale/es/LC_MESSAGES/README.po +++ b/locale/es/LC_MESSAGES/README.po @@ -1,15 +1,17 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-09-08 17:14+0100\n" +"Last-Translator: Daniel González \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" +"Language: es\n" +"Language-Team: \n" #: ../../README.rst:5 msgid "DesignPatternsPHP" @@ -17,69 +19,90 @@ msgstr "" #: ../../README.rst:11 msgid "" -"This is a collection of known `design patterns`_ and some sample code how to" -" implement them in PHP. Every pattern has a small list of examples (most of " +"This is a collection of known `design patterns`_ and some sample code how to " +"implement them in PHP. Every pattern has a small list of examples (most of " "them from Zend Framework, Symfony2 or Doctrine2 as I'm most familiar with " "this software)." msgstr "" +"Esto es un recopilatorio de los conocidos como `patrones de diseño`_ junto " +"con algunos ejemplos de código sobre como implementarlos en PHP. Cada patrón " +"tiene una pequeña lista de ejemplos ( la mayoría de ellos de Zend " +"Framework, Symfony2 o Doctrine2 ya que estoy más familiarizado con ellos )." #: ../../README.rst:16 msgid "" "I think the problem with patterns is that often people do know them but " "don't know when to apply which." msgstr "" +"El problema con los patrones es que la mayoría de la gente los conoce, pero " +"no saben cuando aplicarlos." #: ../../README.rst:20 msgid "Patterns" -msgstr "" +msgstr "Patrones" #: ../../README.rst:22 msgid "" -"The patterns can be structured in roughly three different categories. Please" -" click on **the title of every pattern's page** for a full explanation of " -"the pattern on Wikipedia." +"The patterns can be structured in roughly three different categories. Please " +"click on **the title of every pattern's page** for a full explanation of the " +"pattern on Wikipedia." msgstr "" +"Los patrones pueden clasificarse en tres categorías diferentes. Por favor " +"pincha en **el título de cada pagina de patrón** para ver la explicación " +"completa del patrón en la Wikipedia." #: ../../README.rst:35 msgid "Contribute" -msgstr "" +msgstr "Contribuir" #: ../../README.rst:37 msgid "" "Please feel free to fork and extend existing or add your own examples and " "send a pull request with your changes! To establish a consistent code " "quality, please check your code using `PHP CodeSniffer`_ against `PSR2 " -"standard`_ using ``./vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor " -".``." +"standard`_ using ``./vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor .``." msgstr "" +"Por favor tomate la libertad de copiar, extender y añadir tus propios " +"ejemplos y enviar una solicitud para añadir tus cambios al repositorio " +"principal. Para establecer una calidad de código consistente revisa que tu " +"código usa `PHP CodeSniffer` con el `PSR2 standard`_ utilizando ``./vendor/" +"bin/phpcs -p --standard=PSR2 --ignore=vendor " #: ../../README.rst:44 msgid "License" -msgstr "" +msgstr "Licencia" #: ../../README.rst:46 msgid "(The MIT License)" -msgstr "" +msgstr "(La licencia MIT)" #: ../../README.rst:48 msgid "Copyright (c) 2014 `Dominik Liebler`_ and `contributors`_" -msgstr "" +msgstr "Copyright (c) 2014 `Dominik Liebler`_ and `contributors`_" #: ../../README.rst:50 msgid "" -"Permission is hereby granted, free of charge, to any person obtaining a copy" -" of this software and associated documentation files (the 'Software'), to " +"Permission is hereby granted, free of charge, to any person obtaining a copy " +"of this software and associated documentation files (the 'Software'), to " "deal in the Software without restriction, including without limitation the " "rights to use, copy, modify, merge, publish, distribute, sublicense, and/or " "sell copies of the Software, and to permit persons to whom the Software is " "furnished to do so, subject to the following conditions:" msgstr "" +"Permission is hereby granted, free of charge, to any person obtaining a copy " +"of this software and associated documentation files (the 'Software'), to " +"deal in the Software without restriction, including without limitation the " +"rights to use, copy, modify, merge, publish, distribute, sublicense, and/or " +"sell copies of the Software, and to permit persons to whom the Software is " +"furnished to do so, subject to the following conditions:" #: ../../README.rst:58 msgid "" "The above copyright notice and this permission notice shall be included in " "all copies or substantial portions of the Software." msgstr "" +"The above copyright notice and this permission notice shall be included in " +"all copies or substantial portions of the Software." #: ../../README.rst:61 msgid "" @@ -88,6 +111,13 @@ msgid "" "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER " "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING " -"FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS" -" IN THE SOFTWARE." +"FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS " +"IN THE SOFTWARE." msgstr "" +"THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR " +"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, " +"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " +"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER " +"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING " +"FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS " +"IN THE SOFTWARE." diff --git a/locale/pt_BR/LC_MESSAGES/Creational/SimpleFactory/README.po b/locale/pt_BR/LC_MESSAGES/Creational/SimpleFactory/README.po index d011ad6..74e85d4 100644 --- a/locale/pt_BR/LC_MESSAGES/Creational/SimpleFactory/README.po +++ b/locale/pt_BR/LC_MESSAGES/Creational/SimpleFactory/README.po @@ -20,7 +20,7 @@ msgid "Purpose" msgstr "" #: ../../Creational/SimpleFactory/README.rst:7 -msgid "ConcreteFactory is a simple factory pattern." +msgid "SimpleFactory is a simple factory pattern." msgstr "" #: ../../Creational/SimpleFactory/README.rst:9 @@ -48,7 +48,7 @@ msgid "You can also find these code on `GitHub`_" msgstr "" #: ../../Creational/SimpleFactory/README.rst:27 -msgid "ConcreteFactory.php" +msgid "SimpleFactory.php" msgstr "" #: ../../Creational/SimpleFactory/README.rst:33 diff --git a/locale/ru/LC_MESSAGES/Behavioral/Memento/README.po b/locale/ru/LC_MESSAGES/Behavioral/Memento/README.po index 913069a..146f4f5 100644 --- a/locale/ru/LC_MESSAGES/Behavioral/Memento/README.po +++ b/locale/ru/LC_MESSAGES/Behavioral/Memento/README.po @@ -1,29 +1,32 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2015-05-29 12:18+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"PO-Revision-Date: 2015-05-30 01:42+0300\n" +"Last-Translator: Eugene Glotov \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Language: ru\n" #: ../../Behavioral/Memento/README.rst:2 msgid "`Memento`__" -msgstr "" +msgstr "`Хранитель`__" #: ../../Behavioral/Memento/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "Назначение" #: ../../Behavioral/Memento/README.rst:7 msgid "" "Provide the ability to restore an object to its previous state (undo via " "rollback)." msgstr "" +"Предоставляет возможность восстановить объект в его предыдущем состоянии или " +"получить доступ к состоянию объекта, не раскрывая его реализацию (т.е. сам " +"объект не обязан иметь функционал возврата текущего состояния)." #: ../../Behavioral/Memento/README.rst:10 msgid "" @@ -39,47 +42,74 @@ msgid "" "other objects or resources - the memento pattern operates on a single " "object." msgstr "" +"Паттерн «Хранитель» реализуется тремя объектами: Создатель, Опекун и " +"Хранитель.\n" +"\n" +"Хранитель — объект, который *хранит конкретный уникальный слепок состояния* " +"любого объекта или ресурса: строка, число, массив, экземпляр класса и так " +"далее. Уникальность в данном случае подразумевает не запрет существования " +"одинаковых состояний в слепках, а то, что состояние можно извлечь в виде " +"независимого клона. Это значит, объект, сохраняемый в Хранитель, должен *быть " +"полной копией исходного объекта а не ссылкой* на исходный объект. Сам объект " +"Хранитель является «непрозрачным объектом» (тот, который никто не может и не " +"должен изменять).\n" +"\n" +"Создатель — это объект, который *содержит в себе актуальное состояние внешнего " +"объекта строго заданного типа* и умеет создать уникальную копию этого " +"состояния, возвращая её обёрнутую в Хранитель. Создатель не знает истории " +"изменений. Создателю можно принудительно установить конкретное состояние " +"извне, которое будет считаться актуальным. Создатель должен позаботиться, " +"чтобы это состояние соответствовало типу объекта, с которым ему разрешено " +"работать. Создатель может (но не обязан) иметь любые методы, но они *не могут " +"менять сохранённое состояние объекта*.\n" +"\n" +"Опекун *управляет историей слепков состояний*. Он может вносить изменения в " +"объект, принимать решение о сохранении состояния внешнего объекта в Создателе, " +"требовать от Создателя слепок текущего состояния, или привести состояние " +"Создателя в соответствие состоянию какого-то слепка из истории." #: ../../Behavioral/Memento/README.rst:23 msgid "Examples" -msgstr "" +msgstr "Примеры" #: ../../Behavioral/Memento/README.rst:25 msgid "The seed of a pseudorandom number generator" msgstr "" +"`Семя `_ псевдослучайного генератора " +"чисел." #: ../../Behavioral/Memento/README.rst:26 msgid "The state in a finite state machine" -msgstr "" +msgstr "Состояние конечного автомата" #: ../../Behavioral/Memento/README.rst:29 msgid "UML Diagram" -msgstr "" +msgstr "UML Диаграмма" #: ../../Behavioral/Memento/README.rst:36 msgid "Code" -msgstr "" +msgstr "Код" #: ../../Behavioral/Memento/README.rst:38 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "Вы можете найти этот код на `GitHub`_" #: ../../Behavioral/Memento/README.rst:40 msgid "Memento.php" -msgstr "" +msgstr "Memento.php" #: ../../Behavioral/Memento/README.rst:46 msgid "Originator.php" -msgstr "" +msgstr "Originator.php" #: ../../Behavioral/Memento/README.rst:52 msgid "Caretaker.php" -msgstr "" +msgstr "Caretaker.php" #: ../../Behavioral/Memento/README.rst:59 msgid "Test" -msgstr "" +msgstr "Тест" #: ../../Behavioral/Memento/README.rst:61 msgid "Tests/MementoTest.php" -msgstr "" +msgstr "Tests/MementoTest.php" diff --git a/locale/ru/LC_MESSAGES/Creational/SimpleFactory/README.po b/locale/ru/LC_MESSAGES/Creational/SimpleFactory/README.po index fdec3c4..4d50b56 100644 --- a/locale/ru/LC_MESSAGES/Creational/SimpleFactory/README.po +++ b/locale/ru/LC_MESSAGES/Creational/SimpleFactory/README.po @@ -20,8 +20,8 @@ msgid "Purpose" msgstr "Назначение" #: ../../Creational/SimpleFactory/README.rst:7 -msgid "ConcreteFactory is a simple factory pattern." -msgstr "ConcreteFactory в примере ниже, это паттерн «Простая Фабрика»." +msgid "SimpleFactory is a simple factory pattern." +msgstr "SimpleFactory в примере ниже, это паттерн «Простая Фабрика»." #: ../../Creational/SimpleFactory/README.rst:9 msgid "" @@ -53,8 +53,8 @@ msgid "You can also find these code on `GitHub`_" msgstr "Вы можете найти этот код на `GitHub`_" #: ../../Creational/SimpleFactory/README.rst:27 -msgid "ConcreteFactory.php" -msgstr "ConcreteFactory.php" +msgid "SimpleFactory.php" +msgstr "SimpleFactory.php" #: ../../Creational/SimpleFactory/README.rst:33 msgid "VehicleInterface.php" diff --git a/locale/zh_CN/LC_MESSAGES/Behavioral/Memento/README.po b/locale/zh_CN/LC_MESSAGES/Behavioral/Memento/README.po index 913069a..fa2378c 100644 --- a/locale/zh_CN/LC_MESSAGES/Behavioral/Memento/README.po +++ b/locale/zh_CN/LC_MESSAGES/Behavioral/Memento/README.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" @@ -19,67 +19,117 @@ msgstr "" msgid "Purpose" msgstr "" -#: ../../Behavioral/Memento/README.rst:7 -msgid "" -"Provide the ability to restore an object to its previous state (undo via " -"rollback)." -msgstr "" - -#: ../../Behavioral/Memento/README.rst:10 -msgid "" -"The memento pattern is implemented with three objects: the originator, a " -"caretaker and a memento. The originator is some object that has an internal " -"state. The caretaker is going to do something to the originator, but wants " -"to be able to undo the change. The caretaker first asks the originator for a" -" memento object. Then it does whatever operation (or sequence of operations)" -" it was going to do. To roll back to the state before the operations, it " -"returns the memento object to the originator. The memento object itself is " -"an opaque object (one which the caretaker cannot, or should not, change). " -"When using this pattern, care should be taken if the originator may change " -"other objects or resources - the memento pattern operates on a single " -"object." -msgstr "" - -#: ../../Behavioral/Memento/README.rst:23 +#: ../../Behavioral/Memento/README.rst:39 msgid "Examples" msgstr "" -#: ../../Behavioral/Memento/README.rst:25 +#: ../../Behavioral/Memento/README.rst:41 msgid "The seed of a pseudorandom number generator" msgstr "" -#: ../../Behavioral/Memento/README.rst:26 +#: ../../Behavioral/Memento/README.rst:42 msgid "The state in a finite state machine" msgstr "" -#: ../../Behavioral/Memento/README.rst:29 +#: ../../Behavioral/Memento/README.rst:46 msgid "UML Diagram" msgstr "" -#: ../../Behavioral/Memento/README.rst:36 +#: ../../Behavioral/Memento/README.rst:53 msgid "Code" msgstr "" -#: ../../Behavioral/Memento/README.rst:38 +#: ../../Behavioral/Memento/README.rst:55 msgid "You can also find these code on `GitHub`_" msgstr "" -#: ../../Behavioral/Memento/README.rst:40 +#: ../../Behavioral/Memento/README.rst:57 msgid "Memento.php" msgstr "" -#: ../../Behavioral/Memento/README.rst:46 +#: ../../Behavioral/Memento/README.rst:63 msgid "Originator.php" msgstr "" -#: ../../Behavioral/Memento/README.rst:52 +#: ../../Behavioral/Memento/README.rst:69 msgid "Caretaker.php" msgstr "" -#: ../../Behavioral/Memento/README.rst:59 +#: ../../Behavioral/Memento/README.rst:76 msgid "Test" msgstr "" -#: ../../Behavioral/Memento/README.rst:61 +#: ../../Behavioral/Memento/README.rst:78 msgid "Tests/MementoTest.php" msgstr "" + +#: ../../Behavioral/Memento/README.rst:7 +msgid "" +"It provides the ability to restore an object to it's previous state (undo " +"via rollback) or to gain access to state of the object, without revealing " +"it's implementation (i.e., the object is not required to have a functional " +"for return the current state)." +msgstr "" + +#: ../../Behavioral/Memento/README.rst:12 +msgid "" +"The memento pattern is implemented with three objects: the Originator, a " +"Caretaker and a Memento." +msgstr "" + +#: ../../Behavioral/Memento/README.rst:15 +msgid "" +"Memento – an object that *contains a concrete unique snapshot of state* of " +"any object or resource: string, number, array, an instance of class and so " +"on. The uniqueness in this case does not imply the prohibition existence of " +"similar states in different snapshots. That means the state can be extracted" +" as the independent clone. Any object stored in the Memento should be *a " +"full copy of the original object rather than a reference* to the original " +"object. The Memento object is a \"opaque object\" (the object that no one " +"can or should change)." +msgstr "" + +#: ../../Behavioral/Memento/README.rst:24 +msgid "" +"Originator – it is an object that contains the *actual state of an external " +"object is strictly specified type*. Originator is able to create a unique " +"copy of this state and return it wrapped in a Memento. The Originator does " +"not know the history of changes. You can set a concrete state to Originator " +"from the outside, which will be considered as actual. The Originator must " +"make sure that given state corresponds the allowed type of object. " +"Originator may (but not should) have any methods, but they *they can't make " +"changes to the saved object state*." +msgstr "" + +#: ../../Behavioral/Memento/README.rst:33 +msgid "" +"Caretaker *controls the states history*. He may make changes to an object; " +"take a decision to save the state of an external object in the Originator; " +"ask from the Originator snapshot of the current state; or set the Originator" +" state to equivalence with some snapshot from history." +msgstr "" + +#: ../../Behavioral/Memento/README.rst:43 +msgid "" +"Control for intermediate states of `ORM Model `_ before saving" +msgstr "" + +#~ msgid "" +#~ "Provide the ability to restore an object to its previous state (undo via " +#~ "rollback)." +#~ msgstr "" + +#~ msgid "" +#~ "The memento pattern is implemented with three objects: the originator, a " +#~ "caretaker and a memento. The originator is some object that has an internal " +#~ "state. The caretaker is going to do something to the originator, but wants " +#~ "to be able to undo the change. The caretaker first asks the originator for a" +#~ " memento object. Then it does whatever operation (or sequence of operations)" +#~ " it was going to do. To roll back to the state before the operations, it " +#~ "returns the memento object to the originator. The memento object itself is " +#~ "an opaque object (one which the caretaker cannot, or should not, change). " +#~ "When using this pattern, care should be taken if the originator may change " +#~ "other objects or resources - the memento pattern operates on a single " +#~ "object." +#~ msgstr "" diff --git a/locale/zh_CN/LC_MESSAGES/Creational/Multiton/README.po b/locale/zh_CN/LC_MESSAGES/Creational/Multiton/README.po index 7ce7048..d187f1b 100644 --- a/locale/zh_CN/LC_MESSAGES/Creational/Multiton/README.po +++ b/locale/zh_CN/LC_MESSAGES/Creational/Multiton/README.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" @@ -19,8 +19,7 @@ msgstr "多例" msgid "" "**THIS IS CONSIDERED TO BE AN ANTI-PATTERN! FOR BETTER TESTABILITY AND " "MAINTAINABILITY USE DEPENDENCY INJECTION!**" -msgstr "" -"**多例模式已经被考虑列入到反模式中!请使用依赖注入获得更好的代码可测试性和可控性!**" +msgstr "**多例模式已经被考虑列入到反模式中!请使用依赖注入获得更好的代码可测试性和可控性!**" #: ../../Creational/Multiton/README.rst:8 msgid "Purpose" @@ -61,5 +60,6 @@ msgid "Multiton.php" msgstr "" #: ../../Creational/Multiton/README.rst:38 -msgid "测试" -msgstr "" +msgid "Test" +msgstr "测试" + diff --git a/locale/zh_CN/LC_MESSAGES/Creational/SimpleFactory/README.po b/locale/zh_CN/LC_MESSAGES/Creational/SimpleFactory/README.po index 56221d8..d8eb51c 100644 --- a/locale/zh_CN/LC_MESSAGES/Creational/SimpleFactory/README.po +++ b/locale/zh_CN/LC_MESSAGES/Creational/SimpleFactory/README.po @@ -20,7 +20,7 @@ msgid "Purpose" msgstr "目的" #: ../../Creational/SimpleFactory/README.rst:7 -msgid "ConcreteFactory is a simple factory pattern." +msgid "SimpleFactory is a simple factory pattern." msgstr "简单的创建对象型工厂模式" #: ../../Creational/SimpleFactory/README.rst:9 @@ -52,7 +52,7 @@ msgid "You can also find these code on `GitHub`_" msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Creational/SimpleFactory/README.rst:27 -msgid "ConcreteFactory.php" +msgid "SimpleFactory.php" msgstr "" #: ../../Creational/SimpleFactory/README.rst:33 diff --git a/locale/zh_CN/LC_MESSAGES/More/Delegation/README.po b/locale/zh_CN/LC_MESSAGES/More/Delegation/README.po index 169e8fd..0b52512 100644 --- a/locale/zh_CN/LC_MESSAGES/More/Delegation/README.po +++ b/locale/zh_CN/LC_MESSAGES/More/Delegation/README.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" @@ -19,10 +19,6 @@ msgstr "" msgid "Purpose" msgstr "" -#: ../../More/Delegation/README.rst:7 ../../More/Delegation/README.rst:12 -msgid "..." -msgstr "" - #: ../../More/Delegation/README.rst:10 msgid "Examples" msgstr "" @@ -58,3 +54,22 @@ msgstr "" #: ../../More/Delegation/README.rst:47 msgid "Tests/DelegationTest.php" msgstr "" + +#: ../../More/Delegation/README.rst:7 +msgid "" +"Demonstrate the Delegator pattern, where an object, instead of performing " +"one of its stated tasks, delegates that task to an associated helper object." +" In this case TeamLead professes to writeCode and Usage uses this, while " +"TeamLead delegates writeCode to JuniorDeveloper's writeBadCode function. " +"This inverts the responsibility so that Usage is unknowingly executing " +"writeBadCode." +msgstr "" + +#: ../../More/Delegation/README.rst:12 +msgid "" +"Please review JuniorDeveloper.php, TeamLead.php, and then Usage.php to see " +"it all tied together." +msgstr "" + +#~ msgid "..." +#~ msgstr "" diff --git a/locale/zh_CN/LC_MESSAGES/README.po b/locale/zh_CN/LC_MESSAGES/README.po index 468f5ca..b2d9e60 100644 --- a/locale/zh_CN/LC_MESSAGES/README.po +++ b/locale/zh_CN/LC_MESSAGES/README.po @@ -32,7 +32,7 @@ msgstr "" msgid "" "I think the problem with patterns is that often people do know them but " "don't know when to apply which." -msgstr “” +msgstr "" "我认为人们对于设计模式抱有的问题在于大家都了解它们却不知道该如何在实际中使用它们。" #: ../../README.rst:20 diff --git a/locale/zh_CN/LC_MESSAGES/Structural/Adapter/README.po b/locale/zh_CN/LC_MESSAGES/Structural/Adapter/README.po index b351fc9..99ac6ec 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/Adapter/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/Adapter/README.po @@ -13,11 +13,11 @@ msgstr "" #: ../../Structural/Adapter/README.rst:2 msgid "`Adapter / Wrapper`__" -msgstr "" +msgstr "`适配器模式`__" #: ../../Structural/Adapter/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/Adapter/README.rst:7 msgid "" @@ -26,32 +26,36 @@ msgid "" "incompatible interfaces by providing it's interface to clients while using " "the original interface." msgstr "" +"将某个类的接口转换成与另一个接口兼容。适配器通过将原始接口进行转换,给用户" +"提供一个兼容接口,使得原来因为接口不同而无法一起使用的类可以得到兼容。" #: ../../Structural/Adapter/README.rst:13 msgid "Examples" -msgstr "" +msgstr "例子" #: ../../Structural/Adapter/README.rst:15 msgid "DB Client libraries adapter" -msgstr "" +msgstr "数据库客户端库适配器" #: ../../Structural/Adapter/README.rst:16 msgid "" "using multiple different webservices and adapters normalize data so that the" " outcome is the same for all" msgstr "" +"使用不同的webservices,通过适配器来标准化输出数据,从而保证不同webservice输出的" +"数据是一致的" #: ../../Structural/Adapter/README.rst:20 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/Adapter/README.rst:27 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/Adapter/README.rst:29 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/Adapter/README.rst:31 msgid "PaperBookInterface.php" @@ -75,7 +79,7 @@ msgstr "" #: ../../Structural/Adapter/README.rst:62 msgid "Test" -msgstr "" +msgstr "测试" #: ../../Structural/Adapter/README.rst:64 msgid "Tests/AdapterTest.php" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/Bridge/README.po b/locale/zh_CN/LC_MESSAGES/Structural/Bridge/README.po index a27619b..54266dc 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/Bridge/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/Bridge/README.po @@ -13,21 +13,22 @@ msgstr "" #: ../../Structural/Bridge/README.rst:2 msgid "`Bridge`__" -msgstr "" +msgstr "`桥接模式`__" #: ../../Structural/Bridge/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/Bridge/README.rst:7 msgid "" "Decouple an abstraction from its implementation so that the two can vary " "independently." msgstr "" +"解耦一个对象的实现与抽象,这样两者可以独立地变化。" #: ../../Structural/Bridge/README.rst:11 msgid "Sample:" -msgstr "" +msgstr "例子" #: ../../Structural/Bridge/README.rst:13 msgid "`Symfony DoctrineBridge `__" @@ -35,15 +36,15 @@ msgstr "" #: ../../Structural/Bridge/README.rst:17 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/Bridge/README.rst:24 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/Bridge/README.rst:26 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/Bridge/README.rst:28 msgid "Workshop.php" @@ -71,7 +72,7 @@ msgstr "" #: ../../Structural/Bridge/README.rst:65 msgid "Test" -msgstr "" +msgstr "测试" #: ../../Structural/Bridge/README.rst:67 msgid "Tests/BridgeTest.php" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/Composite/README.po b/locale/zh_CN/LC_MESSAGES/Structural/Composite/README.po index 90ddd21..8c615d0 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/Composite/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/Composite/README.po @@ -13,45 +13,49 @@ msgstr "" #: ../../Structural/Composite/README.rst:2 msgid "`Composite`__" -msgstr "" +msgstr "`组合模式`__" #: ../../Structural/Composite/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/Composite/README.rst:7 msgid "" "To treat a group of objects the same way as a single instance of the object." -msgstr "" +msgstr "以单个对象的方式来对待一组对象" #: ../../Structural/Composite/README.rst:11 msgid "Examples" -msgstr "" +msgstr "例子" #: ../../Structural/Composite/README.rst:13 msgid "" "a form class instance handles all its form elements like a single instance " "of the form, when ``render()`` is called, it subsequently runs through all " "its child elements and calls ``render()`` on them" -msgstr "" +msgstr "" +"form类的实例包含多个子元素,而它也像单个子元素那样响应render()请求,当" +"调用``render()``方法时,它会历遍所有的子元素,调用``render()``方法" #: ../../Structural/Composite/README.rst:16 msgid "" "``Zend_Config``: a tree of configuration options, each one is a " "``Zend_Config`` object itself" msgstr "" +"``Zend_Config``: 配置选项树, 其每一个分支都是 " +"``Zend_Config`` 对象" #: ../../Structural/Composite/README.rst:20 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/Composite/README.rst:27 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/Composite/README.rst:29 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/Composite/README.rst:31 msgid "FormElement.php" @@ -71,7 +75,7 @@ msgstr "" #: ../../Structural/Composite/README.rst:56 msgid "Test" -msgstr "" +msgstr "测试" #: ../../Structural/Composite/README.rst:58 msgid "Tests/CompositeTest.php" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/DataMapper/README.po b/locale/zh_CN/LC_MESSAGES/Structural/DataMapper/README.po index 5ccd9a3..1dca56f 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/DataMapper/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/DataMapper/README.po @@ -13,11 +13,11 @@ msgstr "" #: ../../Structural/DataMapper/README.rst:2 msgid "`Data Mapper`__" -msgstr "" +msgstr "`数据映射器`__" #: ../../Structural/DataMapper/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/DataMapper/README.rst:7 msgid "" @@ -31,34 +31,42 @@ msgid "" "many different domain entity types, dedicated mappers will handle one or a " "few." msgstr "" +"数据映射器是一个数据访问层,用于将数据在持久性数据存储(通常是一个关系数据库)" +"和内存中的数据表示(领域层)之间进行相互转换。其目的是为了将数据的内存表示、持久存储、" +"数据访问进行分离。该层由一个或者多个映射器组成(或者数据访问对象),并且进行数据的转换。" +"映射器的实现在范围上有所不同。通用映射器将处理许多不同领域的实体类型," +"而专用映射器将处理一个或几个。" #: ../../Structural/DataMapper/README.rst:17 msgid "" "The key point of this pattern is, unlike Active Record pattern, the data " "model follows Single Responsibility Principle." msgstr "" +"此模式的主要特点是,与Active Record不同,其数据模式遵循单一职责原则" +"(Single Responsibility Principle)。" #: ../../Structural/DataMapper/README.rst:21 msgid "Examples" -msgstr "" +msgstr "例子" #: ../../Structural/DataMapper/README.rst:23 msgid "" "DB Object Relational Mapper (ORM) : Doctrine2 uses DAO named as " "\"EntityRepository\"" msgstr "" - +"DB Object Relational Mapper (ORM) : Doctrine2 使用 DAO " +"\"EntityRepository\" 作为DAO" #: ../../Structural/DataMapper/README.rst:27 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/DataMapper/README.rst:34 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/DataMapper/README.rst:36 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/DataMapper/README.rst:38 msgid "User.php" @@ -70,7 +78,7 @@ msgstr "" #: ../../Structural/DataMapper/README.rst:51 msgid "Test" -msgstr "" +msgstr "测试" #: ../../Structural/DataMapper/README.rst:53 msgid "Tests/DataMapperTest.php" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/Decorator/README.po b/locale/zh_CN/LC_MESSAGES/Structural/Decorator/README.po index 0ecf351..e0c38b1 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/Decorator/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/Decorator/README.po @@ -13,41 +13,42 @@ msgstr "" #: ../../Structural/Decorator/README.rst:2 msgid "`Decorator`__" -msgstr "" +msgstr "`装饰器`__" #: ../../Structural/Decorator/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/Decorator/README.rst:7 msgid "To dynamically add new functionality to class instances." -msgstr "" +msgstr "动态地为类的实例添加功能" #: ../../Structural/Decorator/README.rst:10 msgid "Examples" -msgstr "" +msgstr "例子" #: ../../Structural/Decorator/README.rst:12 msgid "Zend Framework: decorators for ``Zend_Form_Element`` instances" -msgstr "" +msgstr "Zend Framework: ``Zend_Form_Element`` 实例的装饰器" #: ../../Structural/Decorator/README.rst:13 msgid "" "Web Service Layer: Decorators JSON and XML for a REST service (in this case," " only one of these should be allowed of course)" msgstr "" +"Web Service层:REST服务的JSON与XML装饰器(当然,在此只能使用其中的一种)" #: ../../Structural/Decorator/README.rst:17 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/Decorator/README.rst:24 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/Decorator/README.rst:26 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/Decorator/README.rst:28 msgid "RendererInterface.php" @@ -71,7 +72,7 @@ msgstr "" #: ../../Structural/Decorator/README.rst:59 msgid "Test" -msgstr "" +msgstr "测试" #: ../../Structural/Decorator/README.rst:61 msgid "Tests/DecoratorTest.php" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/DependencyInjection/README.po b/locale/zh_CN/LC_MESSAGES/Structural/DependencyInjection/README.po index 5111f59..426e487 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/DependencyInjection/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/DependencyInjection/README.po @@ -13,7 +13,7 @@ msgstr "" #: ../../Structural/DependencyInjection/README.rst:2 msgid "`Dependency Injection`__" -msgstr "`依赖注入`__" +msgstr "`依赖注入`" #: ../../Structural/DependencyInjection/README.rst:5 msgid "Purpose" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/Facade/README.po b/locale/zh_CN/LC_MESSAGES/Structural/Facade/README.po index 1d78bf4..110cc58 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/Facade/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/Facade/README.po @@ -13,11 +13,11 @@ msgstr "" #: ../../Structural/Facade/README.rst:2 msgid "`Facade`__" -msgstr "" +msgstr "`外观模式`__" #: ../../Structural/Facade/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/Facade/README.rst:7 msgid "" @@ -25,20 +25,23 @@ msgid "" "of a complex API. It's only a side-effect. The first goal is to reduce " "coupling and follow the Law of Demeter." msgstr "" +"外观模式的目的不是为了让你避免阅读烦人的API文档(当然,它有这样的作用)," +"它的主要目的是为了减少耦合并且遵循得墨忒耳定律(Law of Demeter)" #: ../../Structural/Facade/README.rst:11 msgid "" "A Facade is meant to decouple a client and a sub-system by embedding many " "(but sometimes just one) interface, and of course to reduce complexity." msgstr "" +"Facade通过嵌入多个(当然,有时只有一个)接口来解耦访客与子系统,当然也降低复杂度。" #: ../../Structural/Facade/README.rst:15 msgid "A facade does not forbid you the access to the sub-system" -msgstr "" +msgstr "Facade 不会禁止你访问子系统" #: ../../Structural/Facade/README.rst:16 msgid "You can (you should) have multiple facades for one sub-system" -msgstr "" +msgstr "你可以(应该)为一个子系统提供多个 Facade" #: ../../Structural/Facade/README.rst:18 msgid "" @@ -46,6 +49,8 @@ msgid "" "creations for each method, it is not a Facade, it's a Builder or a " "[Abstract\\|Static\\|Simple] Factory [Method]." msgstr "" +"因此一个好的 Facade 里面不会有 ``new`` 。如果每个方法里都要构造多个对象,那么它就" +"不是 Facade,而是生成器或者[抽象\\|静态\\|简单] 工厂 [方法]。" #: ../../Structural/Facade/README.rst:22 msgid "" @@ -53,18 +58,20 @@ msgid "" "parameters. If you need creation of new instances, use a Factory as " "argument." msgstr "" +"优秀的 Facade 不会有 ``new``,并且构造函数参数是接口类型的。如果你需要创建一个新" +"实例,则在参数中传入一个工厂对象。" #: ../../Structural/Facade/README.rst:27 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/Facade/README.rst:34 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/Facade/README.rst:36 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/Facade/README.rst:38 msgid "Facade.php" @@ -80,7 +87,7 @@ msgstr "" #: ../../Structural/Facade/README.rst:57 msgid "Test" -msgstr "" +msgstr "测试" #: ../../Structural/Facade/README.rst:59 msgid "Tests/FacadeTest.php" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/FluentInterface/README.po b/locale/zh_CN/LC_MESSAGES/Structural/FluentInterface/README.po index 0e58551..f0cc8d8 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/FluentInterface/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/FluentInterface/README.po @@ -13,45 +13,46 @@ msgstr "" #: ../../Structural/FluentInterface/README.rst:2 msgid "`Fluent Interface`__" -msgstr "" +msgstr "`连贯接口`__" #: ../../Structural/FluentInterface/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/FluentInterface/README.rst:7 msgid "" "To write code that is easy readable just like sentences in a natural " "language (like English)." msgstr "" +"用来编写易于阅读的代码,就像自然语言一样(如英语)" #: ../../Structural/FluentInterface/README.rst:11 msgid "Examples" -msgstr "" +msgstr "例子" #: ../../Structural/FluentInterface/README.rst:13 msgid "Doctrine2's QueryBuilder works something like that example class below" -msgstr "" +msgstr "Doctrine2 的 QueryBuilder,就像下面例子中类似" #: ../../Structural/FluentInterface/README.rst:15 msgid "PHPUnit uses fluent interfaces to build mock objects" -msgstr "" +msgstr "PHPUnit 使用连贯接口来创建 mock 对象" #: ../../Structural/FluentInterface/README.rst:16 msgid "Yii Framework: CDbCommand and CActiveRecord use this pattern, too" -msgstr "" +msgstr "Yii 框架:CDbCommand 与 CActiveRecord 也使用此模式" #: ../../Structural/FluentInterface/README.rst:19 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/FluentInterface/README.rst:26 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/FluentInterface/README.rst:28 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/FluentInterface/README.rst:30 msgid "Sql.php" @@ -59,7 +60,7 @@ msgstr "" #: ../../Structural/FluentInterface/README.rst:37 msgid "Test" -msgstr "" +msgstr "测试" #: ../../Structural/FluentInterface/README.rst:39 msgid "Tests/FluentInterfaceTest.php" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/Proxy/README.po b/locale/zh_CN/LC_MESSAGES/Structural/Proxy/README.po index 290eacc..5df1caf 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/Proxy/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/Proxy/README.po @@ -13,19 +13,19 @@ msgstr "" #: ../../Structural/Proxy/README.rst:2 msgid "`Proxy`__" -msgstr "" +msgstr "`代理模式`__" #: ../../Structural/Proxy/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/Proxy/README.rst:7 msgid "To interface to anything that is expensive or impossible to duplicate." -msgstr "" +msgstr "为昂贵或者无法复制的资源提供接口。" #: ../../Structural/Proxy/README.rst:10 msgid "Examples" -msgstr "" +msgstr "例子" #: ../../Structural/Proxy/README.rst:12 msgid "" @@ -33,18 +33,20 @@ msgid "" "initialization) in them, while the user still works with his own entity " "classes and will never use nor touch the proxies" msgstr "" +"Doctrine2 使用代理来实现框架特性(如延迟初始化),同时用户还是使用自己的实体类" +"并且不会使用或者接触到代理" #: ../../Structural/Proxy/README.rst:17 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/Proxy/README.rst:24 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/Proxy/README.rst:26 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/Proxy/README.rst:28 msgid "Record.php" @@ -56,4 +58,4 @@ msgstr "" #: ../../Structural/Proxy/README.rst:41 msgid "Test" -msgstr "" +msgstr "测试" diff --git a/locale/zh_CN/LC_MESSAGES/Structural/Registry/README.po b/locale/zh_CN/LC_MESSAGES/Structural/Registry/README.po index 843138c..f01d956 100644 --- a/locale/zh_CN/LC_MESSAGES/Structural/Registry/README.po +++ b/locale/zh_CN/LC_MESSAGES/Structural/Registry/README.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" @@ -13,11 +13,11 @@ msgstr "" #: ../../Structural/Registry/README.rst:2 msgid "`Registry`__" -msgstr "" +msgstr "`注册模式`__" #: ../../Structural/Registry/README.rst:5 msgid "Purpose" -msgstr "" +msgstr "目的" #: ../../Structural/Registry/README.rst:7 msgid "" @@ -25,34 +25,32 @@ msgid "" "application, is typically implemented using an abstract class with only " "static methods (or using the Singleton pattern)" msgstr "" +"为应用中常用的对象实现一个中央存储,通常用一个只有静态方法的抽象类来实现" +"(或者使用单例模式)" #: ../../Structural/Registry/README.rst:12 msgid "Examples" -msgstr "" - -#: ../../Structural/Registry/README.rst:14 -msgid "" -"Zend Framework: ``Zend_Registry`` holds the application's logger object, " -"front controller etc." -msgstr "" +msgstr "例子" #: ../../Structural/Registry/README.rst:16 msgid "" "Yii Framework: ``CWebApplication`` holds all the application components, " "such as ``CWebUser``, ``CUrlManager``, etc." msgstr "" +"Yii 框架: ``CWebApplication`` 持有所有的应用组件," +"如 ``CWebUser``, ``CUrlManager``, 等。" #: ../../Structural/Registry/README.rst:20 msgid "UML Diagram" -msgstr "" +msgstr "UML 图" #: ../../Structural/Registry/README.rst:27 msgid "Code" -msgstr "" +msgstr "代码" #: ../../Structural/Registry/README.rst:29 msgid "You can also find these code on `GitHub`_" -msgstr "" +msgstr "你可以在 `GitHub`_ 上找到这些代码" #: ../../Structural/Registry/README.rst:31 msgid "Registry.php" @@ -60,8 +58,20 @@ msgstr "" #: ../../Structural/Registry/README.rst:38 msgid "Test" -msgstr "" +msgstr "测试" #: ../../Structural/Registry/README.rst:40 msgid "Tests/RegistryTest.php" msgstr "" + +#: ../../Structural/Registry/README.rst:14 +msgid "" +"Zend Framework 1: ``Zend_Registry`` holds the application's logger object, " +"front controller etc." +msgstr "" +"Zend Framework 1: ``Zend_Registry`` 持有应用的logger对象,前端控制器等。" + +#~ msgid "" +#~ "Zend Framework: ``Zend_Registry`` holds the application's logger object, " +#~ "front controller etc." +#~ msgstr ""