/** * set the http methods through which a route can be accessed * * @param PhRouter\RouteInterface $route * @param $methods * @return PhRouter\RouteInterface */ public function setHttpMethods(PhRouter\RouteInterface $route, $methods) { if ($methods === null || empty($methods)) { return; } $route->setHttpMethods($methods); }
/** * @param \Phalcon\Mvc\Router\RouteInterface $authRoute * @return bool */ protected function setNotAuthenticated(\Phalcon\Mvc\Router\RouteInterface $authRoute) { if ($authRoute->getRouteId() != $this->router->getMatchedRoute()->getRouteId()) { //stores url which requires authentication $currentUrl = array(); parse_str($this->request->getServer('QUERY_STRING'), $currentUrl); if (isset($currentUrl['_url'])) { $this->session->set('redirect_url', $currentUrl['_url']); } $response = $this->getDI()->getShared('response'); $response->redirect(array('for' => $authRoute->getName())); if (!$response->isSent()) { $response->send(); } } //needs to stop dispatching return false; }
/** * Checks if a route matches the pattern * * @param Phalcon\Mvc\Router\RouteInterface * @param string * @return bool * @author Neil Brayfield <*****@*****.**> */ protected function matches(RouteInterface $route, $uri) { $pattern = $route->getCompiledPattern(); if (!preg_match($pattern, $uri, $matches)) { return false; } foreach ($matches as $key => $value) { if (is_int($key)) { // Skip all unnamed keys continue; } // Set the value for all matched keys $this->params[$key] = $value; } $this->wasMatch = true; $this->matchedRoute = $route; $this->matches = $route->getPaths(); $converters = $route->getConverters(); if (is_array($converters)) { foreach ($this->params as $part => &$value) { if (isset($converter[$part])) { $value = call_user_func($converter[$part], $value); } } } if (isset($this->params['namespace'])) { $this->namespace = $this->params['namespace']; unset($this->params['namespace']); } elseif (isset($this->matches['namespace'])) { $this->namespace = $this->matches['namespace']; } if (isset($this->params['module'])) { $this->module = $this->params['module']; unset($this->params['module']); } elseif (isset($this->matches['module'])) { $this->module = $this->matches['module']; } if (isset($this->params['controller'])) { $this->controller = $this->params['controller']; unset($this->params['controller']); } elseif (isset($this->matches['controller'])) { $this->controller = $this->matches['controller']; } if (isset($this->params['action'])) { $this->action = $this->params['action']; unset($this->params['action']); } elseif (isset($this->matches['action'])) { $this->action = $this->matches['action']; } return true; }