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()); } } } } } }
/** * visit * * @param KVDthes_Term $node * @return void */ public function visit(KVDthes_Term $node) { $this->result .= $this->pad() . "<li>\n"; $this->depth++; $this->result .= $this->pad() . '<p><a href="' . $this->ro->gen($this->termRoute, array($this->termIdParameter => $node->getId())) . '">' . $node->getTerm() . "</a></p>\n"; $this->depth--; return true; }
/** * Initialize the routing instance. * * @param AgaviContext A Context instance. * @param array An array of initialization parameters. * * @author David Zülke <*****@*****.**> * @since 0.11.0 */ public function initialize(AgaviContext $context, array $parameters = array()) { parent::initialize($context, $parameters); if (!$this->isEnabled()) { return; } $this->updateInput(); }
/** * toHtml * * @param int $range * @return string */ public function toHtml($range = 5, $showtotals = false) { $html = ''; if ($showtotals) { $html .= '<p><strong>Je zoekopdracht leverde ' . $this->pager->getTotalRecordCount() . ' resultaten.</strong></p>'; } if ($this->pager->getPage() > $this->pager->getFirstPage()) { $this->parameters[$this->paginaNaam] = $this->pager->getPrev(); $html .= $this->lh->genHtmlLink($this->ro->gen($this->route, $this->parameters), 'Vorige'); $html .= ' [ '; $this->parameters[$this->paginaNaam] = $this->pager->getFirstPage(); $html .= $this->lh->genHtmlLink($this->ro->gen($this->route, $this->parameters), $this->pager->getFirstPage()) . ' '; } else { $html .= 'Vorige [ '; } $html .= $this->pager->getPage() > $this->pager->getFirstPage() + $range ? '.. ' : ''; foreach ($this->pager->getPrevLinks($range) as $page) { if ($page != $this->pager->getFirstPage()) { $this->parameters[$this->paginaNaam] = $page; $html .= $this->lh->genHtmlLink($this->ro->gen($this->route, $this->parameters), $page) . ' '; } } $html .= '<strong>' . $this->pager->getPage() . '</strong> '; foreach ($this->pager->getNextLinks($range) as $page) { if ($page != $this->pager->getLastPage()) { $this->parameters[$this->paginaNaam] = $page; $html .= $this->lh->genHtmlLink($this->ro->gen($this->route, $this->parameters), $page) . ' '; } } $html .= $this->pager->getPage() < $this->pager->getLastPage() - $range ? '.. ' : ''; if ($this->pager->getPage() < $this->pager->getLastPage()) { $this->parameters[$this->paginaNaam] = $this->pager->getLastPage(); $html .= $this->lh->genHtmlLink($this->ro->gen($this->route, $this->parameters), $this->pager->getLastPage()); $html .= ' ] '; $this->parameters[$this->paginaNaam] = $this->pager->getNext(); $html .= $this->lh->genHtmlLink($this->ro->gen($this->route, $this->parameters), 'Volgende'); } else { $html .= ' ] Volgende'; } return $html; }
/** * Set the name of the called web service method as the routing input. * * @author David Zülke <*****@*****.**> * @since 1.0.0 */ public function startup() { parent::startup(); $this->input = $this->context->getRequest()->getInput(); }
/** * 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); } } }
/** * Generate a formatted Agavi URL. * * @param string A route name. * @param array An associative array of parameters. * @param mixed An array of options, or the name of an options preset. * * @return string The generated URL. * * @author David Zülke <*****@*****.**> * @since 0.11.0 */ public function gen($route, array $params = array(), $options = array()) { $req = $this->context->getRequest(); if (substr($route, -1) == '*') { $options['refill_all_parameters'] = true; $route = substr($route, 0, -1); } $options = $this->resolveGenOptions($options); $aso = $this->argSeparatorOutput; if ($options['separator'] != $aso) { $aso = $options['separator']; } if ($options['use_trans_sid'] === true && defined('SID') && SID !== '') { $params = array_merge($params, array(session_name() => session_id())); } if ($route === null && empty($params)) { $retval = $req->getRequestUri(); $retval = str_replace(array('[', ']', '\''), array('%5B', '%5D', '%27'), $retval); // much quicker than str_replace($this->argSeparatorInput, array_fill(0, count($this->argSeparatorInput), $aso), $retval) foreach ($this->argSeparatorInput as $char) { $retval = str_replace($char, $aso, $retval); } } else { if ($this->isEnabled()) { // the route exists and routing is enabled, the parent method handles it $append = ''; list($path, $usedParams, $options, $extraParams, $isNullRoute) = parent::gen($route, $params, $options); if ($isNullRoute) { // add the incoming parameters from the request uri for gen(null) and friends $extraParams = array_merge($this->inputParameters, $extraParams); } if (count($extraParams) > 0) { $append = http_build_query($extraParams, '', $aso); if ($append !== '') { $append = '?' . $append; } } } else { // the route exists, but we must create a normal index.php?foo=bar URL. $isNullRoute = false; $routes = $this->getAffectedRoutes($route, $isNullRoute); if ($isNullRoute) { $params = array_merge($this->inputParameters, $params); } if (count($routes) == 0) { $path = $route; } // we collect the default parameters from the route and make sure // new parameters don't overwrite already defined parameters $defaults = array(); $ma = $req->getParameter('module_accessor'); $aa = $req->getParameter('action_accessor'); foreach ($routes as $route) { if (isset($this->routes[$route])) { $r = $this->routes[$route]; $myDefaults = array(); foreach ($r['opt']['defaults'] as $key => $default) { $myDefaults[$key] = $default->getValue(); } if ($r['opt']['module']) { $myDefaults[$ma] = $r['opt']['module']; } if ($r['opt']['action']) { $myDefaults[$aa] = $r['opt']['action']; } $defaults = array_merge($myDefaults, $defaults); } } $params = array_merge($defaults, $params); } if (!isset($path)) { // the route does not exist. we generate a normal index.php?foo=bar URL. $path = $_SERVER['SCRIPT_NAME']; } if (!isset($path)) { // routing was off; the name of the route is the input } if (!isset($append)) { $append = '?' . http_build_query($params, '', $aso); } $retval = $path . $append; } if (!$options['relative'] || $options['relative'] && ($options['scheme'] !== null || $options['authority'] !== null || $options['host'] !== null || $options['port'] !== null)) { $scheme = false; if ($options['scheme'] !== false) { $scheme = $options['scheme'] === null ? $req->getUrlScheme() : $options['scheme']; } $authority = ''; if ($options['authority'] === null) { if ($options['host'] !== null && $options['host'] !== false) { $authority = $options['host']; } elseif ($options['host'] === false) { $authority = ''; } else { $authority = $req->getUrlHost(); } $port = null; if ($options['port'] !== null && $options['port'] !== false) { if (AgaviToolkit::isPortNecessary($options['scheme'] !== null && $options['scheme'] !== false ? $options['scheme'] : $req->getUrlScheme(), $options['port'])) { $port = $options['port']; } else { $port = null; } } elseif ($options['port'] === false) { $port = null; } elseif ($options['scheme'] === null) { if (!AgaviToolkit::isPortNecessary($req->getUrlScheme(), $port = $req->getUrlPort())) { $port = null; } } if ($port !== null) { $authority .= ':' . $port; } } elseif ($options['authority'] !== false) { $authority = $options['authority']; } if ($scheme === false) { // nothing at all, e.g. when displaying a URL without the "http://" prefix $scheme = ''; } elseif (trim($scheme) === '') { // a protocol-relative URL (see #1224) $scheme = '//'; } else { // given scheme plus "://" $scheme = $scheme . '://'; } $retval = $scheme . $authority . $retval; } if ($options['fragment'] !== null) { $retval .= '#' . $options['fragment']; } return $retval; }
public function parseRouteString($str) { return parent::parseRouteString($str); }