protected function parseRoutesAndFiles(AgaviRouting $routing, $routes, &$data) { $controller = $this->context->getController(); $request = $this->context->getRequest(); foreach ($routes as $route) { $outputTypes = array(); $routeName = $route->getAttribute('name'); if ($routeName !== '*' && is_null($routing->getRoute($routeName))) { throw new AgaviConfigurationException('Route name "' . $routeName . '" does not exist or is not correct.'); } if ($route->hasAttribute('output_type')) { foreach (explode(' ', $route->getAttribute('output_type')) as $ot) { if ($controller->getOutputType($ot)) { $outputTypes[] = $ot; } } } else { $outputTypes[] = $controller->getOutputType()->getName(); // Defaults to HTML } foreach ($route->get('filelist') as $filelist) { $metatype = $filelist->getAttribute('metatype'); foreach ($filelist->getElementsByTagName('file') as $file) { foreach ($outputTypes as $ot) { if ($file->hasAttribute('name')) { $data[$routeName][$ot][$metatype][$file->getAttribute('name')] = AgaviToolkit::expandDirectives($file->getValue()); } else { $data[$routeName][$ot][$metatype][] = AgaviToolkit::expandDirectives($file->getValue()); } } } } } }
/** * Takes a nested array of AgaviConfigValueHolder containing the routing * information and creates the routes in the given routing. * * @param AgaviRouting The routing instance to create the routes in. * @param mixed The "roles" node (element or node list) * @param string The name of the parent route (if any). * * @author Dominik del Bondio <*****@*****.**> * @since 0.11.0 */ protected function parseRoutes(AgaviRouting $routing, $routes, $parent = null) { foreach ($routes as $route) { $pattern = AgaviToolkit::expandDirectives($route->getAttribute('pattern')); $opts = array(); if ($route->hasAttribute('imply')) { $opts['imply'] = AgaviToolkit::literalize($route->getAttribute('imply')); } if ($route->hasAttribute('cut')) { $opts['cut'] = AgaviToolkit::literalize($route->getAttribute('cut')); } if ($route->hasAttribute('stop')) { $opts['stop'] = AgaviToolkit::literalize($route->getAttribute('stop')); } if ($route->hasAttribute('name')) { $opts['name'] = AgaviToolkit::expandDirectives($route->getAttribute('name')); } if ($route->hasAttribute('source')) { $opts['source'] = AgaviToolkit::expandDirectives($route->getAttribute('source')); } if ($route->hasAttribute('constraint')) { $opts['constraint'] = array_map('trim', explode(' ', trim(AgaviToolkit::expandDirectives($route->getAttribute('constraint'))))); } // values which will be set when the route matched if ($route->hasAttribute('action')) { $opts['action'] = AgaviToolkit::expandDirectives($route->getAttribute('action')); } if ($route->hasAttribute('locale')) { $opts['locale'] = AgaviToolkit::expandDirectives($route->getAttribute('locale')); } if ($route->hasAttribute('method')) { $opts['method'] = AgaviToolkit::expandDirectives($route->getAttribute('method')); } if ($route->hasAttribute('module')) { $opts['module'] = AgaviToolkit::expandDirectives($route->getAttribute('module')); } if ($route->hasAttribute('output_type')) { $opts['output_type'] = AgaviToolkit::expandDirectives($route->getAttribute('output_type')); } if ($route->has('ignores')) { foreach ($route->get('ignores') as $ignore) { $opts['ignores'][] = $ignore->getValue(); } } if ($route->has('defaults')) { foreach ($route->get('defaults') as $default) { $opts['defaults'][$default->getAttribute('for')] = $default->getValue(); } } if ($route->has('callbacks')) { $opts['callbacks'] = array(); foreach ($route->get('callbacks') as $callback) { $opts['callbacks'][] = array('class' => $callback->getAttribute('class'), 'parameters' => $callback->getAgaviParameters()); } } $opts['parameters'] = $route->getAgaviParameters(); if (isset($opts['name']) && $parent) { // don't overwrite $parent since it's used later $parentName = $parent; if ($opts['name'][0] == '.') { while ($parentName && isset($this->unnamedRoutes[$parentName])) { $parentRoute = $routing->getRoute($parentName); $parentName = $parentRoute['opt']['parent']; } $opts['name'] = $parentName . $opts['name']; } } if (isset($opts['action']) && $parent) { if ($opts['action'][0] == '.') { $parentRoute = $routing->getRoute($parent); // unwind all empty 'action' attributes of the parent(s) while ($parentRoute && empty($parentRoute['opt']['action'])) { $parentRoute = $routing->getRoute($parentRoute['opt']['parent']); } if (!empty($parentRoute['opt']['action'])) { $opts['action'] = $parentRoute['opt']['action'] . $opts['action']; } } } $name = $routing->addRoute($pattern, $opts, $parent); if (!isset($opts['name']) || $opts['name'] !== $name) { $this->unnamedRoutes[$name] = true; } if ($route->has('routes')) { $this->parseRoutes($routing, $route->get('routes'), $name); } } }