/** * main routing engine method: determines route by path * @param string path * @return array found route in format: * "controller" => "controller name", "action" => "action name", * "params" => array( "param name" => "param value", ... ). * @author kstep */ public function findRoute($path) { $result = array(); $matches = null; $site = $this->findSite($path); if ($site) { $path = $site['path']; foreach ($site['route'] as $route) { //if (!$route['match'] || preg_match($route['match'], $path, $matches)) if ($route['match'] && preg_match($route['match'], $path, $matches) || $route['@attributes']['default']) { if (!$matches) { $matches = explode('/', $path); } $result = $route; $result['controller'] = is_numeric($route['controller']) ? $matches[$route['controller']] : $route['controller']; $result['action'] = is_numeric($route['action']) ? $matches[$route['action']] : $route['action']; $result['params'] = $route['params'] ? $this->parseParams(&$matches, &$route['params']) : array(); break; } } if ($result['@attributes']['redirect']) { $view = new View_Html(); $view->redir($result['controller'], $result['action'], $result['params'], $result['@attributes']['preserveqs'] === 'true' ? $_SERVER['QUERY_STRING'] : null); $view->setSite($site); $view->render(); exit; } $result['site'] = $site; } return $result; }