public function testOptions() { $route = new Route('/{foo}'); $route->setOptions(array('foo' => 'bar')); $this->assertEquals(array_merge(array('segment_separators' => array('/', '.'), 'text_regex' => '.+?', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), array('foo' => 'bar')), $route->getOptions(), '->setOptions() sets the options'); $this->assertEquals($route, $route->setOptions(array()), '->setOptions() implements a fluent interface'); }
public function testOptions() { $route = new Route('/{foo}'); $route->setOptions(array('foo' => 'bar')); $this->assertEquals(array_merge(array('compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), array('foo' => 'bar')), $route->getOptions(), '->setOptions() sets the options'); $this->assertEquals($route, $route->setOptions(array()), '->setOptions() implements a fluent interface'); $route->setOptions(array('foo' => 'foo')); $route->addOptions(array('bar' => 'bar')); $this->assertEquals($route, $route->addOptions(array()), '->addOptions() implements a fluent interface'); $this->assertEquals(array('foo' => 'foo', 'bar' => 'bar', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), $route->getOptions(), '->addDefaults() keep previous defaults'); }
/** * {@inheritDoc} * * Handling the missing default 'compiler_class' * @see setOptions */ public function getOptions() { $options = parent::getOptions(); if (!array_key_exists('compiler_class', $options)) { $options['compiler_class'] = 'Symfony\\Component\\Routing\\RouteCompiler'; } foreach ($options as $key => $value) { if ($this->isBooleanOption($key)) { $options[$key] = (bool) $value; } } return $options; }
/** * {@inheritDoc} * * Handling the missing default 'compiler_class' * @see setOptions */ public function getOptions() { $options = parent::getOptions(); if (!array_key_exists('compiler_class', $options)) { $options['compiler_class'] = 'Symfony\\Component\\Routing\\RouteCompiler'; } return $options; }
/** * Set the options * * @param array $options * @return Route */ public function setOptions(array $options) { parent::setOptions($options); $this->options = parent::getOptions(); return $this; }
/** * Asserts that a route object has the expected properties. * * @param \Symfony\Component\Routing\Route $route * The route to test. * @param string $expected_path * The expected path for the route. * @param array $expected_defaults * The expected defaults for the route. * @param array $expected_requirements * The expected requirements for the route. * @param array $expected_options * The expected options for the route. */ protected function assertMatchingRoute(Route $route, $expected_path, $expected_defaults, $expected_requirements, $expected_options) { $this->assertSame($expected_path, $route->getPath()); $this->assertSame($expected_defaults, $route->getDefaults()); $this->assertSame($expected_requirements, $route->getRequirements()); $this->assertSame($expected_options, $route->getOptions()); }
/** * Returns the options. * * @return array * The options. */ public function getOptions() { return $this->route->getOptions(); }
/** * 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); } }
/** * Makes a clone of the given Route object. * * @param Route $route * * @return Route */ public function cloneRoute(Route $route) { return new Route($route->getPath(), $route->getDefaults(), $route->getRequirements(), $route->getOptions(), $route->getHost(), $route->getSchemes(), $route->getMethods()); }