Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RepositoryDecorator
- {
- /**
- * @var RepositoryInterface
- */
- private $repository;
- /**
- * @var \SplQueue
- */
- private $queue;
- public function __construct(RepositoryInterface $repository)
- {
- $this->repository = $repository;
- $this->queue = new \SplQueue();
- }
- public function on($name, $will)
- {
- $this->queue->enqueue(['name' => $name, 'value' => $will]);
- return $this;
- }
- public function __call($name, $arguments)
- {
- if (count($this->queue) > 0 && $name === $this->queue->bottom()['name']) {
- $result = $this->queue->dequeue();
- if ($result['value'] instanceof \Exception) {
- throw $result['value'];
- }
- return $result['value'];
- }
- return call_user_func_array(array($this->repository, $name), $arguments);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment