Created
November 5, 2014 06:25
-
-
Save Mattnmoore/8ba708d92c30127eb86a to your computer and use it in GitHub Desktop.
Some base repository setup
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 | |
| interface BaseRepository { | |
| public function find($id); | |
| } | |
| class BaseRepository implements BaseRepository { | |
| private $model; | |
| public function setModel($model) | |
| { | |
| $this->model = $model; | |
| } | |
| public function find($id) | |
| { | |
| return $this->model->find($id); | |
| } | |
| } | |
| class BaseCacheRepository implements BaseRepository { | |
| private $cache; | |
| private $repository; | |
| private $model; | |
| function __construct(Cache $cache, BaseRepository $repository) | |
| { | |
| $this->cache = $cache; | |
| $this->repository = $repository; | |
| } | |
| public function setModel($model) | |
| { | |
| $this->model = $model; | |
| } | |
| public function find($id) | |
| { | |
| $this->cache->tags($model)->rememberForever($model . ':' . $id, function() use ($id) | |
| { | |
| $this->repository->find($id); | |
| } | |
| } | |
| } | |
| class WidgetRepository extends BaseRepository { | |
| function __construct(Widget $widget) | |
| { | |
| $this->setModel($widget); | |
| } | |
| } | |
| class WidgetCachedRepository extends BaseCachedRepository { | |
| function __construct() | |
| { | |
| $this->setModel('widget'); | |
| } | |
| } | |
| $repository = $this->app->make('Conductor\Core\Widget\WidgetCachedRepository'); | |
| $widget = $repostory->find(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment