Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/RefactoringGuru/design-patterns-php
Design Pattern Examples in PHP
https://github.com/RefactoringGuru/design-patterns-php
design-patterns php
Last synced: 2 months ago
JSON representation
Design Pattern Examples in PHP
- Host: GitHub
- URL: https://github.com/RefactoringGuru/design-patterns-php
- Owner: RefactoringGuru
- License: other
- Created: 2017-09-15T12:24:33.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-09-23T13:34:39.000Z (4 months ago)
- Last Synced: 2024-11-29T04:02:25.878Z (2 months ago)
- Topics: design-patterns, php
- Language: PHP
- Homepage: https://refactoring.guru/design-patterns/php
- Size: 1.06 MB
- Stars: 1,025
- Watchers: 55
- Forks: 156
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Design Patterns in PHP
This repository is part of the [Refactoring.Guru](https://refactoring.guru/design-patterns) project.
It contains PHP examples for all classic GoF design patterns.
Each pattern includes two examples:
- **Conceptual** examples show the internal structure of patterns, including detailed comments.
- **RealWorld** examples show how patterns can be used in real-world PHP applications.
## Requirements
These examples require PHP 7.3 and newer, although they can be easily replicated in older versions of PHP.
This version provides explicit argument and return type declarations, which help to understand better some patterns' features that are not very obvious in dynamically typed language.
All examples can be launched via the command line, using the PHP executable as follows:
```
php src/Path-to-example/index.php
```For the best experience, I recommend working with examples with these IDEs:
- [PhpStorm](https://www.jetbrains.com/phpstorm/)
- [Visual Studio Code](https://code.visualstudio.com/)## Roadmap
- [ ] Memento: RealLife
- [ ] State: RealLifeI'm out of decent ideas for real-world usages for these two in PHP apps. If you had used them in your project, feel free to suggest me an idea by posting an Issue.
## FAQ
#### 1. What is the _Client Code_?
_Client_ means _client of classes, defined as part of a pattern_, which is merely a caller of the given methods or a user of the given classes. In other words, it's the part of your application's code that uses the pattern's classes.
#### 2. I don't understand the roles you're referring to in RealWorld examples.
Take a look at the conceptual example first. There you'll find detailed descriptions of each class in a pattern, its role, and connection to other classes.
## Contributor's Guide
I appreciate any help, whether it's a simple fix of a typo or a whole new example. Just [make a fork](https://help.github.com/articles/fork-a-repo/), make your change and submit a [pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/).
Here's a style guide which might help you to keep your changes consistent with the rest of the project's code:
1. All code should match the [PSR2 coding style guide](https://www.php-fig.org/psr/psr-2/)
2. Try to hard-wrap the code at 80th's character. It helps to list the code on the website without scrollbars.
3. Examples should match following namespace convention: RefactoringGuru\\{pattern-name}\\{example-name}. For instance:
```php
## Credits
Authors: Alexander Shvets ([@neochief](https://github.com/neochief)) and Alexey Pyltsyn ([@lex111](https://github.com/lex111))