/** * {@inheritDoc} */ 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(); if (isset($config['locales'])) { $collection->addCollection($this->collectionBuilder->buildCollection($name, $config['locales'], $defaults, $requirements, $options, $host, $schemes, $methods)); } else { $route = new Route($config['path'], $defaults, $requirements, $options, $host, $schemes, $methods); $collection->add($name, $route); } }
/** * @dataProvider provideI18nRouteData */ public function testCollection($name, $locales, $defaults, $requirements, $options, $variables) { $i18nRoute = new I18nRouteCollectionBuilder(); $collection = $i18nRoute->buildCollection($name, $locales, $defaults, $requirements, $options); foreach ($locales as $locale => $pattern) { $route = $collection->get($name . '.' . $locale); $compiled = $route->compile(); $defaults['_locale'] = $locale; $options['compiler_class'] = 'Symfony\\Component\\Routing\\RouteCompiler'; $this->assertEquals($pattern, $route->getPattern(), '(pattern)'); $this->assertEquals($defaults, $route->getDefaults(), '(defaults)'); $this->assertEquals($requirements, $route->getRequirements(), '(requirements)'); $this->assertEquals($options, $route->getOptions(), '(options)'); $this->assertEquals($variables, $compiled->getVariables(), '(variables)'); } }
/** * {@inheritdoc} */ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path) { if ('' === ($id = $node->getAttribute('id'))) { throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" attribute.', $path)); } if ($node->hasAttribute('pattern')) { if ($node->hasAttribute('path')) { throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path)); } $node->setAttribute('path', $node->getAttribute('pattern')); $node->removeAttribute('pattern'); } $schemes = preg_split('/[\\s,\\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY); $methods = preg_split('/[\\s,\\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY); list($defaults, $requirements, $options, $localesWithPaths) = $this->parseConfigs($node, $path); if ($localesWithPaths) { $collection->addCollection($this->collectionBuilder->buildCollection($id, $localesWithPaths, $defaults, $requirements, $options, $node->getAttribute('host'), $schemes, $methods)); } else { if (!$node->hasAttribute('pattern') && !$node->hasAttribute('path')) { throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "path" attribute.', $path)); } $route = new Route($node->getAttribute('path'), $defaults, $requirements, $options, $node->getAttribute('host'), $schemes, $methods); $collection->add($id, $route); } }