Read the Docs of DesignPatternsPHP or Download as PDF/Epub
こちらの資料では知られたデザインパターンといくつかのサンプルコードを、PHP ではどのように実装するのかを記載します。
This is a collection of known design patterns and some sample code how to implement them in PHP. Every pattern has a small list of examples (most of them from Zend Framework, Symfony2 or Doctrine2 as I'm most familiar with this software).
デザインパータンについては知っていても、アプリケーションの中でどのように適用すればいいのかがよくわかっていないという課題があるように感じます。
I think the problem with patterns is that often people do know them but don't know when to apply which.
サンプルコードで何が起きているかを確認するためには実際にテストコードを実行して確認すべきでしょう。
そのために、composerを使って依存関係をインストールしてください。
You should look at and run the tests to see what happens in the example. To do this, you should install dependencies with
Composerfirst:
$ composer installComposerのインストールの仕方や使い方についてより深く知りたい場合はココで確認してください。
Read more about how to install and use
Composeron your local machine here.
テストコードではphpunitを実行します。
To run the tests use
phpunit:
$ ./vendor/bin/phpunit必要に応じてDocker for Mac, Windows or Linuxを使用してドキュメントを作成して閲覧することができます。
You can optionally build and browse the documentation using Docker for Mac, Windows or Linux.
実行方法は以下です。
Just run:
$ docker-compose uphttp://localhost:8080/README.htmlにアクセスすれば、生成されたドキュメントを読むことができます。
Go to http://localhost:8080/README.html to read the generated documentation.
docker-composeを使うためには以下のようにして依存関係をインストールするだけです。
To only install the dependencies, use
docker-composelike this:
$ docker-compose run php php composer.phar installデザインパターンはだいたい3つのカテゴリで構成されています。 📓をクリックするとすべての例を WikiPedia で確認することができます。
The patterns can be structured in roughly three different categories. Please click on the 📓 for a full explanation of the pattern on Wikipedia.
- AbstractFactory 📓
- Builder 📓
- FactoryMethod 📓
- Multiton (is considered an anti-pattern! ⛔)
- Pool 📓
- Prototype 📓
- SimpleFactory
- Singleton 📓 (is considered an anti-pattern! ⛔)
- StaticFactory
- Adapter 📓
- Bridge 📓
- Composite 📓
- DataMapper 📓
- Decorator 📓
- DependencyInjection 📓
- Facade 📓
- FluentInterface 📓
- Flyweight 📓
- Proxy 📓
- Registry 📓
- ChainOfResponsibilities 📓
- Command 📓
- Iterator 📓
- Mediator 📓
- Memento 📓
- NullObject 📓
- Observer 📓
- Specification 📓
- State 📓
- Strategy 📓
- TemplateMethod 📓
- Visitor 📓
- ServiceLocator 📓 (is considered an anti-pattern! ⛔)
- Repository
- EAV 📓
もし、サンプルコードにバグが見つかったり、翻訳間違いを見つけた場合は、お気軽にフォークして、変更内容のプルリクエストを送ってください。
ただし、コードの一貫性を維持するために、PHP_CodeSniffer を利用して PSR2 standard を実行してください。
実行方法は以下の通りです。
./vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor ..
If you encounter any bugs or missing translations, please feel free to fork and send a pull request with your changes. To establish a consistent code quality, please check your code using PHP_CodeSniffer against PSR2 standard using
./vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor ..