The intent of the repository is to inspire developers to understand and use design patterns through various examples. Please consider adding example for any pattern that may help others understand the pattern well.
Please follow the guidelines in order to run this project.
- Clone the repo using
git clone https://github.com/basherr/PHP-Design-Patterns.git
- Run the following command inside the cloned folder:
composer install
- Make sure all the test cases passes by running
composer test
command - To serve the project, navigate inside
public/
folder and run the command:php -S localhost:8000
Checkout the routes.php for testing any specific pattern example.
If you find some implementation wrong or vague, please create an issue and let us help each other in the path for learning Design Patterns.
- Abstract Pattern
- Tv Manufacturer Example - Contributed by owner
- Builder Pattern
- Factroy Method Pattern
- Car Manufacturer - Contributed by owner
- Logger - Contributed by owner
- Pool Pattern
- StringReverse Worker - Contributed by owner
- Prototype Pattern
- AcmePrototype - Contributed by owner
- Static Factory Pattern
- Suppliers - Contributed by owner
- Adapter Pattern
- Human Adapter - Contributed by owner
- Operating Systems Adapter - Contributed by owner
- Bridge Pattern
- Flight Supplier Bridge - Contributed by owner
- Composite Pattern
- Composite Form - Contributed by owner
- Decorator Pattern
- Active Record - Contributed by owner
- Facade
- Quickbooks - Contributed by owner
- Proxy Pattern
- File Reader Proxy - Contributed by owner
- Registery Pattern
- Exam Registery - Contributed by owner
- Dependency Injection Pattern
- Mailer - Contributed by owner
- Chain Of Responsibility Pattern
- Handle Http Request - Contributed by owner
- Command Pattern
- API Scrapper - Contributed by owner
- Iterator Pattern
- Hotel Suppliers - Contributed by owner
- Observer Pattern
- User Signup Observer - Contributed by owner
Your contribution may have a very good impact on the community thus try sharing every possible example that you can either think of or had experienced in the past.
The repository is not based on any framework but rather inspired by No Framework
The code structure for the repository is as follows:
app
bootstraps
public
stubs
tests
The life cycle of the application is as follows:
public/index.php
serves as the entry point for the entire application which loadsboostrap/autoload.php
bootstrap/autoload.php
processesHTTP
request and forwards the route to the relevantController method
defined inbootstrap/routes.php
.
In order to contribute and add real world example for the related pattern, please follow the guidelines:
- Fork the repository
- Create a folder inside
app/Patterns/{Type e.g Creational, Behavioral or Structural}/{Pattern Name}/{Example Name}/your code
- Please create a READMe.md and include a UML diagram. Example README.md
- Add
unit tests
- Create
Application.php
with a method namedrender
to describe the usage. Example Application.php - Add a method in the relevant controller(e.g creational) and add a route in
bootstraps/routes.php
- Please run
composer test
and make sure all tests are passing - Create a PR against the master branch
Please feel free to contribute and create pull requests.
The only console command available for creating tests is:
php .\bootstraps\console_autoload.php MyAwesomeTestName
Please create an issue or join Discord for any discussion.
All of the codebases are MIT licensed unless otherwise specified.