/** * Parses URL * * @param string $url * @return array|null * @throws NotAuthException */ public function parseRoute($url = '') { $route_found = null; $request = new Request(); $url = empty($url) ? $request->getUri() : $url; // Don`t replace slash on route "/" if ($url != '/') { $url = preg_replace('~/$~', '', $url); } foreach (self::$map as $key => $route) { $pattern = $this->prepare($route); if (preg_match($pattern, $url, $params)) { $security = Service::get('security'); $this->current_route = $route; $this->current_route['_name'] = $key; if (isset($route['security'])) { $roles = $route['security']; $user_role = $security->isAuthenticated() ? Service::get('security')->getUser()->role : array(); if (array_search($user_role, $roles) === false) { throw new NotAuthException(); } } // Get assoc array of params: preg_match('~{([\\w\\d_]+)}~', $route['pattern'], $param_names); $params = array_map('urldecode', $params); if (!empty($param_names)) { $params = array_combine($param_names, $params); array_shift($params); // Get rid of 0 element $this->current_route['params'] = $params; } break; } } return $this->current_route; }