public function get_routes(midgardmvc_core_request $request) { $node_is_root = false; if ($request->get_node() == midgardmvc_core::get_instance()->hierarchy->get_root_node()) { $node_is_root = true; } if (isset($this->cached_routes[$node_is_root])) { return $this->cached_routes[$node_is_root]; } $routes = array(); if (!isset($this->manifest['routes'])) { return $routes; } foreach ($this->manifest['routes'] as $route_id => $route) { if (isset($route['root_only']) && $route['root_only'] && !$node_is_root) { // Drop root-only routes from subnodes continue; } if (isset($route['test_only']) && $route['test_only'] && !$request->isset_data_item('test_mode')) { // Drop test-only routes when not in unit tests continue; } if (isset($route['subrequest_only']) && $route['subrequest_only'] && !$request->is_subrequest()) { // Drop routes that are usable via subrequest only from the main request continue; } // Handle the required route parameters if (!isset($route['controller'])) { throw new Exception("Route {$route_id} of {$this->name} has no controller defined"); } if (!isset($route['action'])) { throw new Exception("Route {$route_id} of {$this->name} has no action defined"); } if (!isset($route['path'])) { throw new Exception("Route {$route_id} of {$this->name} has no path defined"); } if (!isset($route['template_aliases'])) { $route['template_aliases'] = array(); } if (!isset($route['mimetype'])) { $route['mimetype'] = 'text/html'; // $route['mimetype'] = 'application/xhtml+xml'; } $routes[$route_id] = new midgardmvc_core_route($route_id, $route['path'], $route['controller'], $route['action'], $route['template_aliases'], $route['mimetype']); } $this->cached_routes[$node_is_root] = $routes; return $routes; }