{"id":15026953,"url":"https://github.com/gabrielanhaia/php-design-patterns","last_synced_at":"2025-04-09T09:08:40.706Z","repository":{"id":38446253,"uuid":"353466393","full_name":"gabrielanhaia/php-design-patterns","owner":"gabrielanhaia","description":"Learn how to implement the most important Design Patterns into your PHP application. This project uses PHP 8+. it has examples for each Pattern and an Article explaining how to use them step by step, their advantages, and disadvantages.","archived":false,"fork":false,"pushed_at":"2023-08-21T18:18:47.000Z","size":260,"stargazers_count":299,"open_issues_count":0,"forks_count":34,"subscribers_count":25,"default_branch":"main","last_synced_at":"2025-04-02T07:09:36.036Z","etag":null,"topics":["design-patterns","php","php8"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabrielanhaia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-31T19:22:18.000Z","updated_at":"2025-03-26T20:24:05.000Z","dependencies_parsed_at":"2024-12-24T18:11:15.845Z","dependency_job_id":"343dea00-642c-4528-b948-21b721061d7f","html_url":"https://github.com/gabrielanhaia/php-design-patterns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielanhaia%2Fphp-design-patterns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielanhaia%2Fphp-design-patterns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielanhaia%2Fphp-design-patterns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielanhaia%2Fphp-design-patterns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabrielanhaia","download_url":"https://codeload.github.com/gabrielanhaia/php-design-patterns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008630,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["design-patterns","php","php8"],"created_at":"2024-09-24T20:05:28.153Z","updated_at":"2025-04-09T09:08:40.690Z","avatar_url":"https://github.com/gabrielanhaia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./logo.png\" alt=\"Logo - PHP 8.1 Design Patterns\"  width=\"80%\" height=\"80%\"\u003e\n\n![Licence](https://img.shields.io/badge/licence-MIT-blue)\n![Package Stars](https://img.shields.io/badge/stars-%E2%98%85%E2%98%85%E2%98%85%E2%98%85%E2%98%85-yellow)\n[![Build Status](https://travis-ci.com/gabrielanhaia/php-circuit-breaker.svg?branch=master)](https://travis-ci.com/gabrielanhaia/php-circuit-breaker)\n![Code Coverage](https://img.shields.io/badge/coverage-100%25-green)\n\nEvery week a new Pattern + Article on www.medium.com/@anhaia.gabriel and www.medium.com/devwarlocks\n\n# PHP 8.2+ - Design Patterns\n\nThis repository was created to show the implementation of various Design Patterns using PHP 8.2. There is no\ndependency on a framework, and the examples are the most real as possible based on my own experiences solving real-life\nproblems. Applying the design pattern and its concept in any PHP project will be effortless once you learn the design\npattern and its concept.\n\n### Classification/Type\n\n| Type                                                               | General Article                                                                                                           | Diagrams                                                                                                    |\n|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|\n| ![Creational](https://img.shields.io/badge/Creational-light_green) | [LEARN HERE 📖](https://medium.com/devwarlocks/comparing-creational-design-patterns-making-the-right-choice-428cc351e926) | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Creational.md) |\n| ![Structural](https://img.shields.io/badge/Structural-8A2BE2)      | SOON                                                                                                                      | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Structural.md)                                                                                                        |\n| ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | SOON                                                                                                                      | SOON                                                                                                        |\n\n## Patterns implemented + Article\n\n| #  | 📖 Pattern              | Classification~Type                                                | Code Example / Implementation                                                              | ✍️ Article / Post 📚                                                                                    | Diagram                                                                                                  |                                                                             \n|----|-------------------------|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|                                                          \n| 1  | Abstract Factory        | ![Creational](https://img.shields.io/badge/Creational-light_green) | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/AbstractFactory) | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Creational.md#abstract-factory) |\n| 2  | Builder                 | ![Creational](https://img.shields.io/badge/Creational-light_green) | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Builder)         | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Creational.md#builder)          |                                                                                                \n| 3  | Factory Method          | ![Creational](https://img.shields.io/badge/Creational-light_green) | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/FactoryMethod)   | [LEARN HERE 📖](https://medium.com/devwarlocks/factory-method-pattern-php-design-patterns-3d1df7707c29) | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Creational.md#factory-method)   |\n| 4  | Prototype               | ![Creational](https://img.shields.io/badge/Creational-light_green) | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Prototype)       | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Creational.md#prototype)        |                                                                                                \n| 5  | Singleton               | ![Creational](https://img.shields.io/badge/Creational-light_green) | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Singleton)       | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Creational.md#singleton)        |                                                                                                \n| 6  | Object Pool             | ![Creational](https://img.shields.io/badge/Creational-light_green) | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/ObjectPool)                                                                                       | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Creational.md#object-pool)      |\n| 7  | Adapter                 | ![Structural](https://img.shields.io/badge/Structural-8A2BE2)      | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Adapter)         | [LEARN HERE 📖 ](https://medium.com/mestredev/adapter-php-8-75e00034ae48)                               | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Structural.md#adapter)                                                                                                       |                           \n| 8  | Composite               | ![Structural](https://img.shields.io/badge/Structural-8A2BE2)      | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Composite)       | [LEARN HERE 📖](https://medium.com/devwarlocks/composite-php-desing-patterns-dd01b1d010f7)              | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Structural.md#composite)                                                                                                      |                                                                                               \n| 9  | Bridge                  | ![Structural](https://img.shields.io/badge/Structural-8A2BE2)      | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Bridge)          | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Structural.md#bridge)                                                                                                      |\n| 10 | Facade                  | ![Structural](https://img.shields.io/badge/Structural-8A2BE2)      | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Facade)          | [LEARN HERE 📖 ](https://medium.com/mestredev/facade-php-8-design-patterns-40b1ef8566b5)                | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Structural.md#facade)                                                                                                      |           \n| 11 | Decorator               | ![Structural](https://img.shields.io/badge/Structural-8A2BE2)      | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Decorator)       | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Structural.md#decorator)                                                                                                      |\n| 12 | Flyweight               | ![Structural](https://img.shields.io/badge/Structural-8A2BE2)      | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Flyweight)       | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Structural.md#flyweight)                                                                                                      |\n| 13 | Proxy                   | ![Structural](https://img.shields.io/badge/Structural-8A2BE2)      | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Proxy)           | SOON                                                                                                    | [HERE](https://github.com/gabrielanhaia/php-design-patterns/blob/main/docs/diagrams/Structural.md#proxy)                                                                                                      |                                                                                                \n| 14 | Template Method         | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/TemplateMethod)  | [LEARN HERE 📖 ](https://medium.com/mestredev/template-method-php-8-a357f3665a4b)                       | SOON                                                                                                     |                    \n| 15 | Strategy                | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Strategy)        | [LEARN HERE 📖 ](https://medium.com/mestredev/strategy-in-php-8-design-patterns-2044e5ef54ed)           | SOON                                                                                                     |       \n| 16 | Iterator                | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Iterator)        | SOON                                                                                                    | SOON                                                                                                     |\n| 17 | Memento                 | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Memento)         | SOON                                                                                                    | SOON                                                                                                     |\n| 18 | Money                   | ![X](https://img.shields.io/badge/X-grey)                          | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Money)           | [LEARN HERE 📖](https://medium.com/devwarlocks/money-pattern-with-symfony-framework-55eff713b3d5)       | SOON                                                                                                     |\n| 19 | Null Object             | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/NullObject)      | SOON                                                                                                    | SOON                                                                                                     |                                                                                                \n| 20 | Observer                | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Observer)        | [LEARN HERE 📖](https://medium.com/devwarlocks/observer-php-design-patterns-a4367b137324)               | SOON                                                                                                     |                                                                                               \n| 21 | State                   | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/State)           | SOON                                                                                                    | SOON                                                                                                     |                                                                                                \n| 22 | Command                 | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Command)         | SOON                                                                                                    | SOON                                                                                                     |\n| 23 | Chain of Responsibility | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/ChainOfResponsibility)                                                                                       | SOON                                                                                                    | SOON                                                                                                     |\n| 24 | Interpreter             | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Interpreter)     | SOON                                                                                                    | SOON                                                                                                     |\n| 25 | Mediator                | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Mediator)        | SOON                                                                                                    | SOON                                                                                                     |\n| 26 | Visitor                 | ![Behavioral](https://img.shields.io/badge/Behavioral-red)         | [HERE](https://github.com/gabrielanhaia/php-design-patterns/tree/main/src/Visitor)         | [LEARN HERE 📖](https://medium.com/devwarlocks/visitor-php-design-patterns-289224470ebd)                | SOON                                                                                                     |\n\n## Dependencies\n\n- [Docker](https://www.docker.com)\n\n## Running the project\n\nI strongly recommend that you follow the articles (links above) and run them with Docker. It will be much easier, and\nyou\nneed to install Docker on your computer, independent of the OS you are using. With a few commands, you will run/test all\nthe Design Patterns implemented throughout the course.\n\n#### 1. Build the container:\n\n```bash \ndocker build -t design-patterns .\n``` \n\nor if you prefer\n\n```bash\nmake build\n```\n\n#### 2. Run the following commands to test the design patterns:\n\n```bash\nmake help\n``` \n\nand then you will see the list of commands\n\n#### 3. You need to run the command with the pattern you want to test, for example:\n\n```bash\nmake strategy\n```\n\n#### 4. In case you want to see a short description of the pattern, you can run the `make PATTERN_NAME-help`, for example:\n\n```bash\nmake strategy-help\n```\n\nWith that, you should see a one-line description of the pattern.\n\n## Additional Information\n\n- If you take a look at the examples in the blog or inside the folders `/src/{$pattern_name}/` you will notice that\n  almost\n  All the examples contain a folder called `components`; those folders are the files/classes used to demonstrate how to\n  use each pattern. Never consider what is in there as part of the pattern! They are not examples to be followed in your\n  applications.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielanhaia%2Fphp-design-patterns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrielanhaia%2Fphp-design-patterns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielanhaia%2Fphp-design-patterns/lists"}