/** * {@inheritdoc} */ public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) { if ($route_name === '<current>') { if ($current_route = $this->routeMatch->getRouteObject()) { $requirements = $current_route->getRequirements(); // Setting _method and _schema is deprecated since 2.7. Using // setMethods() and setSchemes() are now the recommended ways. unset($requirements['_method']); unset($requirements['_schema']); $route->setRequirements($requirements); $route->setPath($current_route->getPath()); $route->setSchemes($current_route->getSchemes()); $route->setMethods($current_route->getMethods()); $route->setOptions($current_route->getOptions()); $route->setDefaults($current_route->getDefaults()); $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all()); if ($bubbleable_metadata) { $bubbleable_metadata->addCacheContexts(['route']); } } else { // If we have no current route match available, point to the frontpage. $route->setPath('/'); } } }
public function testPath() { $route = new Route('/{foo}'); $route->setPath('/{bar}'); $this->assertEquals('/{bar}', $route->getPath(), '->setPath() sets the path'); $route->setPath(''); $this->assertEquals('/', $route->getPath(), '->setPath() adds a / at the beginning of the path if needed'); $route->setPath('bar'); $this->assertEquals('/bar', $route->getPath(), '->setPath() adds a / at the beginning of the path if needed'); $this->assertEquals($route, $route->setPath(''), '->setPath() implements a fluent interface'); $route->setPath('//path'); $this->assertEquals('/path', $route->getPath(), '->setPath() does not allow two slahes "//" at the beginning of the path as it would be confused with a network path when generating the path from the route'); }
/** * {@inheritdoc} */ public function processOutbound($route_name, Route $route, array &$parameters) { if ($route_name === '<current>') { if ($current_route = $this->routeMatch->getRouteObject()) { $route->setPath($current_route->getPath()); $route->setRequirements($current_route->getRequirements()); $route->setOptions($current_route->getOptions()); $route->setDefaults($current_route->getDefaults()); $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all()); } else { // If we have no current route match available, point to the frontpage. $route->setPath('/'); } } }
/** * {@inheritdoc} */ public function processOutbound($route_name, Route $route, array &$parameters) { if ($route_name === '<current>' && ($current_route = $this->routeMatch->getRouteObject())) { $route->setPath($current_route->getPath()); $route->setRequirements($current_route->getRequirements()); $route->setOptions($current_route->getOptions()); $route->setDefaults($current_route->getDefaults()); $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all()); } }
/** * Tests the generate method with passing in a route object into generate(). * * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException */ public function testGenerateByRoute() { $this->generator = new ProviderBasedGenerator($this->provider); // Setup a route with a numeric parameter, but pass in a string, so it // fails and getRouteDebugMessage should be triggered. $route = new Route('/test'); $route->setPath('/test/{number}'); $route->setRequirement('number', '\\+d'); $this->generator->setStrictRequirements(true); $context = new RequestContext(); $this->generator->setContext($context); $this->assertSame(null, $this->generator->generate($route, array('number' => 'string'))); }
/** * @param RouteCollection $collection * @param string $name * @param array $config * @param string $path */ protected function parseRoute(RouteCollection $collection, $name, array $config, $path) { $defaults = isset($config['defaults']) ? $config['defaults'] : array(); $requirements = isset($config['requirements']) ? $config['requirements'] : array(); $options = isset($config['options']) ? $config['options'] : array(); $host = isset($config['host']) ? $config['host'] : ''; $schemes = isset($config['schemes']) ? $config['schemes'] : array(); $methods = isset($config['methods']) ? $config['methods'] : array(); $i18n = isset($config['i18n']) ? $config['i18n'] : true; foreach ($this->registry->getRegisteredLocales() as $locale) { $route = new Route($config['path'], $defaults, $requirements, $options, $host, $schemes, $methods); if ($i18n) { $route->setPath('/' . $locale . '/' . ltrim($this->helper->alterPath($config['path'], $locale), '/')); $route->setDefaults($this->helper->alterDefaults($defaults, $locale)); } $i18nName = $i18n ? $this->helper->alterName($name, $locale) : $name; $collection->add($i18nName, $route); } }
/** * {@inheritDoc} * * Overwritten to make sure the route is recompiled if the pattern was changed */ public function compile() { if ($this->needRecompile) { // calling parent::setPath just to let it set compiled=null. the parent $path field is never used parent::setPath($this->getPath()); } return parent::compile(); }
/** * {@inheritDoc} * * Overwritten to make sure the route is recompiled if the pattern was changed */ public function compile() { if ($this->needRecompile) { // calling parent::setPath just to let it set compiled=null. the parent $path field is never used // TODO: drop setPattern when we drop symfony 2.1 support // TODO: for now we need to check the method as setPattern on 2.2. triggers our setPath instead of parent setPath if (method_exists('Symfony\\Component\\Routing\\Route', 'setPath')) { parent::setPath($this->getPath()); } else { parent::setPattern($this->getPath()); } } return parent::compile(); }
/** * Refresh the entity * * @ORM\PostLoad */ public function refreshEntity() { parent::setPath($this->path); parent::setDefaults($this->defaults); parent::setRequirements($this->requirements); parent::setOptions($this->options); parent::setHost($this->host); parent::setMethods($this->methods); parent::setSchemes($this->schemes); }
/** * {@inheritDoc} */ public function compile() { if ($this->recompile) { parent::setPath($this->getPath()); } return parent::compile(); }
/** * Prepends the bundle prefix to the route. * * @param Route $route * @param AbstractBundle $bundle * * We have to prepend the bundle prefix if * - routes are _not_ currently extracted via the command line and * - the route has i18n set to false. * This is because when extracting the routes, a bundle author only wants to translate the bare route * patterns, without a redundant and potentially customized bundle prefix in front of them. * If i18n is set to true, Zikula's customized pattern generation strategy will take care of it. * See Zikula\RoutesModule\Translation\ZikulaPatternGenerationStrategy */ private function prependBundlePrefix(Route $route, AbstractBundle $bundle) { $prefix = ''; $options = $route->getOptions(); $prependBundle = !isset($GLOBALS['translation_extract_routes']) && isset($options['i18n']) && !$options['i18n']; if ($prependBundle && (!isset($options['zkNoBundlePrefix']) || !$options['zkNoBundlePrefix'])) { // get url from MetaData first. May be empty. $untranslatedPrefix = $bundle->getMetaData()->getUrl(false); if (empty($untranslatedPrefix)) { try { // MetaData will be empty for extensions not Spec-2.0. Try to get from modinfo. // this calls the DB which is not available during install. $modinfo = \ModUtil::getInfoFromName($bundle->getName()); $prefix = $modinfo['url']; } catch (\Exception $e) { } } else { $locale = $this->container->getParameter('locale'); if ($this->translator->getCatalogue($locale)->has($untranslatedPrefix, strtolower($bundle->getName()))) { $prefix = $this->translator->trans($untranslatedPrefix, [], strtolower($bundle->getName()), $locale); } else { $prefix = $untranslatedPrefix; } } $path = "/" . $prefix . $route->getPath(); $route->setPath($path); } }
/** * Apply the parameter map to a Drupal 8 route, modifying it as needed. * * @param \Symfony\Component\Routing\Route $route * The route to process. */ public function applyRoute(Drupal8Route $route) { $this->applyPath($this->path); foreach ($this as $key => $binding) { $parameter = $binding->getParameter(); /** @var ParameterBinding $binding */ if (is_integer($key)) { if ($parameter->isOptional()) { // @todo Don't use eval(). $value = eval('return ' . $parameter->getValue() . ';'); $route->setDefault($parameter->getName(), $value); } } elseif ($binding->hasArgument()) { $route->setDefault($parameter->getName(), $binding->getValue()); } } $route->setPath($this->path->__toString()); }
/** * Adds the locale to the route if prepend_locale is enabled. * * @param Route $route The route */ private function addLocaleToRoute(Route $route) { if ($this->prependLocale) { $route->setPath('/{_locale}' . $route->getPath()); $route->addRequirements(['_locale' => '[a-z]{2}(\\-[A-Z]{2})?']); } else { $route->addDefaults(['_locale' => null]); } }
public function setPath($pattern) { // Remove trailing slash from route return parent::setPath(rtrim($pattern, '/')); }
/** * {@inheritdoc} */ public function processOutbound($route_name, Route $route, array &$parameters) { if ($route_name === '<none>') { $route->setPath(''); } }