/** * @param \Phalcon\Events\Event $event * @param \Phalcon\DispatcherInterface $dispatcher * * @throws \Phalcon\Mvc\Dispatcher\Exception */ public function beforeExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\DispatcherInterface $dispatcher, $data) { $methodAnnotations = $this->annotations->getMethod($dispatcher->getHandlerClass(), $dispatcher->getActiveMethod()); if (!$methodAnnotations->has("RequiredParams")) { return; } $requiredParams = $methodAnnotations->get("RequiredParams")->getArgument(0); $specifiedParams = array_keys($this->getParams()); $missingParams = array_diff($requiredParams, $specifiedParams); if (count($missingParams) > 0) { throw new \Sid\Phalcon\RequiredParams\Exception("Required parameters not specified (" . implode(", ", $missingParams) . ")."); } }
/** * @param \Phalcon\Events\Event $event * @param \Phalcon\DispatcherInterface $dispatcher * @param \Exception $exception * * @return boolean */ public function beforeException(\Phalcon\Events\Event $event, \Phalcon\DispatcherInterface $dispatcher, \Exception $exception) { $methodAnnotations = $this->annotations->getMethod($dispatcher->getHandlerClass(), $dispatcher->getActiveMethod()); if (!$methodAnnotations->has("ForwardException")) { return true; } $annotation = $methodAnnotations->get("ForwardException"); $forward = $annotation->getArgument(0); $dispatcher->forward($forward); if ($annotation->hasArgument(1)) { $callbackNames = $annotation->getArgument(1); foreach ($callbackNames as $callbackName) { if (isset($this->callbacks[$callbackName])) { $closure = \Closure::bind($this->callbacks[$callbackName], $this); $closure($exception); } } } return false; }