Created
October 7, 2012 21:33
-
-
Save kaja47/3849669 to your computer and use it in GitHub Desktop.
inject traits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| trait WantsAuthenticator { | |
| function injectAuthenticator(Authenticator $authenticator) { | |
| $this->authenticator = $authenticator; | |
| } | |
| } | |
| trait WantsCache { | |
| function injectCache(Cache $cache) { | |
| $this->cache = $cache; | |
| } | |
| } | |
| trait WantsDatabase { | |
| function injectDatabase(Database $database) { | |
| $this->database = $database; | |
| } | |
| } | |
| class HomepagePresenter { | |
| use WantsAuthenticator, WantsDatabase; | |
| private $authenticator, $database; | |
| } | |
| class ArticlePresenter { | |
| use WantsDatabase, WantsCache; | |
| private $database, $cache; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To raději http://phpfashion.com/di-a-property-injection