2013-09-04 10:11:18 +02:00
# DesignPatternsPHP
2011-08-30 12:34:45 +02:00
2015-07-14 10:54:40 -04:00
[](https://travis-ci.org/domnikl/DesignPatternsPHP)
2018-06-14 23:02:18 +02:00
[](https://readthedocs.org/projects/designpatternsphp/?badge=latest)
2017-12-27 08:26:12 +01:00
[](https://paypal.me/DominikLiebler)
2013-05-16 09:19:02 +02:00
2015-04-05 03:29:00 +02:00
[Read the Docs of DesignPatternsPHP ](http://designpatternsphp.readthedocs.org )
or [Download as PDF/Epub ](https://readthedocs.org/projects/designpatternsphp/downloads/ )
2015-04-02 00:57:18 +02:00
2013-09-03 14:35:47 +02:00
This is a collection of known design patterns and some sample code how to implement them in PHP. Every pattern has a small list of examples (most of them from Zend Framework, Symfony2 or Doctrine2 as I'm most familiar with this software).
2011-08-30 12:34:45 +02:00
2011-08-30 14:49:09 +02:00
I think the problem with patterns is that often people do know them but don't know when to apply which.
2011-08-30 12:34:45 +02:00
2015-06-01 01:20:57 +03:00
## Installation
You should look at and run the tests to see what happens in the example.
To do this, you should install dependencies with `Composer` first:
```bash
$ composer install
```
Read more about how to install and use `Composer` on your local machine [here ](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx ).
2018-07-08 17:33:49 +02:00
To run the tests use `phpunit` :
2018-02-13 07:47:11 +01:00
```bash
2018-07-08 17:33:49 +02:00
$ ./vendor/bin/phpunit
2018-02-13 07:47:11 +01:00
```
2018-07-08 17:33:49 +02:00
## using Docker (optional)
2019-02-22 21:13:29 +05:00
You can optionally run tests using [Docker for Mac, Windows or Linux ](https://docs.docker.com/compose/install/ ).
2018-07-08 17:33:49 +02:00
Just run:
2018-07-08 17:38:04 +02:00
```bash
$ docker-compose up
2018-07-08 17:33:49 +02:00
```
2018-07-08 17:38:04 +02:00
To only install the dependencies, use `docker-compose` like this:
2015-08-15 12:21:01 +01:00
```bash
2018-07-08 17:38:04 +02:00
$ docker-compose run composer install
2015-08-15 12:21:01 +01:00
```
2013-09-04 10:11:18 +02:00
## Patterns
2014-03-09 13:25:33 -03:00
The patterns can be structured in roughly three different categories. Please click on the [:notebook: ](http://en.wikipedia.org/wiki/Software_design_pattern ) for a full explanation of the pattern on Wikipedia.
2013-09-03 14:35:47 +02:00
2014-04-16 14:51:11 -03:00
### [Creational](Creational)
* [AbstractFactory ](Creational/AbstractFactory ) [:notebook: ](http://en.wikipedia.org/wiki/Abstract_factory_pattern )
* [Builder ](Creational/Builder ) [:notebook: ](http://en.wikipedia.org/wiki/Builder_pattern )
* [FactoryMethod ](Creational/FactoryMethod ) [:notebook: ](http://en.wikipedia.org/wiki/Factory_method_pattern )
2014-05-02 12:33:44 -03:00
* [Multiton ](Creational/Multiton ) (is considered an anti-pattern! :no_entry:)
2014-04-16 14:51:11 -03:00
* [Pool ](Creational/Pool ) [:notebook: ](http://en.wikipedia.org/wiki/Object_pool_pattern )
2014-05-02 12:33:44 -03:00
* [Prototype ](Creational/Prototype ) [:notebook: ](http://en.wikipedia.org/wiki/Prototype_pattern )
* [SimpleFactory ](Creational/SimpleFactory )
2014-04-16 14:51:11 -03:00
* [Singleton ](Creational/Singleton ) [:notebook: ](http://en.wikipedia.org/wiki/Singleton_pattern ) (is considered an anti-pattern! :no_entry:)
2014-05-02 12:33:44 -03:00
* [StaticFactory ](Creational/StaticFactory )
2014-04-16 14:51:11 -03:00
### [Structural](Structural)
* [Adapter ](Structural/Adapter ) [:notebook: ](http://en.wikipedia.org/wiki/Adapter_pattern )
2014-05-02 12:33:44 -03:00
* [Bridge ](Structural/Bridge ) [:notebook: ](http://en.wikipedia.org/wiki/Bridge_pattern )
2014-04-16 14:51:11 -03:00
* [Composite ](Structural/Composite ) [:notebook: ](http://en.wikipedia.org/wiki/Composite_pattern )
* [DataMapper ](Structural/DataMapper ) [:notebook: ](http://en.wikipedia.org/wiki/Data_mapper_pattern )
* [Decorator ](Structural/Decorator ) [:notebook: ](http://en.wikipedia.org/wiki/Decorator_pattern )
* [DependencyInjection ](Structural/DependencyInjection ) [:notebook: ](http://en.wikipedia.org/wiki/Dependency_injection )
* [Facade ](Structural/Facade ) [:notebook: ](http://en.wikipedia.org/wiki/Facade_pattern )
* [FluentInterface ](Structural/FluentInterface ) [:notebook: ](http://en.wikipedia.org/wiki/Fluent_interface )
2016-06-04 01:16:55 +02:00
* [Flyweight ](Structural/Flyweight ) [:notebook: ](https://en.wikipedia.org/wiki/Flyweight_pattern )
2014-04-16 14:51:11 -03:00
* [Proxy ](Structural/Proxy ) [:notebook: ](http://en.wikipedia.org/wiki/Proxy_pattern )
* [Registry ](Structural/Registry ) [:notebook: ](http://en.wikipedia.org/wiki/Service_locator_pattern )
### [Behavioral](Behavioral)
* [ChainOfResponsibilities ](Behavioral/ChainOfResponsibilities ) [:notebook: ](http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern )
* [Command ](Behavioral/Command ) [:notebook: ](http://en.wikipedia.org/wiki/Command_pattern )
* [Iterator ](Behavioral/Iterator ) [:notebook: ](http://en.wikipedia.org/wiki/Iterator_pattern )
* [Mediator ](Behavioral/Mediator ) [:notebook: ](http://en.wikipedia.org/wiki/Mediator_pattern )
2014-06-09 09:43:06 +01:00
* [Memento ](Behavioral/Memento ) [:notebook: ](http://en.wikipedia.org/wiki/Memento_pattern )
2014-04-16 14:51:11 -03:00
* [NullObject ](Behavioral/NullObject ) [:notebook: ](http://en.wikipedia.org/wiki/Null_Object_pattern )
* [Observer ](Behavioral/Observer ) [:notebook: ](http://en.wikipedia.org/wiki/Observer_pattern )
* [Specification ](Behavioral/Specification ) [:notebook: ](http://en.wikipedia.org/wiki/Specification_pattern )
* [State ](Behavioral/State ) [:notebook: ](http://en.wikipedia.org/wiki/State_pattern )
* [Strategy ](Behavioral/Strategy ) [:notebook: ](http://en.wikipedia.org/wiki/Strategy_pattern )
* [TemplateMethod ](Behavioral/TemplateMethod ) [:notebook: ](http://en.wikipedia.org/wiki/Template_method_pattern )
* [Visitor ](Behavioral/Visitor ) [:notebook: ](http://en.wikipedia.org/wiki/Visitor_pattern )
### [More](More)
2018-06-14 21:14:53 +02:00
2016-11-29 10:47:13 +01:00
* [ServiceLocator ](More/ServiceLocator ) [:notebook: ](http://en.wikipedia.org/wiki/Service_locator_pattern ) (is considered an anti-pattern! :no_entry:)
2014-06-06 09:26:13 +02:00
* [Repository ](More/Repository )
2015-10-19 22:04:57 -02:00
* [EAV ](More/EAV ) [:notebook: ](https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model )
2014-03-02 22:16:59 +04:00
2013-09-04 10:11:18 +02:00
## Contribute
2016-09-23 10:55:22 +02:00
If you encounter any bugs or missing translations, please feel free to fork and send a pull request with your changes.
2014-01-08 20:40:20 +01:00
To establish a consistent code quality, please check your code using [PHP_CodeSniffer ](https://github.com/squizlabs/PHP_CodeSniffer ) against [PSR2 standard ](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md ) using `./vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor .` .
2013-09-04 10:11:18 +02:00