Skip to content

Instantly share code, notes, and snippets.

@kaja47
Created October 7, 2012 21:33
Show Gist options
  • Save kaja47/3849669 to your computer and use it in GitHub Desktop.
Save kaja47/3849669 to your computer and use it in GitHub Desktop.
inject traits
<?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;
}
@fprochazka
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment