PHPackages                             domnikl/design-patterns-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. domnikl/design-patterns-php

AbandonedLibrary[Testing &amp; Quality](/categories/testing)

domnikl/design-patterns-php
===========================

Sample code for several design patterns in PHP

20.9k1.2k4.5kPHPCI failing

Since Sep 1Pushed 1y ago1.2k watchersCompare

[ Source](https://github.com/domnikl/DesignPatternsPHP)[ Packagist](https://packagist.org/packages/domnikl/design-patterns-php)[ RSS](/packages/domnikl-design-patterns-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

DesignPatternsPHP
=================

[](#designpatternsphp)

[![Build Status](https://github.com/DesignPatternsPHP/DesignPatternsPHP/workflows/CI/badge.svg?branch=main)](https://github.com/DesignPatternsPHP/DesignPatternsPHP/actions)[![Documentation Status](https://camo.githubusercontent.com/96327a9a2165b37d99505607a1a92a7a84234c8f631f5a555fe88cba276746b2/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f64657369676e7061747465726e737068702f62616467652f3f76657273696f6e3d6c6174657374)](https://designpatternsphp.readthedocs.io/?badge=latest)

[Read the Docs of DesignPatternsPHP](http://designpatternsphp.readthedocs.org)or [Download as PDF/Epub](https://readthedocs.org/projects/designpatternsphp/downloads/)

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.

I think the problem with patterns is that often people do know them but don't know when to apply which. Remember that each pattern has its own trade-offs. And you need to pay attention more to why you're choosing a certain pattern than to how to implement it.

Installation
------------

[](#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:

```
$ 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).

To run the tests use `phpunit`:

```
$ ./vendor/bin/phpunit
```

Using Docker (optional)
-----------------------

[](#using-docker-optional)

You can optionally build and browse the documentation using [Docker for Mac, Windows or Linux](https://docs.docker.com/compose/install/).

Just run:

```
$ docker-compose up --build
```

Go to  to read the generated documentation.

If you want to localize your documentation you can pass the locale as an argument to the docker build:

```
$ docker-compose build --build-arg language=de
$ docker-compose up
```

Patterns
--------

[](#patterns)

The patterns can be structured in roughly three different categories. Please click on the [📓](http://en.wikipedia.org/wiki/Software_design_pattern) for a full explanation of the pattern on Wikipedia.

### [Creational](Creational)

[](#creational)

- [AbstractFactory](Creational/AbstractFactory) [📓](http://en.wikipedia.org/wiki/Abstract_factory_pattern)
- [Builder](Creational/Builder) [📓](http://en.wikipedia.org/wiki/Builder_pattern)
- [FactoryMethod](Creational/FactoryMethod) [📓](http://en.wikipedia.org/wiki/Factory_method_pattern)
- [Pool](Creational/Pool) [📓](http://en.wikipedia.org/wiki/Object_pool_pattern)
- [Prototype](Creational/Prototype) [📓](http://en.wikipedia.org/wiki/Prototype_pattern)
- [SimpleFactory](Creational/SimpleFactory)
- [Singleton](Creational/Singleton) [📓](http://en.wikipedia.org/wiki/Singleton_pattern)
- [StaticFactory](Creational/StaticFactory)

### [Structural](Structural)

[](#structural)

- [Adapter](Structural/Adapter) [📓](http://en.wikipedia.org/wiki/Adapter_pattern)
- [Bridge](Structural/Bridge) [📓](http://en.wikipedia.org/wiki/Bridge_pattern)
- [Composite](Structural/Composite) [📓](http://en.wikipedia.org/wiki/Composite_pattern)
- [DataMapper](Structural/DataMapper) [📓](http://en.wikipedia.org/wiki/Data_mapper_pattern)
- [Decorator](Structural/Decorator) [📓](http://en.wikipedia.org/wiki/Decorator_pattern)
- [DependencyInjection](Structural/DependencyInjection) [📓](http://en.wikipedia.org/wiki/Dependency_injection)
- [Facade](Structural/Facade) [📓](http://en.wikipedia.org/wiki/Facade_pattern)
- [FluentInterface](Structural/FluentInterface) [📓](http://en.wikipedia.org/wiki/Fluent_interface)
- [Flyweight](Structural/Flyweight) [📓](https://en.wikipedia.org/wiki/Flyweight_pattern)
- [Proxy](Structural/Proxy) [📓](http://en.wikipedia.org/wiki/Proxy_pattern)
- [Registry](Structural/Registry) [📓](http://en.wikipedia.org/wiki/Service_locator_pattern)

### [Behavioral](Behavioral)

[](#behavioral)

- [ChainOfResponsibilities](Behavioral/ChainOfResponsibilities) [📓](http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern)
- [Command](Behavioral/Command) [📓](http://en.wikipedia.org/wiki/Command_pattern)
- [Interpreter](Behavioral/Interpreter) [📓](https://en.wikipedia.org/wiki/Interpreter_pattern)
- [Iterator](Behavioral/Iterator) [📓](http://en.wikipedia.org/wiki/Iterator_pattern)
- [Mediator](Behavioral/Mediator) [📓](http://en.wikipedia.org/wiki/Mediator_pattern)
- [Memento](Behavioral/Memento) [📓](http://en.wikipedia.org/wiki/Memento_pattern)
- [NullObject](Behavioral/NullObject) [📓](http://en.wikipedia.org/wiki/Null_Object_pattern)
- [Observer](Behavioral/Observer) [📓](http://en.wikipedia.org/wiki/Observer_pattern)
- [Specification](Behavioral/Specification) [📓](http://en.wikipedia.org/wiki/Specification_pattern)
- [State](Behavioral/State) [📓](http://en.wikipedia.org/wiki/State_pattern)
- [Strategy](Behavioral/Strategy) [📓](http://en.wikipedia.org/wiki/Strategy_pattern)
- [TemplateMethod](Behavioral/TemplateMethod) [📓](http://en.wikipedia.org/wiki/Template_method_pattern)
- [Visitor](Behavioral/Visitor) [📓](http://en.wikipedia.org/wiki/Visitor_pattern)

### [More](More)

[](#more)

- [EAV](More/EAV) [📓](https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model)
- [Repository](More/Repository)
- [ServiceLocator](More/ServiceLocator) [📓](http://en.wikipedia.org/wiki/Service_locator_pattern)

Localization &amp; Supported Languages
--------------------------------------

[](#localization--supported-languages)

The following languages are currently available. However not all are actively supported. The current policy is: if there are no native-speaking maintainers we cannot support the given language. We will still leave the translation as is but we will not update it as the base (English) changes. The table below list which language version is considered "supported" and who maintains it.

We're sorry. We would love to maintain them but it is not possible for us. So if you would like to take care of one or more languages - contact us.

CodeLanguageDocumentationActively Supported?MaintainerenEnglish[Docs 📓](https://designpatternsphp.readthedocs.io/en/latest/)YES--deGerman[Docs 📓](https://designpatternsphp.readthedocs.io/de/latest/)NO-caCatalan[Docs 📓](https://designpatternsphp.readthedocs.io/ca/latest/)NO-zh\_CNChinese[Docs 📓](https://designpatternsphp.readthedocs.io/zh_CN/latest/)NO-nlDutch[Docs 📓](https://designpatternsphp.readthedocs.io/nl/latest/)NO-bgBulgarian[Docs 📓](https://designpatternsphp.readthedocs.io/bg/latest/)YES--jaJapanese[Docs 📓](https://designpatternsphp.readthedocs.io/ja/latest/)NO-plPolish[Docs 📓](https://designpatternsphp.readthedocs.io/pl/latest/)NO-pt\_BRPortuguese-Brazil[Docs 📓](https://designpatternsphp.readthedocs.io/pt_BR/latest/)NO-ruRussian[Docs 📓](https://designpatternsphp.readthedocs.io/ru/latest/)NO-esSpanish[Docs 📓](https://designpatternsphp.readthedocs.io/es/latest/)NO-es\_MXSpanish-Mexican[Docs 📓](https://designpatternsphp.readthedocs.io/es_MX/latest/)NO-trTurkish[Docs 📓](https://designpatternsphp.readthedocs.io/tr/latest/)NO-frFrench[Docs 📓](https://designpatternsphp.readthedocs.io/fr/latest/)NO-itItalian[Docs 📓](https://designpatternsphp.readthedocs.io/it/latest/)NO-ukUkrainian[Docs 📓](https://designpatternsphp.readthedocs.io/uk/latest/)NO-

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community45

Growing community involvement

Maturity36

Early-stage or recently created project

 Bus Factor4

4 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6560b14fb17af0baf63782cef1c8e64adf91b047673306888e94f7bcc5f264e7?d=identicon)[jean-pasqualini](/maintainers/jean-pasqualini)

---

Top Contributors

[![domnikl](https://avatars.githubusercontent.com/u/603116?v=4)](https://github.com/domnikl "domnikl (221 commits)")[![piotrgradzinski](https://avatars.githubusercontent.com/u/1607439?v=4)](https://github.com/piotrgradzinski "piotrgradzinski (58 commits)")[![PabloGarciaComBR](https://avatars.githubusercontent.com/u/6075361?v=4)](https://github.com/PabloGarciaComBR "PabloGarciaComBR (42 commits)")[![guokan-shang](https://avatars.githubusercontent.com/u/1543951?v=4)](https://github.com/guokan-shang "guokan-shang (37 commits)")[![BorislavSabev](https://avatars.githubusercontent.com/u/1708306?v=4)](https://github.com/BorislavSabev "BorislavSabev (26 commits)")[![ns-roxer](https://avatars.githubusercontent.com/u/4972235?v=4)](https://github.com/ns-roxer "ns-roxer (21 commits)")[![leonampd](https://avatars.githubusercontent.com/u/1620107?v=4)](https://github.com/leonampd "leonampd (19 commits)")[![tonicospinelli](https://avatars.githubusercontent.com/u/966337?v=4)](https://github.com/tonicospinelli "tonicospinelli (19 commits)")[![bocharsky-bw](https://avatars.githubusercontent.com/u/3317635?v=4)](https://github.com/bocharsky-bw "bocharsky-bw (17 commits)")[![autoload](https://avatars.githubusercontent.com/u/5227198?v=4)](https://github.com/autoload "autoload (16 commits)")[![jtwebb](https://avatars.githubusercontent.com/u/1922539?v=4)](https://github.com/jtwebb "jtwebb (16 commits)")[![axelitus](https://avatars.githubusercontent.com/u/732441?v=4)](https://github.com/axelitus "axelitus (16 commits)")[![tanden](https://avatars.githubusercontent.com/u/4111626?v=4)](https://github.com/tanden "tanden (13 commits)")[![a1812](https://avatars.githubusercontent.com/u/42714329?v=4)](https://github.com/a1812 "a1812 (10 commits)")[![eddiejaoude](https://avatars.githubusercontent.com/u/624760?v=4)](https://github.com/eddiejaoude "eddiejaoude (9 commits)")[![Trismegiste](https://avatars.githubusercontent.com/u/1260026?v=4)](https://github.com/Trismegiste "Trismegiste (9 commits)")[![aspirantzhang](https://avatars.githubusercontent.com/u/24559988?v=4)](https://github.com/aspirantzhang "aspirantzhang (9 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (9 commits)")[![Hyunk3l](https://avatars.githubusercontent.com/u/754861?v=4)](https://github.com/Hyunk3l "Hyunk3l (9 commits)")[![jdhmtl](https://avatars.githubusercontent.com/u/3738327?v=4)](https://github.com/jdhmtl "jdhmtl (7 commits)")

---

Tags

code-examplesdesign-patterndesign-patternsdesignpatternsphpmodern-phpoopphpphp8phpunit

### Embed Badge

![Health badge](/badges/domnikl-design-patterns-php/health.svg)

```
[![Health](https://phpackages.com/badges/domnikl-design-patterns-php/health.svg)](https://phpackages.com/packages/domnikl-design-patterns-php)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
