2013-09-04 10:11:18 +02:00
# DesignPatternsPHP
2011-08-30 12:34:45 +02:00
2019-12-15 20:08:59 +01:00
[](https://github.com/domnikl/DesignPatternsPHP/actions)
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
2020-10-31 19:43:33 -04:00
This is a collection of known design patterns and some sample codes on how to implement them in PHP. Every pattern has a small list of examples.
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
```
2020-10-31 19:43:33 -04:00
## Using Docker (optional)
2018-07-08 17:33:49 +02:00
2019-02-25 22:15:04 +01:00
You can optionally build and browse the documentation using [Docker for Mac, Windows or Linux ](https://docs.docker.com/compose/install/ ).
2019-02-22 21:13:29 +05:00
2018-07-08 17:33:49 +02:00
Just run:
2018-07-08 17:38:04 +02:00
```bash
2019-09-12 22:00:27 +02:00
$ docker-compose up --build
2018-07-08 17:33:49 +02:00
```
2020-10-05 11:22:04 +02:00
Go to [http://localhost:8080/ ](http://localhost:8080/ ) to read the generated documentation.
2019-02-25 22:15:04 +01:00
2020-10-06 13:45:36 +02:00
If you want to localize your documentation you can pass the locale as an argument to the docker build:
```bash
$ docker-compose build --build-arg language=de
$ docker-compose up
```
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 )
* [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 )
2020-04-17 13:36:04 +02:00
* [Singleton ](Creational/Singleton ) [:notebook: ](http://en.wikipedia.org/wiki/Singleton_pattern )
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
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 )
2019-08-30 07:56:18 +02:00
* [Repository ](More/Repository )
2020-04-17 13:36:04 +02:00
* [ServiceLocator ](More/ServiceLocator ) [:notebook: ](http://en.wikipedia.org/wiki/Service_locator_pattern )
2020-10-04 15:39:02 +02:00
2020-10-31 19:43:33 -04:00
## Localization & Supported Languages
2020-10-04 15:39:02 +02:00
2020-10-13 23:17:41 +02:00
| Code | Language | Documentation |
| ------------------|-------------|------|
| ca | Catalan | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/ca/latest/README.html ) |
2020-10-31 19:47:10 -04:00
| zh_CN | Chinese | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/zh_CN/latest/README.html ) |
| nl | Dutch | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/nl/latest/README.html ) |
| en | English | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/en/latest/README.html ) |
2020-10-13 23:17:41 +02:00
| de | German | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/de/latest/README.html ) |
| ja | Japanese | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/ja/latest/README.html ) |
| pl | Polish | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/pl/latest/README.html ) |
2020-10-04 15:39:02 +02:00
| pt_BR | Portuguese-Brazil | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/pt_BR/latest/README.html ) |
2020-10-13 23:17:41 +02:00
| ru | Russian | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/ru/latest/README.html ) |
2020-10-31 19:47:10 -04:00
| es | Spanish | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/es/latest/README.html ) |
| es_MX | Spanish-Mexican | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/es_MX/latest/README.html ) |
2020-10-13 23:17:41 +02:00
| tr | Turkish | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/tr/latest/README.html ) |
2021-03-13 12:00:47 +01:00
| bg | Bulgarian | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/bg/latest/README.html ) |
| fr | French | [Docs :notebook: ](https://designpatternsphp.readthedocs.io/fr/latest/README.html ) |