/** * Catch all calls, fire events and remap to real instance * * @access public * @param string $method * @param array $args * @return mixed */ public function __call($method, array $args = array()) { $event = $this->observer->createEvent()->setMethod($method)->setParams($args)->setInstance($this)->setType('before'); $before = $this->observer->trigger()->getResult(); if ($event->isPropagationStopped()) { return $before; } /** @var \Closure $closure */ if ($closure = $this->observer->bound($method)) { $callback = $closure->bindTo($this, $this); $result = Executor::callClosure($callback, $event->getParams()); } else { $result = Executor::call($this(true), $method, $event->getParams()); } $event->setType('after')->setResult($result); return $this->observer->trigger()->getResult(); }