├── .gitignore ├── .travis.yml ├── Behavioral ├── ChainOfResponsibilities │ ├── Handler.php │ ├── README.rst │ ├── Request.php │ ├── Responsible │ │ ├── FastStorage.php │ │ └── SlowStorage.php │ ├── Tests │ │ └── ChainTest.php │ └── uml │ │ ├── ChainOfResponsibilities.uml │ │ ├── uml.png │ │ └── uml.svg ├── Command │ ├── CommandInterface.php │ ├── HelloCommand.php │ ├── Invoker.php │ ├── README.rst │ ├── Receiver.php │ ├── Tests │ │ └── CommandTest.php │ └── uml │ │ ├── Command.uml │ │ ├── uml.png │ │ └── uml.svg ├── Iterator │ ├── Book.php │ ├── BookList.php │ ├── BookListIterator.php │ ├── BookListReverseIterator.php │ ├── README.rst │ ├── Tests │ │ └── IteratorTest.php │ └── uml │ │ ├── Iterator.uml │ │ ├── uml.png │ │ └── uml.svg ├── Mediator │ ├── Colleague.php │ ├── Mediator.php │ ├── MediatorInterface.php │ ├── README.rst │ ├── Subsystem │ │ ├── Client.php │ │ ├── Database.php │ │ └── Server.php │ ├── Tests │ │ └── MediatorTest.php │ └── uml │ │ ├── Mediator.uml │ │ ├── uml.png │ │ └── uml.svg ├── Memento │ ├── Caretaker.php │ ├── Memento.php │ ├── Originator.php │ ├── README.rst │ ├── Tests │ │ └── MementoTest.php │ └── uml │ │ ├── Momento.uml │ │ ├── uml.png │ │ └── uml.svg ├── NullObject │ ├── LoggerInterface.php │ ├── NullLogger.php │ ├── PrintLogger.php │ ├── README.rst │ ├── Service.php │ ├── Tests │ │ └── LoggerTest.php │ └── uml │ │ ├── NullObject.uml │ │ ├── uml.png │ │ └── uml.svg ├── Observer │ ├── README.rst │ ├── Tests │ │ └── ObserverTest.php │ ├── User.php │ ├── UserObserver.php │ └── uml │ │ ├── Observer.uml │ │ ├── uml.png │ │ └── uml.svg ├── README.md ├── README.rst ├── Specification │ ├── AbstractSpecification.php │ ├── Either.php │ ├── Item.php │ ├── Not.php │ ├── Plus.php │ ├── PriceSpecification.php │ ├── README.rst │ ├── SpecificationInterface.php │ ├── Tests │ │ └── SpecificationTest.php │ └── uml │ │ ├── Specification.uml │ │ ├── uml.png │ │ └── uml.svg ├── State │ ├── CreateOrder.php │ ├── OrderController.php │ ├── OrderFactory.php │ ├── OrderInterface.php │ ├── README.rst │ ├── ShippingOrder.php │ └── uml │ │ ├── State.uml │ │ ├── uml.png │ │ └── uml.svg ├── Strategy │ ├── ComparatorInterface.php │ ├── DateComparator.php │ ├── IdComparator.php │ ├── ObjectCollection.php │ ├── README.rst │ ├── Tests │ │ └── StrategyTest.php │ └── uml │ │ ├── Strategy.uml │ │ ├── uml.png │ │ └── uml.svg ├── TemplateMethod │ ├── BeachJourney.php │ ├── CityJourney.php │ ├── Journey.php │ ├── README.rst │ ├── Tests │ │ └── JourneyTest.php │ └── uml │ │ ├── TemplateMethod.uml │ │ ├── uml.png │ │ └── uml.svg └── Visitor │ ├── Group.php │ ├── README.rst │ ├── Role.php │ ├── RolePrintVisitor.php │ ├── RoleVisitorInterface.php │ ├── Tests │ └── VisitorTest.php │ ├── User.php │ └── uml │ ├── Visitor.uml │ ├── uml.png │ └── uml.svg ├── Creational ├── AbstractFactory │ ├── AbstractFactory.php │ ├── Html │ │ ├── Picture.php │ │ └── Text.php │ ├── HtmlFactory.php │ ├── Json │ │ ├── Picture.php │ │ └── Text.php │ ├── JsonFactory.php │ ├── MediaInterface.php │ ├── Picture.php │ ├── README.rst │ ├── Tests │ │ └── AbstractFactoryTest.php │ ├── Text.php │ └── uml │ │ ├── AbstractFactory.uml │ │ ├── uml.png │ │ └── uml.svg ├── Builder │ ├── BikeBuilder.php │ ├── BuilderInterface.php │ ├── CarBuilder.php │ ├── Director.php │ ├── Parts │ │ ├── Bike.php │ │ ├── Car.php │ │ ├── Door.php │ │ ├── Engine.php │ │ ├── Vehicle.php │ │ └── Wheel.php │ ├── README.rst │ ├── Tests │ │ └── DirectorTest.php │ └── uml │ │ ├── Builder.uml │ │ ├── uml.png │ │ └── uml.svg ├── FactoryMethod │ ├── Bicycle.php │ ├── FactoryMethod.php │ ├── Ferrari.php │ ├── GermanFactory.php │ ├── ItalianFactory.php │ ├── Porsche.php │ ├── README.rst │ ├── Tests │ │ └── FactoryMethodTest.php │ ├── VehicleInterface.php │ └── uml │ │ ├── FactoryMethod.uml │ │ ├── uml.png │ │ └── uml.svg ├── Multiton │ ├── Multiton.php │ ├── README.rst │ └── uml │ │ ├── Multiton.uml │ │ ├── uml.png │ │ └── uml.svg ├── Pool │ ├── Pool.php │ ├── Processor.php │ ├── README.rst │ ├── Tests │ │ ├── PoolTest.php │ │ └── TestWorker.php │ ├── Worker.php │ └── uml │ │ ├── Pool.uml │ │ ├── uml.png │ │ └── uml.svg ├── Prototype │ ├── BarBookPrototype.php │ ├── BookPrototype.php │ ├── FooBookPrototype.php │ ├── README.rst │ ├── index.php │ └── uml │ │ ├── Prototype.uml │ │ ├── uml.png │ │ └── uml.svg ├── README.md ├── README.rst ├── SimpleFactory │ ├── Bicycle.php │ ├── ConcreteFactory.php │ ├── README.rst │ ├── Scooter.php │ ├── Tests │ │ └── SimpleFactoryTest.php │ ├── VehicleInterface.php │ └── uml │ │ ├── SimpleFactory.uml │ │ ├── uml.png │ │ └── uml.svg ├── Singleton │ ├── README.rst │ ├── Singleton.php │ ├── Tests │ │ └── SingletonTest.php │ └── uml │ │ ├── Singleton.uml │ │ ├── uml.png │ │ └── uml.svg └── StaticFactory │ ├── FormatNumber.php │ ├── FormatString.php │ ├── FormatterInterface.php │ ├── README.rst │ ├── StaticFactory.php │ ├── Tests │ └── StaticFactoryTest.php │ └── uml │ ├── StaticFactory.uml │ ├── uml.png │ └── uml.svg ├── LICENSE ├── Makefile ├── More ├── Delegation │ ├── JuniorDeveloper.php │ ├── README.rst │ ├── TeamLead.php │ ├── Tests │ │ └── DelegationTest.php │ ├── Usage.php │ └── uml │ │ ├── Delegation.uml │ │ ├── uml.png │ │ └── uml.svg ├── README.md ├── README.rst ├── Repository │ ├── MemoryStorage.php │ ├── Post.php │ ├── PostRepository.php │ ├── README.rst │ ├── Storage.php │ └── uml │ │ ├── Repository.uml │ │ ├── uml.png │ │ └── uml.svg └── ServiceLocator │ ├── DatabaseService.php │ ├── DatabaseServiceInterface.php │ ├── LogService.php │ ├── LogServiceInterface.php │ ├── README.rst │ ├── ServiceLocator.php │ ├── ServiceLocatorInterface.php │ ├── Tests │ └── ServiceLocatorTest.php │ └── uml │ ├── ServiceLocator.uml │ ├── uml.png │ └── uml.svg ├── README.md ├── README.rst ├── Structural ├── Adapter │ ├── Book.php │ ├── EBookAdapter.php │ ├── EBookInterface.php │ ├── Kindle.php │ ├── PaperBookInterface.php │ ├── README.rst │ ├── Tests │ │ └── AdapterTest.php │ └── uml │ │ ├── Adapter.uml │ │ ├── uml.png │ │ └── uml.svg ├── Bridge │ ├── Assemble.php │ ├── Car.php │ ├── Motorcycle.php │ ├── Produce.php │ ├── README.rst │ ├── Tests │ │ └── BridgeTest.php │ ├── Vehicle.php │ ├── Workshop.php │ └── uml │ │ ├── Bridge.uml │ │ ├── uml.png │ │ └── uml.svg ├── Composite │ ├── Form.php │ ├── FormElement.php │ ├── InputElement.php │ ├── README.rst │ ├── Tests │ │ └── CompositeTest.php │ ├── TextElement.php │ └── uml │ │ ├── Composite.uml │ │ ├── uml.png │ │ ├── uml.svg │ │ └── uml.txt ├── DataMapper │ ├── README.rst │ ├── Tests │ │ └── DataMapperTest.php │ ├── User.php │ ├── UserMapper.php │ └── uml │ │ ├── DataMapper.uml │ │ ├── uml.png │ │ └── uml.svg ├── Decorator │ ├── Decorator.php │ ├── README.rst │ ├── RenderInJson.php │ ├── RenderInXml.php │ ├── RendererInterface.php │ ├── Tests │ │ └── DecoratorTest.php │ ├── Webservice.php │ └── uml │ │ ├── Decorator.uml │ │ ├── uml.png │ │ └── uml.svg ├── DependencyInjection │ ├── AbstractConfig.php │ ├── ArrayConfig.php │ ├── Connection.php │ ├── Parameters.php │ ├── README.rst │ ├── Tests │ │ ├── DependencyInjectionTest.php │ │ └── config.php │ └── uml │ │ ├── DependencyInjection.uml │ │ ├── uml.png │ │ └── uml.svg ├── Facade │ ├── BiosInterface.php │ ├── Facade.php │ ├── OsInterface.php │ ├── README.rst │ ├── Tests │ │ └── FacadeTest.php │ └── uml │ │ ├── Facade.uml │ │ ├── uml.png │ │ └── uml.svg ├── FluentInterface │ ├── README.rst │ ├── Sql.php │ ├── Tests │ │ └── FluentInterfaceTest.php │ └── uml │ │ ├── FluentInterface.uml │ │ ├── uml.png │ │ └── uml.svg ├── Proxy │ ├── README.rst │ ├── Record.php │ ├── RecordProxy.php │ └── uml │ │ ├── Proxy.uml │ │ ├── uml.png │ │ └── uml.svg ├── README.md ├── README.rst └── Registry │ ├── README.rst │ ├── Registry.php │ ├── Tests │ └── RegistryTest.php │ └── uml │ ├── Registry.uml │ ├── uml.png │ └── uml.svg ├── composer.json ├── composer.lock ├── conf.py ├── locale ├── ca │ └── LC_MESSAGES │ │ ├── Behavioral │ │ ├── ChainOfResponsibilities │ │ │ └── README.po │ │ ├── Command │ │ │ └── README.po │ │ ├── Iterator │ │ │ └── README.po │ │ ├── Mediator │ │ │ └── README.po │ │ ├── Memento │ │ │ └── README.po │ │ ├── NullObject │ │ │ └── README.po │ │ ├── Observer │ │ │ └── README.po │ │ ├── README.po │ │ ├── Specification │ │ │ └── README.po │ │ ├── State │ │ │ └── README.po │ │ ├── Strategy │ │ │ └── README.po │ │ ├── TemplateMethod │ │ │ └── README.po │ │ └── Visitor │ │ │ └── README.po │ │ ├── Creational │ │ ├── AbstractFactory │ │ │ └── README.po │ │ ├── Builder │ │ │ └── README.po │ │ ├── FactoryMethod │ │ │ └── README.po │ │ ├── Multiton │ │ │ └── README.po │ │ ├── Pool │ │ │ └── README.po │ │ ├── Prototype │ │ │ └── README.po │ │ ├── README.po │ │ ├── SimpleFactory │ │ │ └── README.po │ │ ├── Singleton │ │ │ └── README.po │ │ └── StaticFactory │ │ │ └── README.po │ │ ├── More │ │ ├── Delegation │ │ │ └── README.po │ │ ├── README.po │ │ ├── Repository │ │ │ └── README.po │ │ └── ServiceLocator │ │ │ └── README.po │ │ ├── README.po │ │ └── Structural │ │ ├── Adapter │ │ └── README.po │ │ ├── Bridge │ │ └── README.po │ │ ├── Composite │ │ └── README.po │ │ ├── DataMapper │ │ └── README.po │ │ ├── Decorator │ │ └── README.po │ │ ├── DependencyInjection │ │ └── README.po │ │ ├── Facade │ │ └── README.po │ │ ├── FluentInterface │ │ └── README.po │ │ ├── Proxy │ │ └── README.po │ │ ├── README.po │ │ └── Registry │ │ └── README.po ├── es │ └── LC_MESSAGES │ │ ├── Behavioral │ │ ├── ChainOfResponsibilities │ │ │ └── README.po │ │ ├── Command │ │ │ └── README.po │ │ ├── Iterator │ │ │ └── README.po │ │ ├── Mediator │ │ │ └── README.po │ │ ├── Memento │ │ │ └── README.po │ │ ├── NullObject │ │ │ └── README.po │ │ ├── Observer │ │ │ └── README.po │ │ ├── README.po │ │ ├── Specification │ │ │ └── README.po │ │ ├── State │ │ │ └── README.po │ │ ├── Strategy │ │ │ └── README.po │ │ ├── TemplateMethod │ │ │ └── README.po │ │ └── Visitor │ │ │ └── README.po │ │ ├── Creational │ │ ├── AbstractFactory │ │ │ └── README.po │ │ ├── Builder │ │ │ └── README.po │ │ ├── FactoryMethod │ │ │ └── README.po │ │ ├── Multiton │ │ │ └── README.po │ │ ├── Pool │ │ │ └── README.po │ │ ├── Prototype │ │ │ └── README.po │ │ ├── README.po │ │ ├── SimpleFactory │ │ │ └── README.po │ │ ├── Singleton │ │ │ └── README.po │ │ └── StaticFactory │ │ │ └── README.po │ │ ├── More │ │ ├── Delegation │ │ │ └── README.po │ │ ├── README.po │ │ ├── Repository │ │ │ └── README.po │ │ └── ServiceLocator │ │ │ └── README.po │ │ ├── README.po │ │ └── Structural │ │ ├── Adapter │ │ └── README.po │ │ ├── Bridge │ │ └── README.po │ │ ├── Composite │ │ └── README.po │ │ ├── DataMapper │ │ └── README.po │ │ ├── Decorator │ │ └── README.po │ │ ├── DependencyInjection │ │ └── README.po │ │ ├── Facade │ │ └── README.po │ │ ├── FluentInterface │ │ └── README.po │ │ ├── Proxy │ │ └── README.po │ │ ├── README.po │ │ └── Registry │ │ └── README.po ├── pt_BR │ └── LC_MESSAGES │ │ ├── Behavioral │ │ ├── ChainOfResponsibilities │ │ │ └── README.po │ │ ├── Command │ │ │ └── README.po │ │ ├── Iterator │ │ │ └── README.po │ │ ├── Mediator │ │ │ └── README.po │ │ ├── Memento │ │ │ └── README.po │ │ ├── NullObject │ │ │ └── README.po │ │ ├── Observer │ │ │ └── README.po │ │ ├── README.po │ │ ├── Specification │ │ │ └── README.po │ │ ├── State │ │ │ └── README.po │ │ ├── Strategy │ │ │ └── README.po │ │ ├── TemplateMethod │ │ │ └── README.po │ │ └── Visitor │ │ │ └── README.po │ │ ├── Creational │ │ ├── AbstractFactory │ │ │ └── README.po │ │ ├── Builder │ │ │ └── README.po │ │ ├── FactoryMethod │ │ │ └── README.po │ │ ├── Multiton │ │ │ └── README.po │ │ ├── Pool │ │ │ └── README.po │ │ ├── Prototype │ │ │ └── README.po │ │ ├── README.po │ │ ├── SimpleFactory │ │ │ └── README.po │ │ ├── Singleton │ │ │ └── README.po │ │ └── StaticFactory │ │ │ └── README.po │ │ ├── More │ │ ├── Delegation │ │ │ └── README.po │ │ ├── README.po │ │ ├── Repository │ │ │ └── README.po │ │ └── ServiceLocator │ │ │ └── README.po │ │ ├── README.po │ │ └── Structural │ │ ├── Adapter │ │ └── README.po │ │ ├── Bridge │ │ └── README.po │ │ ├── Composite │ │ └── README.po │ │ ├── DataMapper │ │ └── README.po │ │ ├── Decorator │ │ └── README.po │ │ ├── DependencyInjection │ │ └── README.po │ │ ├── Facade │ │ └── README.po │ │ ├── FluentInterface │ │ └── README.po │ │ ├── Proxy │ │ └── README.po │ │ ├── README.po │ │ └── Registry │ │ └── README.po ├── ru │ └── LC_MESSAGES │ │ ├── Behavioral │ │ ├── ChainOfResponsibilities │ │ │ └── README.po │ │ ├── Command │ │ │ └── README.po │ │ ├── Iterator │ │ │ └── README.po │ │ ├── Mediator │ │ │ └── README.po │ │ ├── Memento │ │ │ └── README.po │ │ ├── NullObject │ │ │ └── README.po │ │ ├── Observer │ │ │ └── README.po │ │ ├── README.po │ │ ├── Specification │ │ │ └── README.po │ │ ├── State │ │ │ └── README.po │ │ ├── Strategy │ │ │ └── README.po │ │ ├── TemplateMethod │ │ │ └── README.po │ │ └── Visitor │ │ │ └── README.po │ │ ├── Creational │ │ ├── AbstractFactory │ │ │ └── README.po │ │ ├── Builder │ │ │ └── README.po │ │ ├── FactoryMethod │ │ │ └── README.po │ │ ├── Multiton │ │ │ └── README.po │ │ ├── Pool │ │ │ └── README.po │ │ ├── Prototype │ │ │ └── README.po │ │ ├── README.po │ │ ├── SimpleFactory │ │ │ └── README.po │ │ ├── Singleton │ │ │ └── README.po │ │ └── StaticFactory │ │ │ └── README.po │ │ ├── More │ │ ├── Delegation │ │ │ └── README.po │ │ ├── README.po │ │ ├── Repository │ │ │ └── README.po │ │ └── ServiceLocator │ │ │ └── README.po │ │ ├── README.po │ │ └── Structural │ │ ├── Adapter │ │ └── README.po │ │ ├── Bridge │ │ └── README.po │ │ ├── Composite │ │ └── README.po │ │ ├── DataMapper │ │ └── README.po │ │ ├── Decorator │ │ └── README.po │ │ ├── DependencyInjection │ │ └── README.po │ │ ├── Facade │ │ └── README.po │ │ ├── FluentInterface │ │ └── README.po │ │ ├── Proxy │ │ └── README.po │ │ ├── README.po │ │ └── Registry │ │ └── README.po └── zh_CN │ └── LC_MESSAGES │ ├── Behavioral │ ├── ChainOfResponsibilities │ │ └── README.po │ ├── Command │ │ └── README.po │ ├── Iterator │ │ └── README.po │ ├── Mediator │ │ └── README.po │ ├── Memento │ │ └── README.po │ ├── NullObject │ │ └── README.po │ ├── Observer │ │ └── README.po │ ├── README.po │ ├── Specification │ │ └── README.po │ ├── State │ │ └── README.po │ ├── Strategy │ │ └── README.po │ ├── TemplateMethod │ │ └── README.po │ └── Visitor │ │ └── README.po │ ├── Creational │ ├── AbstractFactory │ │ └── README.po │ ├── Builder │ │ └── README.po │ ├── FactoryMethod │ │ └── README.po │ ├── Multiton │ │ └── README.po │ ├── Pool │ │ └── README.po │ ├── Prototype │ │ └── README.po │ ├── README.po │ ├── SimpleFactory │ │ └── README.po │ ├── Singleton │ │ └── README.po │ └── StaticFactory │ │ └── README.po │ ├── More │ ├── Delegation │ │ └── README.po │ ├── README.po │ ├── Repository │ │ └── README.po │ └── ServiceLocator │ │ └── README.po │ ├── README.po │ └── Structural │ ├── Adapter │ └── README.po │ ├── Bridge │ └── README.po │ ├── Composite │ └── README.po │ ├── DataMapper │ └── README.po │ ├── Decorator │ └── README.po │ ├── DependencyInjection │ └── README.po │ ├── Facade │ └── README.po │ ├── FluentInterface │ └── README.po │ ├── Proxy │ └── README.po │ ├── README.po │ └── Registry │ └── README.po ├── make.bat └── phpunit.xml.dist /.gitignore: -------------------------------------------------------------------------------- 1 | # common 2 | .idea 3 | /nbproject 4 | /vendor/ 5 | _build/ 6 | *.mo 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | php: 6 | - 5.3 7 | - 5.4 8 | - 5.5 9 | - 5.6 10 | - 7.0 11 | - hhvm 12 | 13 | matrix: 14 | allow_failures: 15 | - php: hhvm 16 | - php: 7.0 17 | fast_finish: true 18 | 19 | cache: 20 | directories: 21 | - $HOME/.composer/cache 22 | 23 | before_install: 24 | - composer self-update 25 | - composer validate 26 | 27 | install: 28 | - composer install --prefer-dist --no-interaction 29 | 30 | script: 31 | - vendor/bin/phpunit 32 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibilities/Request.php: -------------------------------------------------------------------------------- 1 | data = $data; 24 | } 25 | 26 | protected function processing(Request $req) 27 | { 28 | if ('get' === $req->verb) { 29 | if (array_key_exists($req->key, $this->data)) { 30 | // the handler IS responsible and then processes the request 31 | $req->response = $this->data[$req->key]; 32 | // instead of returning true, I could return the value but it proves 33 | // to be a bad idea. What if the value IS "false" ? 34 | return true; 35 | } 36 | } 37 | 38 | return false; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibilities/Responsible/SlowStorage.php: -------------------------------------------------------------------------------- 1 | data = $data; 31 | } 32 | 33 | protected function processing(Request $req) 34 | { 35 | if ('get' === $req->verb) { 36 | if (array_key_exists($req->key, $this->data)) { 37 | $req->response = $this->data[$req->key]; 38 | 39 | return true; 40 | } 41 | } 42 | 43 | return false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibilities/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/ChainOfResponsibilities/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/Command/CommandInterface.php: -------------------------------------------------------------------------------- 1 | output = $console; 25 | } 26 | 27 | /** 28 | * execute and output "Hello World" 29 | */ 30 | public function execute() 31 | { 32 | // sometimes, there is no receiver and this is the command which 33 | // does all the work 34 | $this->output->write('Hello World'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Behavioral/Command/Invoker.php: -------------------------------------------------------------------------------- 1 | command = $cmd; 25 | } 26 | 27 | /** 28 | * executes the command 29 | */ 30 | public function run() 31 | { 32 | // here is a key feature of the invoker 33 | // the invoker is the same whatever is the command 34 | $this->command->execute(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Behavioral/Command/Receiver.php: -------------------------------------------------------------------------------- 1 | invoker = new Invoker(); 28 | $this->receiver = new Receiver(); 29 | } 30 | 31 | public function testInvocation() 32 | { 33 | $this->invoker->setCommand(new HelloCommand($this->receiver)); 34 | $this->expectOutputString('Hello World'); 35 | $this->invoker->run(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Behavioral/Command/uml/Command.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Behavioral\Command\HelloCommand 5 | 6 | \DesignPatterns\Behavioral\Command\Invoker 7 | \DesignPatterns\Behavioral\Command\HelloCommand 8 | \DesignPatterns\Behavioral\Command\Receiver 9 | \DesignPatterns\Behavioral\Command\CommandInterface 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Fields 22 | Constants 23 | Constructors 24 | Methods 25 | 26 | private 27 | 28 | 29 | -------------------------------------------------------------------------------- /Behavioral/Command/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/Command/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/Iterator/Book.php: -------------------------------------------------------------------------------- 1 | author = $author; 15 | $this->title = $title; 16 | } 17 | 18 | public function getAuthor() 19 | { 20 | return $this->author; 21 | } 22 | 23 | public function getTitle() 24 | { 25 | return $this->title; 26 | } 27 | 28 | public function getAuthorAndTitle() 29 | { 30 | return $this->getTitle() . ' by ' . $this->getAuthor(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Behavioral/Iterator/BookList.php: -------------------------------------------------------------------------------- 1 | count()) { 13 | return $this->books[$bookNumberToGet]; 14 | } 15 | 16 | return null; 17 | } 18 | 19 | public function addBook(Book $book) 20 | { 21 | $this->books[] = $book; 22 | 23 | return $this->count(); 24 | } 25 | 26 | public function removeBook(Book $bookToRemove) 27 | { 28 | foreach ($this->books as $key => $book) { 29 | /** @var Book $book */ 30 | if ($book->getAuthorAndTitle() === $bookToRemove->getAuthorAndTitle()) { 31 | unset($this->books[$key]); 32 | } 33 | } 34 | 35 | return $this->count(); 36 | } 37 | 38 | public function count() 39 | { 40 | return count($this->books); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Behavioral/Iterator/BookListReverseIterator.php: -------------------------------------------------------------------------------- 1 | bookList = $bookList; 11 | $this->currentBook = $this->bookList->count() - 1; 12 | } 13 | 14 | public function next() 15 | { 16 | $this->currentBook--; 17 | } 18 | 19 | public function valid() 20 | { 21 | return 0 <= $this->currentBook; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Behavioral/Iterator/README.rst: -------------------------------------------------------------------------------- 1 | `Iterator`__ 2 | ============ 3 | 4 | Purpose 5 | ------- 6 | 7 | To make an object iterable and to make it appear like a collection of 8 | objects. 9 | 10 | Examples 11 | -------- 12 | 13 | - to process a file line by line by just running over all lines (which 14 | have an object representation) for a file (which of course is an 15 | object, too) 16 | 17 | Note 18 | ---- 19 | 20 | Standard PHP Library (SPL) defines an interface Iterator which is best 21 | suited for this! Often you would want to implement the Countable 22 | interface too, to allow ``count($object)`` on your iterable object 23 | 24 | UML Diagram 25 | ----------- 26 | 27 | .. image:: uml/uml.png 28 | :alt: Alt Iterator UML Diagram 29 | :align: center 30 | 31 | Code 32 | ---- 33 | 34 | You can also find these code on `GitHub`_ 35 | 36 | Book.php 37 | 38 | .. literalinclude:: Book.php 39 | :language: php 40 | :linenos: 41 | 42 | BookList.php 43 | 44 | .. literalinclude:: BookList.php 45 | :language: php 46 | :linenos: 47 | 48 | BookListIterator.php 49 | 50 | .. literalinclude:: BookListIterator.php 51 | :language: php 52 | :linenos: 53 | 54 | BookListReverseIterator.php 55 | 56 | .. literalinclude:: BookListReverseIterator.php 57 | :language: php 58 | :linenos: 59 | 60 | Test 61 | ---- 62 | 63 | Tests/IteratorTest.php 64 | 65 | .. literalinclude:: Tests/IteratorTest.php 66 | :language: php 67 | :linenos: 68 | 69 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Iterator 70 | .. __: http://en.wikipedia.org/wiki/Iterator_pattern -------------------------------------------------------------------------------- /Behavioral/Iterator/uml/Iterator.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Behavioral\Iterator\Book 5 | 6 | \DesignPatterns\Behavioral\Iterator\BookListReverseIterator 7 | \DesignPatterns\Behavioral\Iterator\BookList 8 | \DesignPatterns\Behavioral\Iterator\BookListIterator 9 | \DesignPatterns\Behavioral\Iterator\Book 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Fields 22 | Constants 23 | Constructors 24 | Methods 25 | 26 | private 27 | 28 | 29 | -------------------------------------------------------------------------------- /Behavioral/Iterator/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/Iterator/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/Mediator/Colleague.php: -------------------------------------------------------------------------------- 1 | mediator = $medium; 25 | } 26 | 27 | // for subclasses 28 | protected function getMediator() 29 | { 30 | return $this->mediator; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Mediator.php: -------------------------------------------------------------------------------- 1 | database = $db; 37 | $this->server = $srv; 38 | $this->client = $cl; 39 | } 40 | 41 | /** 42 | * make request 43 | */ 44 | public function makeRequest() 45 | { 46 | $this->server->process(); 47 | } 48 | 49 | /** 50 | * query db 51 | * @return mixed 52 | */ 53 | public function queryDb() 54 | { 55 | return $this->database->getData(); 56 | } 57 | 58 | /** 59 | * send response 60 | * 61 | * @param string $content 62 | */ 63 | public function sendResponse($content) 64 | { 65 | $this->client->output($content); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Behavioral/Mediator/MediatorInterface.php: -------------------------------------------------------------------------------- 1 | getMediator()->makeRequest(); 18 | } 19 | 20 | /** 21 | * output content 22 | * 23 | * @param string $content 24 | */ 25 | public function output($content) 26 | { 27 | echo $content; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Subsystem/Database.php: -------------------------------------------------------------------------------- 1 | getMediator()->queryDb(); 18 | $this->getMediator()->sendResponse("Hello $data"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Tests/MediatorTest.php: -------------------------------------------------------------------------------- 1 | client = new Client($media); 22 | $media->setColleague(new Database($media), $this->client, new Server($media)); 23 | } 24 | 25 | public function testOutputHelloWorld() 26 | { 27 | // testing if Hello World is output : 28 | $this->expectOutputString('Hello World'); 29 | // as you see, the 3 components Client, Server and Database are totally decoupled 30 | $this->client->request(); 31 | // Anyway, it remains complexity in the Mediator that's why the pattern 32 | // Observer is preferable in mnay situations. 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Behavioral/Mediator/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/Mediator/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/Memento/Caretaker.php: -------------------------------------------------------------------------------- 1 | setState("State1"); 17 | //Setting state to State2 18 | $originator->setState("State2"); 19 | //Saving State2 to Memento 20 | $savedStates[] = $originator->saveToMemento(); 21 | //Setting state to State3 22 | $originator->setState("State3"); 23 | 24 | // We can request multiple mementos, and choose which one to roll back to. 25 | // Saving State3 to Memento 26 | $savedStates[] = $originator->saveToMemento(); 27 | //Setting state to State4 28 | $originator->setState("State4"); 29 | 30 | $originator->restoreFromMemento($savedStates[1]); 31 | //State after restoring from Memento: State3 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Behavioral/Memento/Memento.php: -------------------------------------------------------------------------------- 1 | state = $stateToSave; 16 | } 17 | 18 | /** 19 | * @return mixed 20 | */ 21 | public function getState() 22 | { 23 | return $this->state; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Behavioral/Memento/Originator.php: -------------------------------------------------------------------------------- 1 | state = $state; 19 | } 20 | 21 | /** 22 | * @return Memento 23 | */ 24 | public function saveToMemento() 25 | { 26 | $state = is_object($this->state) ? clone $this->state : $this->state; 27 | 28 | return new Memento($state); 29 | } 30 | 31 | public function restoreFromMemento(Memento $memento) 32 | { 33 | $this->state = $memento->getState(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Behavioral/Memento/uml/Momento.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Behavioral\Memento\Caretaker 5 | 6 | \DesignPatterns\Behavioral\Memento\Caretaker 7 | \DesignPatterns\Behavioral\Memento\Originator 8 | \DesignPatterns\Behavioral\Memento\Memento 9 | 10 | 11 | 12 | 13 | 14 | 15 | Fields 16 | Constants 17 | Constructors 18 | Methods 19 | 20 | private 21 | 22 | 23 | -------------------------------------------------------------------------------- /Behavioral/Memento/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/Memento/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/NullObject/LoggerInterface.php: -------------------------------------------------------------------------------- 1 | logger = $log; 23 | } 24 | 25 | /** 26 | * do something ... 27 | */ 28 | public function doSomething() 29 | { 30 | // no more check "if (!is_null($this->logger))..." with the NullObject pattern 31 | $this->logger->log('We are in ' . __METHOD__); 32 | // something to do... 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Behavioral/NullObject/Tests/LoggerTest.php: -------------------------------------------------------------------------------- 1 | expectOutputString(null); // no output 21 | $service->doSomething(); 22 | } 23 | 24 | public function testStandardLogger() 25 | { 26 | $service = new Service(new PrintLogger()); 27 | $this->expectOutputString('We are in DesignPatterns\Behavioral\NullObject\Service::doSomething'); 28 | $service->doSomething(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Behavioral/NullObject/uml/NullObject.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Behavioral\NullObject\Service 5 | 6 | \DesignPatterns\Behavioral\NullObject\NullLogger 7 | \DesignPatterns\Behavioral\NullObject\PrintLogger 8 | \DesignPatterns\Behavioral\NullObject\LoggerInterface 9 | \DesignPatterns\Behavioral\NullObject\Service 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | Fields 30 | Constants 31 | Constructors 32 | Methods 33 | 34 | private 35 | 36 | 37 | -------------------------------------------------------------------------------- /Behavioral/NullObject/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/NullObject/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/Observer/README.rst: -------------------------------------------------------------------------------- 1 | `Observer`__ 2 | ============ 3 | 4 | Purpose 5 | ------- 6 | 7 | To implement a publish/subscribe behaviour to an object, whenever a 8 | "Subject" object changes it's state, the attached "Observers" will be 9 | notified. It is used to shorten the amount of coupled objects and uses 10 | loose coupling instead. 11 | 12 | Examples 13 | -------- 14 | 15 | - a message queue system is observed to show the progress of a job in a 16 | GUI 17 | 18 | Note 19 | ---- 20 | 21 | PHP already defines two interfaces that can help to implement this 22 | pattern: SplObserver and SplSubject. 23 | 24 | UML Diagram 25 | ----------- 26 | 27 | .. image:: uml/uml.png 28 | :alt: Alt Observer UML Diagram 29 | :align: center 30 | 31 | Code 32 | ---- 33 | 34 | You can also find these code on `GitHub`_ 35 | 36 | User.php 37 | 38 | .. literalinclude:: User.php 39 | :language: php 40 | :linenos: 41 | 42 | UserObserver.php 43 | 44 | .. literalinclude:: UserObserver.php 45 | :language: php 46 | :linenos: 47 | 48 | Test 49 | ---- 50 | 51 | Tests/ObserverTest.php 52 | 53 | .. literalinclude:: Tests/ObserverTest.php 54 | :language: php 55 | :linenos: 56 | 57 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Observer 58 | .. __: http://en.wikipedia.org/wiki/Observer_pattern -------------------------------------------------------------------------------- /Behavioral/Observer/UserObserver.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Behavioral\Observer\User 5 | 6 | \DesignPatterns\Behavioral\Observer\UserObserver 7 | \DesignPatterns\Behavioral\Observer\User 8 | \SplSubject 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Fields 21 | Constants 22 | Constructors 23 | Methods 24 | 25 | private 26 | 27 | 28 | -------------------------------------------------------------------------------- /Behavioral/Observer/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/Observer/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/README.md: -------------------------------------------------------------------------------- 1 | # Behavioral 2 | 3 | In software engineering, behavioral design patterns are design patterns that 4 | identify common communication patterns between objects and realize these 5 | patterns. By doing so, these patterns increase flexibility in carrying out this 6 | communication. 7 | 8 | * [ChainOfResponsibilities](ChainOfResponsibilities) [:notebook:](http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern) 9 | * [Command](Command) [:notebook:](http://en.wikipedia.org/wiki/Command_pattern) 10 | * [Iterator](Iterator) [:notebook:](http://en.wikipedia.org/wiki/Iterator_pattern) 11 | * [Mediator](Mediator) [:notebook:](http://en.wikipedia.org/wiki/Mediator_pattern) 12 | * [Memento](Behavioral/Memento) [:notebook:](http://en.wikipedia.org/wiki/Memento_pattern) 13 | * [NullObject](NullObject) [:notebook:](http://en.wikipedia.org/wiki/Null_Object_pattern) 14 | * [Observer](Observer) [:notebook:](http://en.wikipedia.org/wiki/Observer_pattern) 15 | * [Specification](Specification) [:notebook:](http://en.wikipedia.org/wiki/Specification_pattern) 16 | * [State](State) [:notebook:](http://en.wikipedia.org/wiki/State_pattern) 17 | * [Strategy](Strategy) [:notebook:](http://en.wikipedia.org/wiki/Strategy_pattern) 18 | * [TemplateMethod](TemplateMethod) [:notebook:](http://en.wikipedia.org/wiki/Template_method_pattern) 19 | * [Visitor](Visitor) [:notebook:](http://en.wikipedia.org/wiki/Visitor_pattern) 20 | -------------------------------------------------------------------------------- /Behavioral/README.rst: -------------------------------------------------------------------------------- 1 | `Behavioral`__ 2 | ============== 3 | 4 | In software engineering, behavioral design patterns are design patterns 5 | that identify common communication patterns between objects and realize 6 | these patterns. By doing so, these patterns increase flexibility in 7 | carrying out this communication. 8 | 9 | .. toctree:: 10 | :titlesonly: 11 | 12 | ChainOfResponsibilities/README 13 | Command/README 14 | Iterator/README 15 | Mediator/README 16 | Memento/README 17 | NullObject/README 18 | Observer/README 19 | Specification/README 20 | State/README 21 | Strategy/README 22 | TemplateMethod/README 23 | Visitor/README 24 | 25 | .. __: http://en.wikipedia.org/wiki/Behavioral_pattern -------------------------------------------------------------------------------- /Behavioral/Specification/AbstractSpecification.php: -------------------------------------------------------------------------------- 1 | left = $left; 22 | $this->right = $right; 23 | } 24 | 25 | /** 26 | * Returns the evaluation of both wrapped specifications as a logical OR 27 | * 28 | * @param Item $item 29 | * 30 | * @return bool 31 | */ 32 | public function isSatisfiedBy(Item $item) 33 | { 34 | return $this->left->isSatisfiedBy($item) || $this->right->isSatisfiedBy($item); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Behavioral/Specification/Item.php: -------------------------------------------------------------------------------- 1 | price = $price; 19 | } 20 | 21 | /** 22 | * Get the items price 23 | * 24 | * @return int 25 | */ 26 | public function getPrice() 27 | { 28 | return $this->price; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Behavioral/Specification/Not.php: -------------------------------------------------------------------------------- 1 | spec = $spec; 20 | } 21 | 22 | /** 23 | * Returns the negated result of the wrapped specification 24 | * 25 | * @param Item $item 26 | * 27 | * @return bool 28 | */ 29 | public function isSatisfiedBy(Item $item) 30 | { 31 | return !$this->spec->isSatisfiedBy($item); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Behavioral/Specification/Plus.php: -------------------------------------------------------------------------------- 1 | left = $left; 22 | $this->right = $right; 23 | } 24 | 25 | /** 26 | * Checks if the composite AND of specifications passes 27 | * 28 | * @param Item $item 29 | * 30 | * @return bool 31 | */ 32 | public function isSatisfiedBy(Item $item) 33 | { 34 | return $this->left->isSatisfiedBy($item) && $this->right->isSatisfiedBy($item); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Behavioral/Specification/PriceSpecification.php: -------------------------------------------------------------------------------- 1 | maxPrice = $maxPrice; 20 | } 21 | 22 | /** 23 | * Sets the optional minimum price 24 | * 25 | * @param int $minPrice 26 | */ 27 | public function setMinPrice($minPrice) 28 | { 29 | $this->minPrice = $minPrice; 30 | } 31 | 32 | /** 33 | * Checks if Item price falls between bounds 34 | * 35 | * @param Item $item 36 | * 37 | * @return bool 38 | */ 39 | public function isSatisfiedBy(Item $item) 40 | { 41 | if (!empty($this->maxPrice) && $item->getPrice() > $this->maxPrice) { 42 | return false; 43 | } 44 | if (!empty($this->minPrice) && $item->getPrice() < $this->minPrice) { 45 | return false; 46 | } 47 | 48 | return true; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Behavioral/Specification/SpecificationInterface.php: -------------------------------------------------------------------------------- 1 | order = $order; 26 | } 27 | 28 | /** 29 | * @return mixed 30 | */ 31 | public function shipOrder() 32 | { 33 | $this->order['status'] = 'shipping'; 34 | $this->order['updatedTime'] = time(); 35 | 36 | // Setting the new order status into database; 37 | return $this->updateOrder($this->order); 38 | } 39 | 40 | /** 41 | * @return mixed|void 42 | * @throws \Exception 43 | */ 44 | public function completeOrder() 45 | { 46 | //Can not complete the order which status is created, throw exception; 47 | throw new \Exception('Can not complete the order which status is created!'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Behavioral/State/OrderController.php: -------------------------------------------------------------------------------- 1 | shipOrder(); 18 | } catch (Exception $e) { 19 | //handle error! 20 | } 21 | // response to browser 22 | } 23 | 24 | /** 25 | * @param int $id 26 | */ 27 | public function completeAction($id) 28 | { 29 | $order = OrderFactory::getOrder($id); 30 | try { 31 | $order->completeOrder(); 32 | } catch (Exception $e) { 33 | //handle error! 34 | } 35 | // response to browser 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Behavioral/State/OrderFactory.php: -------------------------------------------------------------------------------- 1 | order = $order; 26 | } 27 | 28 | /** 29 | * @return mixed|void 30 | * @throws \Exception 31 | */ 32 | public function shipOrder() 33 | { 34 | //Can not ship the order which status is shipping, throw exception; 35 | throw new \Exception('Can not ship the order which status is shipping!'); 36 | } 37 | 38 | /** 39 | * @return mixed 40 | */ 41 | public function completeOrder() 42 | { 43 | $this->order['status'] = 'completed'; 44 | $this->order['updatedTime'] = time(); 45 | 46 | // Setting the new order status into database; 47 | return $this->updateOrder($this->order); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Behavioral/State/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/State/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/Strategy/ComparatorInterface.php: -------------------------------------------------------------------------------- 1 | elements = $elements; 26 | } 27 | 28 | /** 29 | * @return array 30 | */ 31 | public function sort() 32 | { 33 | if (!$this->comparator) { 34 | throw new \LogicException("Comparator is not set"); 35 | } 36 | 37 | $callback = array($this->comparator, 'compare'); 38 | uasort($this->elements, $callback); 39 | 40 | return $this->elements; 41 | } 42 | 43 | /** 44 | * @param ComparatorInterface $comparator 45 | * 46 | * @return void 47 | */ 48 | public function setComparator(ComparatorInterface $comparator) 49 | { 50 | $this->comparator = $comparator; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Behavioral/Strategy/README.rst: -------------------------------------------------------------------------------- 1 | `Strategy`__ 2 | ============ 3 | 4 | Terminology: 5 | ------------ 6 | 7 | - Context 8 | - Strategy 9 | - Concrete Strategy 10 | 11 | Purpose 12 | ------- 13 | 14 | To separate strategies and to enable fast switching between them. Also 15 | this pattern is a good alternative to inheritance (instead of having an 16 | abstract class that is extended). 17 | 18 | Examples 19 | -------- 20 | 21 | - sorting a list of objects, one strategy by date, the other by id 22 | - simplify unit testing: e.g. switching between file and in-memory 23 | storage 24 | 25 | UML Diagram 26 | ----------- 27 | 28 | .. image:: uml/uml.png 29 | :alt: Alt Strategy UML Diagram 30 | :align: center 31 | 32 | Code 33 | ---- 34 | 35 | You can also find these code on `GitHub`_ 36 | 37 | ObjectCollection.php 38 | 39 | .. literalinclude:: ObjectCollection.php 40 | :language: php 41 | :linenos: 42 | 43 | ComparatorInterface.php 44 | 45 | .. literalinclude:: ComparatorInterface.php 46 | :language: php 47 | :linenos: 48 | 49 | DateComparator.php 50 | 51 | .. literalinclude:: DateComparator.php 52 | :language: php 53 | :linenos: 54 | 55 | IdComparator.php 56 | 57 | .. literalinclude:: IdComparator.php 58 | :language: php 59 | :linenos: 60 | 61 | Test 62 | ---- 63 | 64 | Tests/StrategyTest.php 65 | 66 | .. literalinclude:: Tests/StrategyTest.php 67 | :language: php 68 | :linenos: 69 | 70 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Strategy 71 | .. __: http://en.wikipedia.org/wiki/Strategy_pattern -------------------------------------------------------------------------------- /Behavioral/Strategy/uml/Strategy.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Behavioral\Strategy\ComparatorInterface 5 | 6 | \DesignPatterns\Behavioral\Strategy\ObjectCollection 7 | \DesignPatterns\Behavioral\Strategy\DateComparator 8 | \DesignPatterns\Behavioral\Strategy\ComparatorInterface 9 | \DesignPatterns\Behavioral\Strategy\IdComparator 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | Fields 30 | Constants 31 | Constructors 32 | Methods 33 | 34 | private 35 | 36 | 37 | -------------------------------------------------------------------------------- /Behavioral/Strategy/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/Strategy/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/BeachJourney.php: -------------------------------------------------------------------------------- 1 | expectOutputRegex('#sun-bathing#'); 17 | $journey->takeATrip(); 18 | } 19 | 20 | public function testCity() 21 | { 22 | $journey = new TemplateMethod\CityJourney(); 23 | $this->expectOutputRegex('#drink#'); 24 | $journey->takeATrip(); 25 | } 26 | 27 | /** 28 | * How to test an abstract template method with PHPUnit 29 | */ 30 | public function testLasVegas() 31 | { 32 | $journey = $this->getMockForAbstractClass('DesignPatterns\Behavioral\TemplateMethod\Journey'); 33 | $journey->expects($this->once()) 34 | ->method('enjoyVacation') 35 | ->will($this->returnCallback(array($this, 'mockUpVacation'))); 36 | $this->expectOutputRegex('#Las Vegas#'); 37 | $journey->takeATrip(); 38 | } 39 | 40 | public function mockUpVacation() 41 | { 42 | echo "Fear and loathing in Las Vegas\n"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/uml/TemplateMethod.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Behavioral\TemplateMethod\BeachJourney 5 | 6 | \DesignPatterns\Behavioral\TemplateMethod\CityJourney 7 | \DesignPatterns\Behavioral\TemplateMethod\Journey 8 | \DesignPatterns\Behavioral\TemplateMethod\BeachJourney 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | Fields 29 | Constants 30 | Constructors 31 | Methods 32 | 33 | private 34 | 35 | 36 | -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/TemplateMethod/uml/uml.png -------------------------------------------------------------------------------- /Behavioral/Visitor/Group.php: -------------------------------------------------------------------------------- 1 | name = (string) $name; 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function getName() 27 | { 28 | return "Group: " . $this->name; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Behavioral/Visitor/README.rst: -------------------------------------------------------------------------------- 1 | `Visitor`__ 2 | =========== 3 | 4 | Purpose 5 | ------- 6 | 7 | The Visitor Pattern lets you outsource operations on objects to other 8 | objects. The main reason to do this is to keep a separation of concerns. 9 | But classes have to define a contract to allow visitors (the 10 | ``Role::accept`` method in the example). 11 | 12 | The contract is an abstract class but you can have also a clean 13 | interface. In that case, each Visitor has to choose itself which method 14 | to invoke on the visitor. 15 | 16 | UML Diagram 17 | ----------- 18 | 19 | .. image:: uml/uml.png 20 | :alt: Alt Visitor UML Diagram 21 | :align: center 22 | 23 | Code 24 | ---- 25 | 26 | You can also find these code on `GitHub`_ 27 | 28 | RoleVisitorInterface.php 29 | 30 | .. literalinclude:: RoleVisitorInterface.php 31 | :language: php 32 | :linenos: 33 | 34 | RolePrintVisitor.php 35 | 36 | .. literalinclude:: RolePrintVisitor.php 37 | :language: php 38 | :linenos: 39 | 40 | Role.php 41 | 42 | .. literalinclude:: Role.php 43 | :language: php 44 | :linenos: 45 | 46 | User.php 47 | 48 | .. literalinclude:: User.php 49 | :language: php 50 | :linenos: 51 | 52 | Group.php 53 | 54 | .. literalinclude:: Group.php 55 | :language: php 56 | :linenos: 57 | 58 | Test 59 | ---- 60 | 61 | Tests/VisitorTest.php 62 | 63 | .. literalinclude:: Tests/VisitorTest.php 64 | :language: php 65 | :linenos: 66 | 67 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Visitor 68 | .. __: http://en.wikipedia.org/wiki/Visitor_pattern -------------------------------------------------------------------------------- /Behavioral/Visitor/Role.php: -------------------------------------------------------------------------------- 1 | getName(); 18 | } 19 | 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function visitUser(User $role) 24 | { 25 | echo "Role: " . $role->getName(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Behavioral/Visitor/RoleVisitorInterface.php: -------------------------------------------------------------------------------- 1 | visitor = new Visitor\RolePrintVisitor(); 18 | } 19 | 20 | public function getRole() 21 | { 22 | return array( 23 | array(new Visitor\User("Dominik"), 'Role: User Dominik'), 24 | array(new Visitor\Group("Administrators"), 'Role: Group: Administrators') 25 | ); 26 | } 27 | 28 | /** 29 | * @dataProvider getRole 30 | */ 31 | public function testVisitSomeRole(Visitor\Role $role, $expect) 32 | { 33 | $this->expectOutputString($expect); 34 | $role->accept($this->visitor); 35 | } 36 | 37 | /** 38 | * @expectedException \InvalidArgumentException 39 | * @expectedExceptionMessage Mock 40 | */ 41 | public function testUnknownObject() 42 | { 43 | $mock = $this->getMockForAbstractClass('DesignPatterns\Behavioral\Visitor\Role'); 44 | $mock->accept($this->visitor); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Behavioral/Visitor/User.php: -------------------------------------------------------------------------------- 1 | name = (string) $name; 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getName() 29 | { 30 | return "User " . $this->name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Behavioral/Visitor/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Behavioral/Visitor/uml/uml.png -------------------------------------------------------------------------------- /Creational/AbstractFactory/AbstractFactory.php: -------------------------------------------------------------------------------- 1 | ', $this->path, $this->name); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/Html/Text.php: -------------------------------------------------------------------------------- 1 | ' . htmlspecialchars($this->text) . ''; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/HtmlFactory.php: -------------------------------------------------------------------------------- 1 | $this->name, 'path' => $this->path)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/Json/Text.php: -------------------------------------------------------------------------------- 1 | $this->text)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/JsonFactory.php: -------------------------------------------------------------------------------- 1 | name = (string) $name; 28 | $this->path = (string) $path; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/Tests/AbstractFactoryTest.php: -------------------------------------------------------------------------------- 1 | createText('Lorem Ipsum'), 33 | $factory->createPicture('/image.jpg', 'caption'), 34 | $factory->createText('footnotes') 35 | ); 36 | 37 | $this->assertContainsOnly('DesignPatterns\Creational\AbstractFactory\MediaInterface', $article); 38 | 39 | /* this is the time to look at the Builder pattern. This pattern 40 | * helps you to create complex object like that article above with 41 | * a given Abstract Factory 42 | */ 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/Text.php: -------------------------------------------------------------------------------- 1 | text = (string) $text; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Creational/AbstractFactory/uml/uml.png -------------------------------------------------------------------------------- /Creational/Builder/BikeBuilder.php: -------------------------------------------------------------------------------- 1 | bike->setPart('engine', new Parts\Engine()); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function addWheel() 34 | { 35 | $this->bike->setPart('forwardWheel', new Parts\Wheel()); 36 | $this->bike->setPart('rearWheel', new Parts\Wheel()); 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | public function createVehicle() 43 | { 44 | $this->bike = new Parts\Bike(); 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | public function getVehicle() 51 | { 52 | return $this->bike; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Creational/Builder/BuilderInterface.php: -------------------------------------------------------------------------------- 1 | car->setPart('rightdoor', new Parts\Door()); 21 | $this->car->setPart('leftDoor', new Parts\Door()); 22 | } 23 | 24 | /** 25 | * @return void 26 | */ 27 | public function addEngine() 28 | { 29 | $this->car->setPart('engine', new Parts\Engine()); 30 | } 31 | 32 | /** 33 | * @return void 34 | */ 35 | public function addWheel() 36 | { 37 | $this->car->setPart('wheelLF', new Parts\Wheel()); 38 | $this->car->setPart('wheelRF', new Parts\Wheel()); 39 | $this->car->setPart('wheelLR', new Parts\Wheel()); 40 | $this->car->setPart('wheelRR', new Parts\Wheel()); 41 | } 42 | 43 | /** 44 | * @return void 45 | */ 46 | public function createVehicle() 47 | { 48 | $this->car = new Parts\Car(); 49 | } 50 | 51 | /** 52 | * @return Parts\Car 53 | */ 54 | public function getVehicle() 55 | { 56 | return $this->car; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Creational/Builder/Director.php: -------------------------------------------------------------------------------- 1 | createVehicle(); 24 | $builder->addDoors(); 25 | $builder->addEngine(); 26 | $builder->addWheel(); 27 | 28 | return $builder->getVehicle(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Creational/Builder/Parts/Bike.php: -------------------------------------------------------------------------------- 1 | data[$key] = $value; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Creational/Builder/Parts/Wheel.php: -------------------------------------------------------------------------------- 1 | director = new Director(); 21 | } 22 | 23 | public function getBuilder() 24 | { 25 | return array( 26 | array(new CarBuilder()), 27 | array(new BikeBuilder()) 28 | ); 29 | } 30 | 31 | /** 32 | * Here we test the build process. Notice that the client don't know 33 | * anything about the concrete builder. 34 | * 35 | * @dataProvider getBuilder 36 | */ 37 | public function testBuild(BuilderInterface $builder) 38 | { 39 | $newVehicle = $this->director->build($builder); 40 | $this->assertInstanceOf('DesignPatterns\Creational\Builder\Parts\Vehicle', $newVehicle); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Creational/Builder/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Creational/Builder/uml/uml.png -------------------------------------------------------------------------------- /Creational/FactoryMethod/Bicycle.php: -------------------------------------------------------------------------------- 1 | color = $rgb; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Creational/FactoryMethod/FactoryMethod.php: -------------------------------------------------------------------------------- 1 | createVehicle($type); 35 | $obj->setColor("#f00"); 36 | 37 | return $obj; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Creational/FactoryMethod/Ferrari.php: -------------------------------------------------------------------------------- 1 | color = $rgb; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Creational/FactoryMethod/GermanFactory.php: -------------------------------------------------------------------------------- 1 | addTuningAMG(); 24 | 25 | return $obj; 26 | break; 27 | default: 28 | throw new \InvalidArgumentException("$type is not a valid vehicle"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Creational/FactoryMethod/ItalianFactory.php: -------------------------------------------------------------------------------- 1 | color = $rgb; 21 | } 22 | 23 | /** 24 | * although tuning by AMG is only offered for Mercedes Cars, 25 | * this is a valid coding example ... 26 | */ 27 | public function addTuningAMG() 28 | { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Creational/FactoryMethod/Tests/FactoryMethodTest.php: -------------------------------------------------------------------------------- 1 | type as $oneType) { 36 | $vehicle = $shop->create($oneType); 37 | $this->assertInstanceOf('DesignPatterns\Creational\FactoryMethod\VehicleInterface', $vehicle); 38 | } 39 | } 40 | 41 | /** 42 | * @dataProvider getShop 43 | * @expectedException \InvalidArgumentException 44 | * @expectedExceptionMessage spaceship is not a valid vehicle 45 | */ 46 | public function testUnknownType(FactoryMethod $shop) 47 | { 48 | $shop->create('spaceship'); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Creational/FactoryMethod/VehicleInterface.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Creational\Multiton\Multiton 5 | 6 | \DesignPatterns\Creational\Multiton\Multiton 7 | 8 | 9 | 10 | 11 | 12 | 13 | Fields 14 | Constants 15 | Constructors 16 | Methods 17 | 18 | private 19 | 20 | 21 | -------------------------------------------------------------------------------- /Creational/Multiton/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Creational/Multiton/uml/uml.png -------------------------------------------------------------------------------- /Creational/Pool/Pool.php: -------------------------------------------------------------------------------- 1 | class = $class; 14 | } 15 | 16 | public function get() 17 | { 18 | if (count($this->instances) > 0) { 19 | return array_pop($this->instances); 20 | } 21 | 22 | return new $this->class(); 23 | } 24 | 25 | public function dispose($instance) 26 | { 27 | $this->instances[] = $instance; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Creational/Pool/Processor.php: -------------------------------------------------------------------------------- 1 | pool = $pool; 16 | } 17 | 18 | public function process($image) 19 | { 20 | if ($this->processing++ < $this->maxProcesses) { 21 | $this->createWorker($image); 22 | } else { 23 | $this->pushToWaitingQueue($image); 24 | } 25 | } 26 | 27 | private function createWorker($image) 28 | { 29 | $worker = $this->pool->get(); 30 | $worker->run($image, array($this, 'processDone')); 31 | } 32 | 33 | public function processDone($worker) 34 | { 35 | $this->processing--; 36 | $this->pool->dispose($worker); 37 | 38 | if (count($this->waitingQueue) > 0) { 39 | $this->createWorker($this->popFromWaitingQueue()); 40 | } 41 | } 42 | 43 | private function pushToWaitingQueue($image) 44 | { 45 | $this->waitingQueue[] = $image; 46 | } 47 | 48 | private function popFromWaitingQueue() 49 | { 50 | return array_pop($this->waitingQueue); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Creational/Pool/Tests/PoolTest.php: -------------------------------------------------------------------------------- 1 | get(); 13 | 14 | $this->assertEquals(1, $worker->id); 15 | 16 | $worker->id = 5; 17 | $pool->dispose($worker); 18 | 19 | $this->assertEquals(5, $pool->get()->id); 20 | $this->assertEquals(1, $pool->get()->id); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Creational/Pool/Tests/TestWorker.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Creational\Pool\Processor 5 | 6 | \DesignPatterns\Creational\Pool\Pool 7 | \DesignPatterns\Creational\Pool\Processor 8 | \DesignPatterns\Creational\Pool\Worker 9 | 10 | 11 | 12 | 13 | 14 | 15 | Fields 16 | Constants 17 | Constructors 18 | Methods 19 | 20 | private 21 | 22 | 23 | -------------------------------------------------------------------------------- /Creational/Pool/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Creational/Pool/uml/uml.png -------------------------------------------------------------------------------- /Creational/Prototype/BarBookPrototype.php: -------------------------------------------------------------------------------- 1 | title; 32 | } 33 | 34 | /** 35 | * @param string $title 36 | */ 37 | public function setTitle($title) 38 | { 39 | $this->title = $title; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Creational/Prototype/FooBookPrototype.php: -------------------------------------------------------------------------------- 1 | setTitle('Foo Book No ' . $i); 12 | } 13 | 14 | for ($i = 0; $i < 5000; $i++) { 15 | $book = clone $barPrototype; 16 | $book->setTitle('Bar Book No ' . $i); 17 | } 18 | -------------------------------------------------------------------------------- /Creational/Prototype/uml/Prototype.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Creational\Prototype\BarBookPrototype 5 | 6 | \DesignPatterns\Creational\Prototype\BookPrototype 7 | \DesignPatterns\Creational\Prototype\FooBookPrototype 8 | \DesignPatterns\Creational\Prototype\BarBookPrototype 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | Fields 29 | Constants 30 | Constructors 31 | Methods 32 | 33 | private 34 | 35 | 36 | -------------------------------------------------------------------------------- /Creational/Prototype/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Creational/Prototype/uml/uml.png -------------------------------------------------------------------------------- /Creational/README.md: -------------------------------------------------------------------------------- 1 | # Creational 2 | 3 | In software engineering, creational design patterns are design patterns that 4 | deal with object creation mechanisms, trying to create objects in a manner 5 | suitable to the situation. The basic form of object creation could result in 6 | design problems or added complexity to the design. Creational design patterns 7 | solve this problem by somehow controlling this object creation. 8 | 9 | * [AbstractFactory](AbstractFactory) [:notebook:](http://en.wikipedia.org/wiki/Abstract_factory_pattern) 10 | * [Builder](Builder) [:notebook:](http://en.wikipedia.org/wiki/Builder_pattern) 11 | * [FactoryMethod](FactoryMethod) [:notebook:](http://en.wikipedia.org/wiki/Factory_method_pattern) 12 | * [Multiton](Multiton) (is considered an anti-pattern! :no_entry:) 13 | * [Pool](Pool) [:notebook:](http://en.wikipedia.org/wiki/Object_pool_pattern) 14 | * [Prototype](Prototype) [:notebook:](http://en.wikipedia.org/wiki/Prototype_pattern) 15 | * [SimpleFactory](SimpleFactory) 16 | * [Singleton](Singleton) [:notebook:](http://en.wikipedia.org/wiki/Singleton_pattern) (is considered an anti-pattern! :no_entry:) 17 | * [StaticFactory](StaticFactory) 18 | -------------------------------------------------------------------------------- /Creational/README.rst: -------------------------------------------------------------------------------- 1 | `Creational`__ 2 | ============== 3 | 4 | In software engineering, creational design patterns are design patterns 5 | that deal with object creation mechanisms, trying to create objects in a 6 | manner suitable to the situation. The basic form of object creation 7 | could result in design problems or added complexity to the design. 8 | Creational design patterns solve this problem by somehow controlling 9 | this object creation. 10 | 11 | .. toctree:: 12 | :titlesonly: 13 | 14 | AbstractFactory/README 15 | Builder/README 16 | FactoryMethod/README 17 | Multiton/README 18 | Pool/README 19 | Prototype/README 20 | SimpleFactory/README 21 | Singleton/README 22 | StaticFactory/README 23 | 24 | .. __: http://en.wikipedia.org/wiki/Creational_pattern 25 | -------------------------------------------------------------------------------- /Creational/SimpleFactory/Bicycle.php: -------------------------------------------------------------------------------- 1 | typeList = array( 22 | 'bicycle' => __NAMESPACE__ . '\Bicycle', 23 | 'other' => __NAMESPACE__ . '\Scooter' 24 | ); 25 | } 26 | 27 | /** 28 | * Creates a vehicle 29 | * 30 | * @param string $type a known type key 31 | * 32 | * @return VehicleInterface a new instance of VehicleInterface 33 | * @throws \InvalidArgumentException 34 | */ 35 | public function createVehicle($type) 36 | { 37 | if (!array_key_exists($type, $this->typeList)) { 38 | throw new \InvalidArgumentException("$type is not valid vehicle"); 39 | } 40 | $className = $this->typeList[$type]; 41 | 42 | return new $className(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Creational/SimpleFactory/README.rst: -------------------------------------------------------------------------------- 1 | Simple Factory 2 | ============== 3 | 4 | Purpose 5 | ------- 6 | 7 | ConcreteFactory is a simple factory pattern. 8 | 9 | It differs from the static factory because it is NOT static and as you 10 | know: static => global => evil! 11 | 12 | Therefore, you can have multiple factories, differently parametrized, 13 | you can subclass it and you can mock-up it. 14 | 15 | UML Diagram 16 | ----------- 17 | 18 | .. image:: uml/uml.png 19 | :alt: Alt SimpleFactory UML Diagram 20 | :align: center 21 | 22 | Code 23 | ---- 24 | 25 | You can also find these code on `GitHub`_ 26 | 27 | ConcreteFactory.php 28 | 29 | .. literalinclude:: ConcreteFactory.php 30 | :language: php 31 | :linenos: 32 | 33 | VehicleInterface.php 34 | 35 | .. literalinclude:: VehicleInterface.php 36 | :language: php 37 | :linenos: 38 | 39 | Bicycle.php 40 | 41 | .. literalinclude:: Bicycle.php 42 | :language: php 43 | :linenos: 44 | 45 | Scooter.php 46 | 47 | .. literalinclude:: Scooter.php 48 | :language: php 49 | :linenos: 50 | 51 | Test 52 | ---- 53 | 54 | Tests/SimpleFactoryTest.php 55 | 56 | .. literalinclude:: Tests/SimpleFactoryTest.php 57 | :language: php 58 | :linenos: 59 | 60 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Creational/SimpleFactory 61 | -------------------------------------------------------------------------------- /Creational/SimpleFactory/Scooter.php: -------------------------------------------------------------------------------- 1 | factory = new ConcreteFactory(); 18 | } 19 | 20 | public function getType() 21 | { 22 | return array( 23 | array('bicycle'), 24 | array('other') 25 | ); 26 | } 27 | 28 | /** 29 | * @dataProvider getType 30 | */ 31 | public function testCreation($type) 32 | { 33 | $obj = $this->factory->createVehicle($type); 34 | $this->assertInstanceOf('DesignPatterns\Creational\SimpleFactory\VehicleInterface', $obj); 35 | } 36 | 37 | /** 38 | * @expectedException \InvalidArgumentException 39 | */ 40 | public function testBadType() 41 | { 42 | $this->factory->createVehicle('car'); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Creational/SimpleFactory/VehicleInterface.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('DesignPatterns\Creational\Singleton\Singleton', $firstCall); 17 | $secondCall = Singleton::getInstance(); 18 | $this->assertSame($firstCall, $secondCall); 19 | } 20 | 21 | public function testNoConstructor() 22 | { 23 | $obj = Singleton::getInstance(); 24 | 25 | $refl = new \ReflectionObject($obj); 26 | $meth = $refl->getMethod('__construct'); 27 | $this->assertTrue($meth->isPrivate()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Creational/Singleton/uml/Singleton.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Creational\Singleton\Singleton 5 | 6 | \DesignPatterns\Creational\Singleton\Singleton 7 | 8 | 9 | 10 | 11 | 12 | 13 | Fields 14 | Constants 15 | Constructors 16 | Methods 17 | 18 | private 19 | 20 | 21 | -------------------------------------------------------------------------------- /Creational/Singleton/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Creational/Singleton/uml/uml.png -------------------------------------------------------------------------------- /Creational/StaticFactory/FormatNumber.php: -------------------------------------------------------------------------------- 1 | global => evil 7 | * Note2: Cannot be subclassed or mock-upped or have multiple different instances 8 | */ 9 | class StaticFactory 10 | { 11 | /** 12 | * the parametrized function to get create an instance 13 | * 14 | * @param string $type 15 | * 16 | * @static 17 | * 18 | * @throws \InvalidArgumentException 19 | * @return FormatterInterface 20 | */ 21 | public static function factory($type) 22 | { 23 | $className = __NAMESPACE__ . '\Format' . ucfirst($type); 24 | 25 | if (!class_exists($className)) { 26 | throw new \InvalidArgumentException('Missing format class.'); 27 | } 28 | 29 | return new $className(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Creational/StaticFactory/Tests/StaticFactoryTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('DesignPatterns\Creational\StaticFactory\FormatterInterface', $obj); 29 | } 30 | 31 | /** 32 | * @expectedException InvalidArgumentException 33 | */ 34 | public function testException() 35 | { 36 | StaticFactory::factory(""); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Creational/StaticFactory/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Creational/StaticFactory/uml/uml.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Dominik Liebler 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /More/Delegation/JuniorDeveloper.php: -------------------------------------------------------------------------------- 1 | slave = $junior; 22 | } 23 | 24 | /** 25 | * TeamLead drink coffee, junior work 26 | * @return mixed 27 | */ 28 | public function writeCode() 29 | { 30 | return $this->slave->writeBadCode(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /More/Delegation/Tests/DelegationTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($junior->writeBadCode(), $teamLead->writeCode()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /More/Delegation/Usage.php: -------------------------------------------------------------------------------- 1 | writeCode(); 10 | -------------------------------------------------------------------------------- /More/Delegation/uml/Delegation.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\More\Delegation\JuniorDeveloper 5 | 6 | \DesignPatterns\More\Delegation\JuniorDeveloper 7 | \DesignPatterns\More\Delegation\TeamLead 8 | 9 | 10 | 11 | 12 | 13 | 14 | Fields 15 | Constants 16 | Constructors 17 | Methods 18 | 19 | private 20 | 21 | 22 | -------------------------------------------------------------------------------- /More/Delegation/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/More/Delegation/uml/uml.png -------------------------------------------------------------------------------- /More/README.md: -------------------------------------------------------------------------------- 1 | # More 2 | 3 | * [Delegation](Delegation) [:notebook:](http://en.wikipedia.org/wiki/Delegation_pattern) 4 | * [ServiceLocator](ServiceLocator) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) 5 | * [Repository](Repository) 6 | -------------------------------------------------------------------------------- /More/README.rst: -------------------------------------------------------------------------------- 1 | More 2 | ==== 3 | 4 | .. toctree:: 5 | :titlesonly: 6 | 7 | Delegation/README 8 | ServiceLocator/README 9 | Repository/README 10 | -------------------------------------------------------------------------------- /More/Repository/MemoryStorage.php: -------------------------------------------------------------------------------- 1 | data = array(); 18 | $this->lastId = 0; 19 | } 20 | 21 | /** 22 | * {@inheritdoc} 23 | */ 24 | public function persist($data) 25 | { 26 | $this->data[++$this->lastId] = $data; 27 | return $this->lastId; 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function retrieve($id) 34 | { 35 | return isset($this->data[$id]) ? $this->data[$id] : null; 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | */ 41 | public function delete($id) 42 | { 43 | if (!isset($this->data[$id])) { 44 | return false; 45 | } 46 | 47 | $this->data[$id] = null; 48 | unset($this->data[$id]); 49 | 50 | return true; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /More/Repository/README.rst: -------------------------------------------------------------------------------- 1 | Repository 2 | ========== 3 | 4 | Purpose 5 | ------- 6 | 7 | Mediates between the domain and data mapping layers using a 8 | collection-like interface for accessing domain objects. Repository 9 | encapsulates the set of objects persisted in a data store and the 10 | operations performed over them, providing a more object-oriented view of 11 | the persistence layer. Repository also supports the objective of 12 | achieving a clean separation and one-way dependency between the domain 13 | and data mapping layers. 14 | 15 | Examples 16 | -------- 17 | 18 | - Doctrine 2 ORM: there is Repository that mediates between Entity and 19 | DBAL and contains methods to retrieve objects 20 | - Laravel Framework 21 | 22 | UML Diagram 23 | ----------- 24 | 25 | .. image:: uml/uml.png 26 | :alt: Alt Repository UML Diagram 27 | :align: center 28 | 29 | Code 30 | ---- 31 | 32 | You can also find these code on `GitHub`_ 33 | 34 | Post.php 35 | 36 | .. literalinclude:: Post.php 37 | :language: php 38 | :linenos: 39 | 40 | PostRepository.php 41 | 42 | .. literalinclude:: PostRepository.php 43 | :language: php 44 | :linenos: 45 | 46 | Storage.php 47 | 48 | .. literalinclude:: Storage.php 49 | :language: php 50 | :linenos: 51 | 52 | MemoryStorage.php 53 | 54 | .. literalinclude:: MemoryStorage.php 55 | :language: php 56 | :linenos: 57 | 58 | Test 59 | ---- 60 | 61 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/Repository 62 | -------------------------------------------------------------------------------- /More/Repository/Storage.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Repository\PostRepository 5 | 6 | \DesignPatterns\Repository\Storage 7 | \DesignPatterns\Repository\MemoryStorage 8 | \DesignPatterns\Repository\Post 9 | \DesignPatterns\Repository\PostRepository 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Fields 22 | Constants 23 | Constructors 24 | Methods 25 | 26 | private 27 | 28 | 29 | -------------------------------------------------------------------------------- /More/Repository/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/More/Repository/uml/uml.png -------------------------------------------------------------------------------- /More/ServiceLocator/DatabaseService.php: -------------------------------------------------------------------------------- 1 | eBook = $ebook; 26 | } 27 | 28 | /** 29 | * This class makes the proper translation from one interface to another 30 | */ 31 | public function open() 32 | { 33 | $this->eBook->pressStart(); 34 | } 35 | 36 | /** 37 | * turns pages 38 | */ 39 | public function turnPage() 40 | { 41 | $this->eBook->pressNext(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Structural/Adapter/EBookInterface.php: -------------------------------------------------------------------------------- 1 | open(); 39 | $book->turnPage(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Structural/Adapter/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Structural/Adapter/uml/uml.png -------------------------------------------------------------------------------- /Structural/Bridge/Assemble.php: -------------------------------------------------------------------------------- 1 | workShop1->work(); 20 | $this->workShop2->work(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Structural/Bridge/Motorcycle.php: -------------------------------------------------------------------------------- 1 | workShop1->work(); 20 | $this->workShop2->work(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Structural/Bridge/Produce.php: -------------------------------------------------------------------------------- 1 | `__ 15 | 16 | UML Diagram 17 | ----------- 18 | 19 | .. image:: uml/uml.png 20 | :alt: Alt Bridge UML Diagram 21 | :align: center 22 | 23 | Code 24 | ---- 25 | 26 | You can also find these code on `GitHub`_ 27 | 28 | Workshop.php 29 | 30 | .. literalinclude:: Workshop.php 31 | :language: php 32 | :linenos: 33 | 34 | Assemble.php 35 | 36 | .. literalinclude:: Assemble.php 37 | :language: php 38 | :linenos: 39 | 40 | Produce.php 41 | 42 | .. literalinclude:: Produce.php 43 | :language: php 44 | :linenos: 45 | 46 | Vehicle.php 47 | 48 | .. literalinclude:: Vehicle.php 49 | :language: php 50 | :linenos: 51 | 52 | Motorcycle.php 53 | 54 | .. literalinclude:: Motorcycle.php 55 | :language: php 56 | :linenos: 57 | 58 | Car.php 59 | 60 | .. literalinclude:: Car.php 61 | :language: php 62 | :linenos: 63 | 64 | Test 65 | ---- 66 | 67 | Tests/BridgeTest.php 68 | 69 | .. literalinclude:: Tests/BridgeTest.php 70 | :language: php 71 | :linenos: 72 | 73 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/Bridge 74 | .. __: http://en.wikipedia.org/wiki/Bridge_pattern 75 | -------------------------------------------------------------------------------- /Structural/Bridge/Tests/BridgeTest.php: -------------------------------------------------------------------------------- 1 | expectOutputString('Car Produced Assembled'); 17 | $vehicle->manufacture(); 18 | } 19 | 20 | public function testMotorcycle() 21 | { 22 | $vehicle = new Motorcycle(new Produce(), new Assemble()); 23 | $this->expectOutputString('Motorcycle Produced Assembled'); 24 | $vehicle->manufacture(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Structural/Bridge/Vehicle.php: -------------------------------------------------------------------------------- 1 | workShop1 = $workShop1; 17 | $this->workShop2 = $workShop2; 18 | } 19 | 20 | public function manufacture() 21 | { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Structural/Bridge/Workshop.php: -------------------------------------------------------------------------------- 1 | elements as $element) { 31 | $formCode .= $element->render($indent + 1) . PHP_EOL; 32 | } 33 | 34 | return $formCode; 35 | } 36 | 37 | /** 38 | * @param FormElement $element 39 | */ 40 | public function addElement(FormElement $element) 41 | { 42 | $this->elements[] = $element; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Structural/Composite/FormElement.php: -------------------------------------------------------------------------------- 1 | '; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Structural/Composite/README.rst: -------------------------------------------------------------------------------- 1 | `Composite`__ 2 | ============= 3 | 4 | Purpose 5 | ------- 6 | 7 | To treat a group of objects the same way as a single instance of the 8 | object. 9 | 10 | Examples 11 | -------- 12 | 13 | - a form class instance handles all its form elements like a single 14 | instance of the form, when ``render()`` is called, it subsequently 15 | runs through all its child elements and calls ``render()`` on them 16 | - ``Zend_Config``: a tree of configuration options, each one is a 17 | ``Zend_Config`` object itself 18 | 19 | UML Diagram 20 | ----------- 21 | 22 | .. image:: uml/uml.png 23 | :alt: Alt Composite UML Diagram 24 | :align: center 25 | 26 | Code 27 | ---- 28 | 29 | You can also find these code on `GitHub`_ 30 | 31 | FormElement.php 32 | 33 | .. literalinclude:: FormElement.php 34 | :language: php 35 | :linenos: 36 | 37 | Form.php 38 | 39 | .. literalinclude:: Form.php 40 | :language: php 41 | :linenos: 42 | 43 | InputElement.php 44 | 45 | .. literalinclude:: InputElement.php 46 | :language: php 47 | :linenos: 48 | 49 | TextElement.php 50 | 51 | .. literalinclude:: TextElement.php 52 | :language: php 53 | :linenos: 54 | 55 | Test 56 | ---- 57 | 58 | Tests/CompositeTest.php 59 | 60 | .. literalinclude:: Tests/CompositeTest.php 61 | :language: php 62 | :linenos: 63 | 64 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/Composite 65 | .. __: http://en.wikipedia.org/wiki/Composite_pattern 66 | -------------------------------------------------------------------------------- /Structural/Composite/Tests/CompositeTest.php: -------------------------------------------------------------------------------- 1 | addElement(new Composite\TextElement()); 17 | $form->addElement(new Composite\InputElement()); 18 | $embed = new Composite\Form(); 19 | $embed->addElement(new Composite\TextElement()); 20 | $embed->addElement(new Composite\InputElement()); 21 | $form->addElement($embed); // here we have a embedded form (like SF2 does) 22 | 23 | $this->assertRegExp('#^\s{4}#m', $form->render()); 24 | } 25 | 26 | /** 27 | * The all point of this pattern, a Composite must inherit from the node 28 | * if you want to builld trees 29 | */ 30 | public function testFormImplementsFormEelement() 31 | { 32 | $className = 'DesignPatterns\Structural\Composite\Form'; 33 | $abstractName = 'DesignPatterns\Structural\Composite\FormElement'; 34 | $this->assertTrue(is_subclass_of($className, $abstractName)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Structural/Composite/TextElement.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Structural\DataMapper\User 5 | 6 | \DesignPatterns\Structural\DataMapper\User 7 | \DesignPatterns\Structural\DataMapper\UserMapper 8 | 9 | 10 | 11 | 12 | 13 | \DesignPatterns\Structural\DataMapper\User 14 | 15 | 16 | Fields 17 | Constants 18 | Constructors 19 | Methods 20 | 21 | private 22 | 23 | 24 | -------------------------------------------------------------------------------- /Structural/DataMapper/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Structural/DataMapper/uml/uml.png -------------------------------------------------------------------------------- /Structural/Decorator/Decorator.php: -------------------------------------------------------------------------------- 1 | wrapped = $wrappable; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Structural/Decorator/README.rst: -------------------------------------------------------------------------------- 1 | `Decorator`__ 2 | ============= 3 | 4 | Purpose 5 | ------- 6 | 7 | To dynamically add new functionality to class instances. 8 | 9 | Examples 10 | -------- 11 | 12 | - Zend Framework: decorators for ``Zend_Form_Element`` instances 13 | - Web Service Layer: Decorators JSON and XML for a REST service (in 14 | this case, only one of these should be allowed of course) 15 | 16 | UML Diagram 17 | ----------- 18 | 19 | .. image:: uml/uml.png 20 | :alt: Alt Decorator UML Diagram 21 | :align: center 22 | 23 | Code 24 | ---- 25 | 26 | You can also find these code on `GitHub`_ 27 | 28 | RendererInterface.php 29 | 30 | .. literalinclude:: RendererInterface.php 31 | :language: php 32 | :linenos: 33 | 34 | Webservice.php 35 | 36 | .. literalinclude:: Webservice.php 37 | :language: php 38 | :linenos: 39 | 40 | Decorator.php 41 | 42 | .. literalinclude:: Decorator.php 43 | :language: php 44 | :linenos: 45 | 46 | RenderInXml.php 47 | 48 | .. literalinclude:: RenderInXml.php 49 | :language: php 50 | :linenos: 51 | 52 | RenderInJson.php 53 | 54 | .. literalinclude:: RenderInJson.php 55 | :language: php 56 | :linenos: 57 | 58 | Test 59 | ---- 60 | 61 | Tests/DecoratorTest.php 62 | 63 | .. literalinclude:: Tests/DecoratorTest.php 64 | :language: php 65 | :linenos: 66 | 67 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/Decorator 68 | .. __: http://en.wikipedia.org/wiki/Decorator_pattern 69 | -------------------------------------------------------------------------------- /Structural/Decorator/RenderInJson.php: -------------------------------------------------------------------------------- 1 | wrapped->renderData(); 18 | 19 | return json_encode($output); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Structural/Decorator/RenderInXml.php: -------------------------------------------------------------------------------- 1 | wrapped->renderData(); 18 | 19 | // do some fancy conversion to xml from array ... 20 | 21 | $doc = new \DOMDocument(); 22 | 23 | foreach ($output as $key => $val) { 24 | $doc->appendChild($doc->createElement($key, $val)); 25 | } 26 | 27 | return $doc->saveXML(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Structural/Decorator/RendererInterface.php: -------------------------------------------------------------------------------- 1 | data = $data; 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function renderData() 27 | { 28 | return $this->data; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Structural/Decorator/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Structural/Decorator/uml/uml.png -------------------------------------------------------------------------------- /Structural/DependencyInjection/AbstractConfig.php: -------------------------------------------------------------------------------- 1 | storage = $storage; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Structural/DependencyInjection/ArrayConfig.php: -------------------------------------------------------------------------------- 1 | storage[$key])) { 22 | return $this->storage[$key]; 23 | } 24 | return $default; 25 | } 26 | 27 | /** 28 | * Set parameter 29 | * 30 | * @param string|int $key 31 | * @param mixed $value 32 | */ 33 | public function set($key, $value) 34 | { 35 | $this->storage[$key] = $value; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Structural/DependencyInjection/Connection.php: -------------------------------------------------------------------------------- 1 | configuration = $config; 26 | } 27 | 28 | /** 29 | * connection using the injected config 30 | */ 31 | public function connect() 32 | { 33 | $host = $this->configuration->get('host'); 34 | // connection to host, authentication etc... 35 | 36 | //if connected 37 | $this->host = $host; 38 | } 39 | 40 | /* 41 | * Get currently connected host 42 | * 43 | * @return string 44 | */ 45 | public function getHost() 46 | { 47 | return $this->host; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Structural/DependencyInjection/Parameters.php: -------------------------------------------------------------------------------- 1 | source = include 'config.php'; 16 | $this->config = new ArrayConfig($this->source); 17 | } 18 | 19 | public function testDependencyInjection() 20 | { 21 | $connection = new Connection($this->config); 22 | $connection->connect(); 23 | $this->assertEquals($this->source['host'], $connection->getHost()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Structural/DependencyInjection/Tests/config.php: -------------------------------------------------------------------------------- 1 | 'github.com'); 4 | -------------------------------------------------------------------------------- /Structural/DependencyInjection/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Structural/DependencyInjection/uml/uml.png -------------------------------------------------------------------------------- /Structural/Facade/BiosInterface.php: -------------------------------------------------------------------------------- 1 | bios = $bios; 31 | $this->os = $os; 32 | } 33 | 34 | /** 35 | * turn on the system 36 | */ 37 | public function turnOn() 38 | { 39 | $this->bios->execute(); 40 | $this->bios->waitForKeyPress(); 41 | $this->bios->launch($this->os); 42 | } 43 | 44 | /** 45 | * turn off the system 46 | */ 47 | public function turnOff() 48 | { 49 | $this->os->halt(); 50 | $this->bios->powerDown(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Structural/Facade/OsInterface.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('DesignPatterns\Structural\Facade\BiosInterface') 17 | ->setMethods(array('launch', 'execute', 'waitForKeyPress')) 18 | ->disableAutoload() 19 | ->getMock(); 20 | $operatingSys = $this->getMockBuilder('DesignPatterns\Structural\Facade\OsInterface') 21 | ->setMethods(array('getName')) 22 | ->disableAutoload() 23 | ->getMock(); 24 | $bios->expects($this->once()) 25 | ->method('launch') 26 | ->with($operatingSys); 27 | $operatingSys 28 | ->expects($this->once()) 29 | ->method('getName') 30 | ->will($this->returnValue('Linux')); 31 | 32 | $facade = new Computer($bios, $operatingSys); 33 | return array(array($facade, $operatingSys)); 34 | } 35 | 36 | /** 37 | * @dataProvider getComputer 38 | */ 39 | public function testComputerOn(Computer $facade, OsInterface $os) 40 | { 41 | // interface is simpler : 42 | $facade->turnOn(); 43 | // but I can access to lower component 44 | $this->assertEquals('Linux', $os->getName()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Structural/Facade/uml/Facade.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Structural\Facade\BiosInterface 5 | 6 | \DesignPatterns\Structural\Facade\BiosInterface 7 | \DesignPatterns\Structural\Facade\OsInterface 8 | \DesignPatterns\Structural\Facade\Facade 9 | 10 | 11 | 12 | 13 | 14 | \DesignPatterns\Structural\Facade\BiosInterface 15 | 16 | 17 | Fields 18 | Constants 19 | Constructors 20 | Methods 21 | 22 | private 23 | 24 | 25 | -------------------------------------------------------------------------------- /Structural/Facade/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Structural/Facade/uml/uml.png -------------------------------------------------------------------------------- /Structural/FluentInterface/README.rst: -------------------------------------------------------------------------------- 1 | `Fluent Interface`__ 2 | ==================== 3 | 4 | Purpose 5 | ------- 6 | 7 | To write code that is easy readable just like sentences in a natural 8 | language (like English). 9 | 10 | Examples 11 | -------- 12 | 13 | - Doctrine2's QueryBuilder works something like that example class 14 | below 15 | - PHPUnit uses fluent interfaces to build mock objects 16 | - Yii Framework: CDbCommand and CActiveRecord use this pattern, too 17 | 18 | UML Diagram 19 | ----------- 20 | 21 | .. image:: uml/uml.png 22 | :alt: Alt FluentInterface UML Diagram 23 | :align: center 24 | 25 | Code 26 | ---- 27 | 28 | You can also find these code on `GitHub`_ 29 | 30 | Sql.php 31 | 32 | .. literalinclude:: Sql.php 33 | :language: php 34 | :linenos: 35 | 36 | Test 37 | ---- 38 | 39 | Tests/FluentInterfaceTest.php 40 | 41 | .. literalinclude:: Tests/FluentInterfaceTest.php 42 | :language: php 43 | :linenos: 44 | 45 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/FluentInterface 46 | .. __: http://en.wikipedia.org/wiki/Fluent_interface -------------------------------------------------------------------------------- /Structural/FluentInterface/Tests/FluentInterfaceTest.php: -------------------------------------------------------------------------------- 1 | select(array('foo', 'bar')) 17 | ->from('foobar', 'f') 18 | ->where('f.bar = ?') 19 | ->getQuery(); 20 | 21 | $this->assertEquals('SELECT foo,bar FROM foobar AS f WHERE f.bar = ?', $query); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Structural/FluentInterface/uml/FluentInterface.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Structural\FluentInterface\Sql 5 | 6 | \DesignPatterns\Structural\FluentInterface\Sql 7 | 8 | 9 | 10 | 11 | 12 | \DesignPatterns\Structural\FluentInterface\Sql 13 | 14 | 15 | Fields 16 | Constants 17 | Constructors 18 | Methods 19 | 20 | private 21 | 22 | 23 | -------------------------------------------------------------------------------- /Structural/FluentInterface/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Structural/FluentInterface/uml/uml.png -------------------------------------------------------------------------------- /Structural/Proxy/README.rst: -------------------------------------------------------------------------------- 1 | `Proxy`__ 2 | ========= 3 | 4 | Purpose 5 | ------- 6 | 7 | To interface to anything that is expensive or impossible to duplicate. 8 | 9 | Examples 10 | -------- 11 | 12 | - Doctrine2 uses proxies to implement framework magic (e.g. lazy 13 | initialization) in them, while the user still works with his own 14 | entity classes and will never use nor touch the proxies 15 | 16 | UML Diagram 17 | ----------- 18 | 19 | .. image:: uml/uml.png 20 | :alt: Alt Proxy UML Diagram 21 | :align: center 22 | 23 | Code 24 | ---- 25 | 26 | You can also find these code on `GitHub`_ 27 | 28 | Record.php 29 | 30 | .. literalinclude:: Record.php 31 | :language: php 32 | :linenos: 33 | 34 | RecordProxy.php 35 | 36 | .. literalinclude:: RecordProxy.php 37 | :language: php 38 | :linenos: 39 | 40 | Test 41 | ---- 42 | 43 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/Proxy 44 | .. __: http://en.wikipedia.org/wiki/Proxy_pattern 45 | -------------------------------------------------------------------------------- /Structural/Proxy/Record.php: -------------------------------------------------------------------------------- 1 | data = (array) $data; 21 | } 22 | 23 | /** 24 | * magic setter 25 | * 26 | * @param string $name 27 | * @param mixed $value 28 | * 29 | * @return void 30 | */ 31 | public function __set($name, $value) 32 | { 33 | $this->data[(string) $name] = $value; 34 | } 35 | 36 | /** 37 | * magic getter 38 | * 39 | * @param string $name 40 | * 41 | * @return mixed|null 42 | */ 43 | public function __get($name) 44 | { 45 | if (array_key_exists($name, $this->data)) { 46 | return $this->data[(string) $name]; 47 | } else { 48 | return null; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Structural/Proxy/RecordProxy.php: -------------------------------------------------------------------------------- 1 | isInitialized = true; 33 | $this->isDirty = true; 34 | } 35 | } 36 | 37 | /** 38 | * magic setter 39 | * 40 | * @param string $name 41 | * @param mixed $value 42 | * 43 | * @return void 44 | */ 45 | public function __set($name, $value) 46 | { 47 | $this->isDirty = true; 48 | parent::__set($name, $value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Structural/Proxy/uml/Proxy.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Structural\Proxy\Record 5 | 6 | \DesignPatterns\Structural\Proxy\Record 7 | \DesignPatterns\Structural\Proxy\RecordProxy 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | \DesignPatterns\Structural\Proxy\Record 19 | 20 | 21 | Fields 22 | Constants 23 | Constructors 24 | Methods 25 | 26 | private 27 | 28 | 29 | -------------------------------------------------------------------------------- /Structural/Proxy/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Structural/Proxy/uml/uml.png -------------------------------------------------------------------------------- /Structural/README.md: -------------------------------------------------------------------------------- 1 | # Structural 2 | 3 | In Software Engineering, Structural Design Patterns are Design Patterns that 4 | ease the design by identifying a simple way to realize relationships between 5 | entities. 6 | 7 | * [Adapter](Adapter) [:notebook:](http://en.wikipedia.org/wiki/Adapter_pattern) 8 | * [Bridge](Bridge) [:notebook:](http://en.wikipedia.org/wiki/Bridge_pattern) 9 | * [Composite](Composite) [:notebook:](http://en.wikipedia.org/wiki/Composite_pattern) 10 | * [DataMapper](DataMapper) [:notebook:](http://en.wikipedia.org/wiki/Data_mapper_pattern) 11 | * [Decorator](Decorator) [:notebook:](http://en.wikipedia.org/wiki/Decorator_pattern) 12 | * [DependencyInjection](DependencyInjection) [:notebook:](http://en.wikipedia.org/wiki/Dependency_injection) 13 | * [Facade](Facade) [:notebook:](http://en.wikipedia.org/wiki/Facade_pattern) 14 | * [FluentInterface](FluentInterface) [:notebook:](http://en.wikipedia.org/wiki/Fluent_interface) 15 | * [Proxy](Proxy) [:notebook:](http://en.wikipedia.org/wiki/Proxy_pattern) 16 | * [Registry](Registry) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) 17 | -------------------------------------------------------------------------------- /Structural/README.rst: -------------------------------------------------------------------------------- 1 | `Structural`__ 2 | ============== 3 | 4 | In Software Engineering, Structural Design Patterns are Design Patterns 5 | that ease the design by identifying a simple way to realize 6 | relationships between entities. 7 | 8 | .. toctree:: 9 | :titlesonly: 10 | 11 | Adapter/README 12 | Bridge/README 13 | Composite/README 14 | DataMapper/README 15 | Decorator/README 16 | DependencyInjection/README 17 | Facade/README 18 | FluentInterface/README 19 | Proxy/README 20 | Registry/README 21 | 22 | .. __: http://en.wikipedia.org/wiki/Structural_pattern -------------------------------------------------------------------------------- /Structural/Registry/README.rst: -------------------------------------------------------------------------------- 1 | `Registry`__ 2 | ============ 3 | 4 | Purpose 5 | ------- 6 | 7 | To implement a central storage for objects often used throughout the 8 | application, is typically implemented using an abstract class with only 9 | static methods (or using the Singleton pattern) 10 | 11 | Examples 12 | -------- 13 | 14 | - Zend Framework 1: ``Zend_Registry`` holds the application's logger 15 | object, front controller etc. 16 | - Yii Framework: ``CWebApplication`` holds all the application 17 | components, such as ``CWebUser``, ``CUrlManager``, etc. 18 | 19 | UML Diagram 20 | ----------- 21 | 22 | .. image:: uml/uml.png 23 | :alt: Alt Registry UML Diagram 24 | :align: center 25 | 26 | Code 27 | ---- 28 | 29 | You can also find these code on `GitHub`_ 30 | 31 | Registry.php 32 | 33 | .. literalinclude:: Registry.php 34 | :language: php 35 | :linenos: 36 | 37 | Test 38 | ---- 39 | 40 | Tests/RegistryTest.php 41 | 42 | .. literalinclude:: Tests/RegistryTest.php 43 | :language: php 44 | :linenos: 45 | 46 | .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/Registry 47 | .. __: http://en.wikipedia.org/wiki/Service_locator_pattern 48 | -------------------------------------------------------------------------------- /Structural/Registry/Registry.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('StdClass', $logger); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Structural/Registry/uml/Registry.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP 4 | \DesignPatterns\Structural\Registry\Registry 5 | 6 | \DesignPatterns\Structural\Registry\Registry 7 | 8 | 9 | 10 | 11 | 12 | \DesignPatterns\Structural\Registry\Registry 13 | 14 | 15 | Fields 16 | Constants 17 | Constructors 18 | Methods 19 | 20 | private 21 | 22 | 23 | -------------------------------------------------------------------------------- /Structural/Registry/uml/uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creocoder/DesignPatternsPHP/0285ba376074127fe5e5aa13f10e52ffc16b582f/Structural/Registry/uml/uml.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "domnikl/design-patterns-php", 3 | "description": "Sample code for several design patterns in PHP", 4 | "authors": [ 5 | { 6 | "name": "Dominik Liebler", 7 | "email": "liebler.dominik@googlemail.com" 8 | } 9 | ], 10 | "minimum-stability": "stable", 11 | "require-dev": { 12 | "phpunit/phpunit": "4.6.*", 13 | "squizlabs/php_codesniffer": "1.5.*" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "DesignPatterns\\": "" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /locale/ca/LC_MESSAGES/Behavioral/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Behavioral/README.rst:2 15 | msgid "`Behavioral`__" 16 | msgstr "" 17 | 18 | #: ../../Behavioral/README.rst:4 19 | msgid "" 20 | "In software engineering, behavioral design patterns are design patterns that" 21 | " identify common communication patterns between objects and realize these " 22 | "patterns. By doing so, these patterns increase flexibility in carrying out " 23 | "this communication." 24 | msgstr "" 25 | -------------------------------------------------------------------------------- /locale/ca/LC_MESSAGES/Creational/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Creational/README.rst:2 15 | msgid "`Creational`__" 16 | msgstr "" 17 | 18 | #: ../../Creational/README.rst:4 19 | msgid "" 20 | "In software engineering, creational design patterns are design patterns that" 21 | " deal with object creation mechanisms, trying to create objects in a manner " 22 | "suitable to the situation. The basic form of object creation could result in" 23 | " design problems or added complexity to the design. Creational design " 24 | "patterns solve this problem by somehow controlling this object creation." 25 | msgstr "" 26 | -------------------------------------------------------------------------------- /locale/ca/LC_MESSAGES/More/Delegation/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../More/Delegation/README.rst:2 15 | msgid "`Delegation`__" 16 | msgstr "" 17 | 18 | #: ../../More/Delegation/README.rst:5 19 | msgid "Purpose" 20 | msgstr "" 21 | 22 | #: ../../More/Delegation/README.rst:7 ../../More/Delegation/README.rst:12 23 | msgid "..." 24 | msgstr "" 25 | 26 | #: ../../More/Delegation/README.rst:10 27 | msgid "Examples" 28 | msgstr "" 29 | 30 | #: ../../More/Delegation/README.rst:15 31 | msgid "UML Diagram" 32 | msgstr "" 33 | 34 | #: ../../More/Delegation/README.rst:22 35 | msgid "Code" 36 | msgstr "" 37 | 38 | #: ../../More/Delegation/README.rst:24 39 | msgid "You can also find these code on `GitHub`_" 40 | msgstr "" 41 | 42 | #: ../../More/Delegation/README.rst:26 43 | msgid "Usage.php" 44 | msgstr "" 45 | 46 | #: ../../More/Delegation/README.rst:32 47 | msgid "TeamLead.php" 48 | msgstr "" 49 | 50 | #: ../../More/Delegation/README.rst:38 51 | msgid "JuniorDeveloper.php" 52 | msgstr "" 53 | 54 | #: ../../More/Delegation/README.rst:45 55 | msgid "Test" 56 | msgstr "" 57 | 58 | #: ../../More/Delegation/README.rst:47 59 | msgid "Tests/DelegationTest.php" 60 | msgstr "" 61 | -------------------------------------------------------------------------------- /locale/ca/LC_MESSAGES/More/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../More/README.rst:2 15 | msgid "More" 16 | msgstr "" 17 | -------------------------------------------------------------------------------- /locale/ca/LC_MESSAGES/Structural/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Structural/README.rst:2 15 | msgid "`Structural`__" 16 | msgstr "" 17 | 18 | #: ../../Structural/README.rst:4 19 | msgid "" 20 | "In Software Engineering, Structural Design Patterns are Design Patterns that" 21 | " ease the design by identifying a simple way to realize relationships " 22 | "between entities." 23 | msgstr "" 24 | -------------------------------------------------------------------------------- /locale/es/LC_MESSAGES/Behavioral/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Behavioral/README.rst:2 15 | msgid "`Behavioral`__" 16 | msgstr "" 17 | 18 | #: ../../Behavioral/README.rst:4 19 | msgid "" 20 | "In software engineering, behavioral design patterns are design patterns that" 21 | " identify common communication patterns between objects and realize these " 22 | "patterns. By doing so, these patterns increase flexibility in carrying out " 23 | "this communication." 24 | msgstr "" 25 | -------------------------------------------------------------------------------- /locale/es/LC_MESSAGES/Creational/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Creational/README.rst:2 15 | msgid "`Creational`__" 16 | msgstr "" 17 | 18 | #: ../../Creational/README.rst:4 19 | msgid "" 20 | "In software engineering, creational design patterns are design patterns that" 21 | " deal with object creation mechanisms, trying to create objects in a manner " 22 | "suitable to the situation. The basic form of object creation could result in" 23 | " design problems or added complexity to the design. Creational design " 24 | "patterns solve this problem by somehow controlling this object creation." 25 | msgstr "" 26 | -------------------------------------------------------------------------------- /locale/es/LC_MESSAGES/More/Delegation/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../More/Delegation/README.rst:2 15 | msgid "`Delegation`__" 16 | msgstr "" 17 | 18 | #: ../../More/Delegation/README.rst:5 19 | msgid "Purpose" 20 | msgstr "" 21 | 22 | #: ../../More/Delegation/README.rst:7 ../../More/Delegation/README.rst:12 23 | msgid "..." 24 | msgstr "" 25 | 26 | #: ../../More/Delegation/README.rst:10 27 | msgid "Examples" 28 | msgstr "" 29 | 30 | #: ../../More/Delegation/README.rst:15 31 | msgid "UML Diagram" 32 | msgstr "" 33 | 34 | #: ../../More/Delegation/README.rst:22 35 | msgid "Code" 36 | msgstr "" 37 | 38 | #: ../../More/Delegation/README.rst:24 39 | msgid "You can also find these code on `GitHub`_" 40 | msgstr "" 41 | 42 | #: ../../More/Delegation/README.rst:26 43 | msgid "Usage.php" 44 | msgstr "" 45 | 46 | #: ../../More/Delegation/README.rst:32 47 | msgid "TeamLead.php" 48 | msgstr "" 49 | 50 | #: ../../More/Delegation/README.rst:38 51 | msgid "JuniorDeveloper.php" 52 | msgstr "" 53 | 54 | #: ../../More/Delegation/README.rst:45 55 | msgid "Test" 56 | msgstr "" 57 | 58 | #: ../../More/Delegation/README.rst:47 59 | msgid "Tests/DelegationTest.php" 60 | msgstr "" 61 | -------------------------------------------------------------------------------- /locale/es/LC_MESSAGES/More/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../More/README.rst:2 15 | msgid "More" 16 | msgstr "" 17 | -------------------------------------------------------------------------------- /locale/es/LC_MESSAGES/Structural/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Structural/README.rst:2 15 | msgid "`Structural`__" 16 | msgstr "" 17 | 18 | #: ../../Structural/README.rst:4 19 | msgid "" 20 | "In Software Engineering, Structural Design Patterns are Design Patterns that" 21 | " ease the design by identifying a simple way to realize relationships " 22 | "between entities." 23 | msgstr "" 24 | -------------------------------------------------------------------------------- /locale/pt_BR/LC_MESSAGES/Behavioral/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Behavioral/README.rst:2 15 | msgid "`Behavioral`__" 16 | msgstr "" 17 | 18 | #: ../../Behavioral/README.rst:4 19 | msgid "" 20 | "In software engineering, behavioral design patterns are design patterns that" 21 | " identify common communication patterns between objects and realize these " 22 | "patterns. By doing so, these patterns increase flexibility in carrying out " 23 | "this communication." 24 | msgstr "" 25 | -------------------------------------------------------------------------------- /locale/pt_BR/LC_MESSAGES/Creational/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Creational/README.rst:2 15 | msgid "`Creational`__" 16 | msgstr "`Criacional`__" 17 | 18 | #: ../../Creational/README.rst:4 19 | msgid "" 20 | "In software engineering, creational design patterns are design patterns that" 21 | " deal with object creation mechanisms, trying to create objects in a manner " 22 | "suitable to the situation. The basic form of object creation could result in" 23 | " design problems or added complexity to the design. Creational design " 24 | "patterns solve this problem by somehow controlling this object creation." 25 | msgstr "" 26 | "Em engenharia de software, padrões de projeto do tipo criacional são padrões que" 27 | " trabalham com mecanismos de criação de objetos, criando objetos de maneira " 28 | "adequada às situações. A forma básica para criação de objetos pode resultar em" 29 | " problemas de design ou adicionar complexidade ao mesmo. Padrões de Criação " 30 | "resolvem este problema mantendo a criação do objeto sob controle." 31 | -------------------------------------------------------------------------------- /locale/pt_BR/LC_MESSAGES/More/Delegation/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../More/Delegation/README.rst:2 15 | msgid "`Delegation`__" 16 | msgstr "" 17 | 18 | #: ../../More/Delegation/README.rst:5 19 | msgid "Purpose" 20 | msgstr "" 21 | 22 | #: ../../More/Delegation/README.rst:7 ../../More/Delegation/README.rst:12 23 | msgid "..." 24 | msgstr "" 25 | 26 | #: ../../More/Delegation/README.rst:10 27 | msgid "Examples" 28 | msgstr "" 29 | 30 | #: ../../More/Delegation/README.rst:15 31 | msgid "UML Diagram" 32 | msgstr "Diagrama UML" 33 | 34 | #: ../../More/Delegation/README.rst:22 35 | msgid "Code" 36 | msgstr "" 37 | 38 | #: ../../More/Delegation/README.rst:24 39 | msgid "You can also find these code on `GitHub`_" 40 | msgstr "" 41 | 42 | #: ../../More/Delegation/README.rst:26 43 | msgid "Usage.php" 44 | msgstr "" 45 | 46 | #: ../../More/Delegation/README.rst:32 47 | msgid "TeamLead.php" 48 | msgstr "" 49 | 50 | #: ../../More/Delegation/README.rst:38 51 | msgid "JuniorDeveloper.php" 52 | msgstr "" 53 | 54 | #: ../../More/Delegation/README.rst:45 55 | msgid "Test" 56 | msgstr "" 57 | 58 | #: ../../More/Delegation/README.rst:47 59 | msgid "Tests/DelegationTest.php" 60 | msgstr "" 61 | -------------------------------------------------------------------------------- /locale/pt_BR/LC_MESSAGES/More/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../More/README.rst:2 15 | msgid "More" 16 | msgstr "Outros" 17 | -------------------------------------------------------------------------------- /locale/pt_BR/LC_MESSAGES/Structural/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Structural/README.rst:2 15 | msgid "`Structural`__" 16 | msgstr "" 17 | 18 | #: ../../Structural/README.rst:4 19 | msgid "" 20 | "In Software Engineering, Structural Design Patterns are Design Patterns that" 21 | " ease the design by identifying a simple way to realize relationships " 22 | "between entities." 23 | msgstr "" 24 | -------------------------------------------------------------------------------- /locale/ru/LC_MESSAGES/Behavioral/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: 2015-05-29 21:22+0300\n" 8 | "Last-Translator: Eugene Glotov \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "Language: ru\n" 13 | 14 | #: ../../Behavioral/README.rst:2 15 | msgid "`Behavioral`__" 16 | msgstr "`Поведенческие шаблоны проектирования `_ (`Behavioral`__)" 17 | 18 | #: ../../Behavioral/README.rst:4 19 | msgid "" 20 | "In software engineering, behavioral design patterns are design patterns that" 21 | " identify common communication patterns between objects and realize these " 22 | "patterns. By doing so, these patterns increase flexibility in carrying out " 23 | "this communication." 24 | msgstr "" 25 | "Поведенческие шаблоны проектирования определяют общие закономерности связей " 26 | "между объектами, реализующими данные паттерны. Следование этим шаблонам " 27 | "уменьшает связность системы и облегчает коммуникацию между объектами, что " 28 | "улучшает гибкость программного продукта." 29 | -------------------------------------------------------------------------------- /locale/ru/LC_MESSAGES/Creational/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: 2015-05-30 23:11+0300\n" 8 | "Last-Translator: Eugene Glotov \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "Language: ru\n" 13 | 14 | #: ../../Creational/README.rst:2 15 | msgid "`Creational`__" 16 | msgstr "Порождающие шаблоны проектирования (`Creational`__)" 17 | 18 | #: ../../Creational/README.rst:4 19 | msgid "" 20 | "In software engineering, creational design patterns are design patterns that" 21 | " deal with object creation mechanisms, trying to create objects in a manner " 22 | "suitable to the situation. The basic form of object creation could result in" 23 | " design problems or added complexity to the design. Creational design " 24 | "patterns solve this problem by somehow controlling this object creation." 25 | msgstr "" 26 | "В разработке программного обеспечения, Порождающие шаблоны проектирования – " 27 | "это паттерны, которые имеют дело с механизмами создания объекта и пытаются " 28 | "создать объекты в порядке, подходящем к ситуации. Обычная форма создания " 29 | "объекта может привести к проблемам проектирования или увеличивать сложность " 30 | "конструкции. Порождающие шаблоны проектирования решают эту проблему, " 31 | "определённым образом контролируя процесс создания объекта." 32 | -------------------------------------------------------------------------------- /locale/ru/LC_MESSAGES/More/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: Eugene Glotov \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "Language: ru\n" 13 | 14 | #: ../../More/README.rst:2 15 | msgid "More" 16 | msgstr "Дополнительно" 17 | -------------------------------------------------------------------------------- /locale/ru/LC_MESSAGES/Structural/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: 2015-05-30 23:27+0300\n" 8 | "Last-Translator: Eugene Glotov \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "Language: ru\n" 13 | 14 | #: ../../Structural/README.rst:2 15 | msgid "`Structural`__" 16 | msgstr "" 17 | "`Структурные шаблоны проектирования `_ (`Structural`__)" 19 | 20 | #: ../../Structural/README.rst:4 21 | msgid "" 22 | "In Software Engineering, Structural Design Patterns are Design Patterns that" 23 | " ease the design by identifying a simple way to realize relationships " 24 | "between entities." 25 | msgstr "" 26 | "При разработке программного обеспечения, Структурные шаблоны проектирования " 27 | "упрощают проектирование путем выявления простого способа реализовать " 28 | "отношения между субъектами." 29 | -------------------------------------------------------------------------------- /locale/zh_CN/LC_MESSAGES/Behavioral/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Behavioral/README.rst:2 15 | msgid "`Behavioral`__" 16 | msgstr "" 17 | 18 | #: ../../Behavioral/README.rst:4 19 | msgid "" 20 | "In software engineering, behavioral design patterns are design patterns that" 21 | " identify common communication patterns between objects and realize these " 22 | "patterns. By doing so, these patterns increase flexibility in carrying out " 23 | "this communication." 24 | msgstr "" 25 | -------------------------------------------------------------------------------- /locale/zh_CN/LC_MESSAGES/Creational/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Creational/README.rst:2 15 | msgid "`Creational`__" 16 | msgstr "`创建型设计模式`__" 17 | 18 | #: ../../Creational/README.rst:4 19 | msgid "" 20 | "In software engineering, creational design patterns are design patterns that" 21 | " deal with object creation mechanisms, trying to create objects in a manner " 22 | "suitable to the situation. The basic form of object creation could result in" 23 | " design problems or added complexity to the design. Creational design " 24 | "patterns solve this problem by somehow controlling this object creation." 25 | msgstr "" 26 | "在软件工程中,创建型设计模式承担着对象创建的职责,尝试创建" 27 | "适合程序上下文的对象,对象创建设计模式的产生是由于软件工程" 28 | "设计的问题,具体说是向设计中增加复杂度,创建型设计模式解决" 29 | "了程序设计中对象创建的问题。" 30 | -------------------------------------------------------------------------------- /locale/zh_CN/LC_MESSAGES/More/Delegation/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../More/Delegation/README.rst:2 15 | msgid "`Delegation`__" 16 | msgstr "" 17 | 18 | #: ../../More/Delegation/README.rst:5 19 | msgid "Purpose" 20 | msgstr "" 21 | 22 | #: ../../More/Delegation/README.rst:7 ../../More/Delegation/README.rst:12 23 | msgid "..." 24 | msgstr "" 25 | 26 | #: ../../More/Delegation/README.rst:10 27 | msgid "Examples" 28 | msgstr "" 29 | 30 | #: ../../More/Delegation/README.rst:15 31 | msgid "UML Diagram" 32 | msgstr "" 33 | 34 | #: ../../More/Delegation/README.rst:22 35 | msgid "Code" 36 | msgstr "" 37 | 38 | #: ../../More/Delegation/README.rst:24 39 | msgid "You can also find these code on `GitHub`_" 40 | msgstr "" 41 | 42 | #: ../../More/Delegation/README.rst:26 43 | msgid "Usage.php" 44 | msgstr "" 45 | 46 | #: ../../More/Delegation/README.rst:32 47 | msgid "TeamLead.php" 48 | msgstr "" 49 | 50 | #: ../../More/Delegation/README.rst:38 51 | msgid "JuniorDeveloper.php" 52 | msgstr "" 53 | 54 | #: ../../More/Delegation/README.rst:45 55 | msgid "Test" 56 | msgstr "" 57 | 58 | #: ../../More/Delegation/README.rst:47 59 | msgid "Tests/DelegationTest.php" 60 | msgstr "" 61 | -------------------------------------------------------------------------------- /locale/zh_CN/LC_MESSAGES/More/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../More/README.rst:2 15 | msgid "More" 16 | msgstr "" 17 | -------------------------------------------------------------------------------- /locale/zh_CN/LC_MESSAGES/Structural/README.po: -------------------------------------------------------------------------------- 1 | # 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: DesignPatternsPHP 1.0\n" 5 | "Report-Msgid-Bugs-To: \n" 6 | "POT-Creation-Date: 2015-05-29 12:18+0200\n" 7 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 8 | "Last-Translator: FULL NAME \n" 9 | "Language-Team: LANGUAGE \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | 14 | #: ../../Structural/README.rst:2 15 | msgid "`Structural`__" 16 | msgstr "`结构型设计模式`__" 17 | 18 | #: ../../Structural/README.rst:4 19 | msgid "" 20 | "In Software Engineering, Structural Design Patterns are Design Patterns that" 21 | " ease the design by identifying a simple way to realize relationships " 22 | "between entities." 23 | msgstr "" 24 | "在软件工程中,结构型设计模式集是用来抽象真实程序中的对象实体之间的关系,并使" 25 | "这种关系可被描述,概括和具体化。" -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Behavioral/*/Tests 7 | Creational/*/Tests 8 | More/*/Tests 9 | Structural/*/Tests 10 | 11 | 12 | 13 | 14 | ./vendor 15 | 16 | 17 | 18 | --------------------------------------------------------------------------------