diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index fe887ca9c97b..98966a5a18bb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -6,7 +6,6 @@ CHANGELOG * Added link to source for controllers registered as named services * Added link to source on controller on `router:match`/`debug:router` (when `framework.ide` is configured) - * Added `Routing\Loader` and `Routing\Loader\Configurator` namespaces to ease defining routes with default controllers * Added the `framework.router.context` configuration node to configure the `RequestContext` * Made `MicroKernelTrait::configureContainer()` compatible with `ContainerConfigurator` * Added a new `mailer.message_bus` option to configure or disable the message bus to use to send mails. diff --git a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php index 73c2a0605c06..d0d6fca01250 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php @@ -11,14 +11,14 @@ namespace Symfony\Bundle\FrameworkBundle\Kernel; -use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator; -use Symfony\Bundle\FrameworkBundle\Routing\Loader\PhpFileLoader as RoutingPhpFileLoader; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\AbstractConfigurator; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader as ContainerPhpFileLoader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; +use Symfony\Component\Routing\Loader\PhpFileLoader as RoutingPhpFileLoader; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouteCollectionBuilder; diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index 9c9eec1e152b..cf662e274801 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -25,7 +25,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/GoneRouteConfigurator.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/GoneRouteConfigurator.php deleted file mode 100644 index be1b83da4c20..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/GoneRouteConfigurator.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator; - -use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait; -use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator; - -/** - * @author Nicolas Grekas - */ -class GoneRouteConfigurator extends RouteConfigurator -{ - use AddTrait; - - /** - * @param bool $permanent Whether the route is gone permanently - * - * @return $this - */ - final public function permanent(bool $permanent = true) - { - return $this->defaults(['permanent' => $permanent]); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RedirectRouteConfigurator.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RedirectRouteConfigurator.php deleted file mode 100644 index 80c28bc5246b..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RedirectRouteConfigurator.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator; - -use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait; -use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator; - -/** - * @author Jules Pietri - */ -class RedirectRouteConfigurator extends RouteConfigurator -{ - use AddTrait; - - /** - * @param bool $permanent Whether the redirection is permanent - * - * @return $this - */ - final public function permanent(bool $permanent = true) - { - return $this->defaults(['permanent' => $permanent]); - } - - /** - * @param bool|array $ignoreAttributes Whether to ignore attributes or an array of attributes to ignore - * - * @return $this - */ - final public function ignoreAttributes($ignoreAttributes = true) - { - return $this->defaults(['ignoreAttributes' => $ignoreAttributes]); - } - - /** - * @param bool $keepRequestMethod Whether redirect action should keep HTTP request method - * - * @return $this - */ - final public function keepRequestMethod(bool $keepRequestMethod = true) - { - return $this->defaults(['keepRequestMethod' => $keepRequestMethod]); - } - - /** - * @param bool $keepQueryParams Whether redirect action should keep query parameters - * - * @return $this - */ - final public function keepQueryParams(bool $keepQueryParams = true) - { - return $this->defaults(['keepQueryParams' => $keepQueryParams]); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RouteConfigurator.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RouteConfigurator.php deleted file mode 100644 index 5932d987479b..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RouteConfigurator.php +++ /dev/null @@ -1,73 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator; - -use Symfony\Bundle\FrameworkBundle\Controller\RedirectController; -use Symfony\Bundle\FrameworkBundle\Controller\TemplateController; -use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator as BaseRouteConfigurator; - -/** - * @author Jules Pietri - */ -class RouteConfigurator extends BaseRouteConfigurator -{ - /** - * @param string $template The template name - * @param array $context The template variables - */ - final public function template(string $template, array $context = []): TemplateRouteConfigurator - { - return (new TemplateRouteConfigurator($this->collection, $this->route, $this->name, $this->parentConfigurator, $this->prefixes)) - ->defaults([ - '_controller' => TemplateController::class, - 'template' => $template, - 'context' => $context, - ]) - ; - } - - /** - * @param string $route The route name to redirect to - */ - final public function redirectToRoute(string $route): RedirectRouteConfigurator - { - return (new RedirectRouteConfigurator($this->collection, $this->route, $this->name, $this->parentConfigurator, $this->prefixes)) - ->defaults([ - '_controller' => RedirectController::class.'::redirectAction', - 'route' => $route, - ]) - ; - } - - /** - * @param string $url The relative path or URL to redirect to - */ - final public function redirectToUrl(string $url): UrlRedirectRouteConfigurator - { - return (new UrlRedirectRouteConfigurator($this->collection, $this->route, $this->name, $this->parentConfigurator, $this->prefixes)) - ->defaults([ - '_controller' => RedirectController::class.'::urlRedirectAction', - 'path' => $url, - ]) - ; - } - - final public function gone(): GoneRouteConfigurator - { - return (new GoneRouteConfigurator($this->collection, $this->route, $this->name, $this->parentConfigurator, $this->prefixes)) - ->defaults([ - '_controller' => RedirectController::class.'::redirectAction', - 'route' => '', - ]) - ; - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RoutingConfigurator.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RoutingConfigurator.php deleted file mode 100644 index a429e9e75a83..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/RoutingConfigurator.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator; - -use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait; -use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator as BaseRoutingConfigurator; - -class RoutingConfigurator extends BaseRoutingConfigurator -{ - use AddTrait; -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/TemplateRouteConfigurator.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/TemplateRouteConfigurator.php deleted file mode 100644 index ea53a22e2395..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/TemplateRouteConfigurator.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator; - -use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait; -use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator; - -/** - * @author Jules Pietri - */ -class TemplateRouteConfigurator extends RouteConfigurator -{ - use AddTrait; - - /** - * @param int|null $maxAge Max age for client caching - * - * @return $this - */ - final public function maxAge(?int $maxAge) - { - return $this->defaults(['maxAge' => $maxAge]); - } - - /** - * @param int|null $sharedMaxAge Max age for shared (proxy) caching - * - * @return $this - */ - final public function sharedMaxAge(?int $sharedMaxAge) - { - return $this->defaults(['sharedAge' => $sharedMaxAge]); - } - - /** - * @param bool|null $private Whether or not caching should apply for client caches only - * - * @return $this - */ - final public function private(?bool $private = true) - { - return $this->defaults(['private' => $private]); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/Traits/AddTrait.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/Traits/AddTrait.php deleted file mode 100644 index 6647cb4a2754..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/Traits/AddTrait.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits; - -use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RouteConfigurator; -use Symfony\Component\Routing\Loader\Configurator\CollectionConfigurator; -use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator as BaseRouteConfigurator; - -trait AddTrait -{ - /** - * Adds a route. - * - * @param string|array $path the path, or the localized paths of the route - * - * @return RouteConfigurator - */ - public function add(string $name, $path): BaseRouteConfigurator - { - $parentConfigurator = $this instanceof CollectionConfigurator ? $this : ($this instanceof RouteConfigurator ? $this->parentConfigurator : null); - $route = $this->createLocalizedRoute($this->collection, $name, $path, $this->name, $this->prefixes); - - return new RouteConfigurator($this->collection, $route, $this->name, $parentConfigurator, $this->prefixes); - } - - /** - * Adds a route. - * - * @param string|array $path the path, or the localized paths of the route - * - * @return RouteConfigurator - */ - final public function __invoke(string $name, $path): BaseRouteConfigurator - { - return $this->add($name, $path); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/UrlRedirectRouteConfigurator.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/UrlRedirectRouteConfigurator.php deleted file mode 100644 index 4061d5aa0fad..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/Configurator/UrlRedirectRouteConfigurator.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator; - -use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait; -use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator; - -/** - * @author Jules Pietri - */ -class UrlRedirectRouteConfigurator extends RouteConfigurator -{ - use AddTrait; - - /** - * @param bool $permanent Whether the redirection is permanent - * - * @return $this - */ - final public function permanent(bool $permanent = true) - { - return $this->defaults(['permanent' => $permanent]); - } - - /** - * @param string|null $scheme The URL scheme (null to keep the current one) - * @param int|null $port The HTTP or HTTPS port (null to keep the current one for the same scheme or the default configured port) - * - * @return $this - */ - final public function scheme(?string $scheme, int $port = null) - { - $this->defaults(['scheme' => $scheme]); - - if ('http' === $scheme) { - $this->defaults(['httpPort' => $port]); - } elseif ('https' === $scheme) { - $this->defaults(['httpsPort' => $port]); - } - - return $this; - } - - /** - * @param bool $keepRequestMethod Whether redirect action should keep HTTP request method - * - * @return $this - */ - final public function keepRequestMethod(bool $keepRequestMethod = true) - { - return $this->defaults(['keepRequestMethod' => $keepRequestMethod]); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/PhpFileLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/PhpFileLoader.php deleted file mode 100644 index 0265612b88d7..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Loader/PhpFileLoader.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Routing\Loader; - -use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator; -use Symfony\Component\Routing\Loader\PhpFileLoader as BasePhpFileLoader; -use Symfony\Component\Routing\RouteCollection; - -/** - * @author Jules Pietri - */ -class PhpFileLoader extends BasePhpFileLoader -{ - protected function callConfigurator(callable $result, string $path, string $file): RouteCollection - { - $collection = new RouteCollection(); - - $result(new RoutingConfigurator($collection, $this, $path, $file)); - - return $collection; - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/config/routing/routes.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/config/routing/routes.php deleted file mode 100644 index eaa8affaaba1..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/config/routing/routes.php +++ /dev/null @@ -1,45 +0,0 @@ -add('classic_route', '/classic'); - - $routes->add('template_route', '/static') - ->template('static.html.twig', ['foo' => 'bar']) - ->maxAge(300) - ->sharedMaxAge(100) - ->private() - ->methods(['GET']) - ->utf8() - ->condition('abc') - ; - $routes->add('redirect_route', '/redirect') - ->redirectToRoute('target_route') - ->permanent() - ->ignoreAttributes(['attr', 'ibutes']) - ->keepRequestMethod() - ->keepQueryParams() - ->schemes(['http']) - ->host('legacy') - ->utf8() - ; - $routes->add('url_redirect_route', '/redirect-url') - ->redirectToUrl('/url-target') - ->permanent() - ->scheme('http', 1) - ->keepRequestMethod() - ->host('legacy') - ->utf8() - ; - $routes->add('not_a_route', '/not-a-path') - ->gone() - ->host('legacy') - ->utf8() - ; - $routes->add('gone_route', '/gone-path') - ->gone() - ->permanent() - ->utf8() - ; -}; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Loader/AbstractLoaderTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Loader/AbstractLoaderTest.php deleted file mode 100644 index 12a832a37cdb..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Loader/AbstractLoaderTest.php +++ /dev/null @@ -1,116 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Tests\Routing\Loader; - -use Symfony\Bundle\FrameworkBundle\Controller\RedirectController; -use Symfony\Bundle\FrameworkBundle\Controller\TemplateController; -use Symfony\Bundle\FrameworkBundle\Tests\TestCase; -use Symfony\Component\Config\FileLocator; -use Symfony\Component\Config\FileLocatorInterface; -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\RouteCollection; - -abstract class AbstractLoaderTest extends TestCase -{ - /** @var LoaderInterface */ - protected $loader; - - abstract protected function getLoader(): LoaderInterface; - - abstract protected function getType(): string; - - protected function setUp(): void - { - $this->loader = $this->getLoader(); - } - - protected function tearDown(): void - { - $this->loader = null; - } - - public function getLocator(): FileLocatorInterface - { - return new FileLocator([__DIR__.'/../../Fixtures/Resources/config/routing']); - } - - public function testRoutesAreLoaded() - { - $routeCollection = $this->loader->load('routes.'.$this->getType()); - - $expectedCollection = new RouteCollection(); - - $expectedCollection->add('classic_route', (new Route('/classic'))); - - $expectedCollection->add('template_route', (new Route('/static')) - ->setDefaults([ - '_controller' => TemplateController::class, - 'context' => ['foo' => 'bar'], - 'template' => 'static.html.twig', - 'maxAge' => 300, - 'sharedAge' => 100, - 'private' => true, - ]) - ->setMethods(['GET']) - ->setOptions(['utf8' => true]) - ->setCondition('abc') - ); - $expectedCollection->add('redirect_route', (new Route('/redirect')) - ->setDefaults([ - '_controller' => RedirectController::class.'::redirectAction', - 'route' => 'target_route', - 'permanent' => true, - 'ignoreAttributes' => ['attr', 'ibutes'], - 'keepRequestMethod' => true, - 'keepQueryParams' => true, - ]) - ->setSchemes(['http']) - ->setHost('legacy') - ->setOptions(['utf8' => true]) - ); - $expectedCollection->add('url_redirect_route', (new Route('/redirect-url')) - ->setDefaults([ - '_controller' => RedirectController::class.'::urlRedirectAction', - 'path' => '/url-target', - 'permanent' => true, - 'scheme' => 'http', - 'httpPort' => 1, - 'keepRequestMethod' => true, - ]) - ->setHost('legacy') - ->setOptions(['utf8' => true]) - ); - $expectedCollection->add('not_a_route', (new Route('/not-a-path')) - ->setDefaults([ - '_controller' => RedirectController::class.'::redirectAction', - 'route' => '', - ]) - ->setHost('legacy') - ->setOptions(['utf8' => true]) - ); - $expectedCollection->add('gone_route', (new Route('/gone-path')) - ->setDefaults([ - '_controller' => RedirectController::class.'::redirectAction', - 'route' => '', - 'permanent' => true, - ]) - ->setOptions(['utf8' => true]) - ); - $expectedCollection->addResource(new FileResource(realpath( - __DIR__.'/../../Fixtures/Resources/config/routing/routes.'.$this->getType() - ))); - - $this->assertEquals($expectedCollection, $routeCollection); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Loader/PhpFileLoaderTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Loader/PhpFileLoaderTest.php deleted file mode 100644 index 196233b5d11b..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Loader/PhpFileLoaderTest.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Tests\Routing\Loader; - -use Symfony\Bundle\FrameworkBundle\Routing\Loader\PhpFileLoader; -use Symfony\Component\Config\Loader\LoaderInterface; - -class PhpFileLoaderTest extends AbstractLoaderTest -{ - protected function getLoader(): LoaderInterface - { - return new PhpFileLoader($this->getLocator()); - } - - protected function getType(): string - { - return 'php'; - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index c39184c8ce7e..9a10e0d7de5b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -83,7 +83,6 @@ "symfony/messenger": "<4.4", "symfony/mime": "<4.4", "symfony/property-info": "<4.4", - "symfony/routing": "<5.1", "symfony/serializer": "<4.4", "symfony/stopwatch": "<4.4", "symfony/translation": "<5.0", diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index 12f437341d15..4599ee75b5a7 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -104,33 +104,31 @@ public function supports($resource, string $type = null) /** * Parses a route and adds it to the RouteCollection. * - * @param \DOMElement $node Element to parse that represents a Route - * @param string $filepath Full path of the XML file being processed + * @param \DOMElement $node Element to parse that represents a Route + * @param string $path Full path of the XML file being processed * * @throws \InvalidArgumentException When the XML is invalid */ - protected function parseRoute(RouteCollection $collection, \DOMElement $node, string $filepath) + protected function parseRoute(RouteCollection $collection, \DOMElement $node, string $path) { if ('' === $id = $node->getAttribute('id')) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must have an "id" attribute.', $filepath)); + throw new \InvalidArgumentException(sprintf('The element in file "%s" must have an "id" attribute.', $path)); } $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, $condition, $paths, /* $prefixes */, $hosts) = $this->parseConfigs($node, $filepath); - - $path = $node->getAttribute('path'); + list($defaults, $requirements, $options, $condition, $paths, /* $prefixes */, $hosts) = $this->parseConfigs($node, $path); - if (!$paths && '' === $path) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must have a "path" attribute or child nodes.', $filepath)); + if (!$paths && '' === $node->getAttribute('path')) { + throw new \InvalidArgumentException(sprintf('The element in file "%s" must have a "path" attribute or child nodes.', $path)); } - if ($paths && '' !== $path) { - throw new \InvalidArgumentException(sprintf('The element in file "%s" must not have both a "path" attribute and child nodes.', $filepath)); + if ($paths && '' !== $node->getAttribute('path')) { + throw new \InvalidArgumentException(sprintf('The element in file "%s" must not have both a "path" attribute and child nodes.', $path)); } - $routes = $this->createLocalizedRoute($collection, $id, $paths ?: $path); + $routes = $this->createLocalizedRoute($collection, $id, $paths ?: $node->getAttribute('path')); $routes->addDefaults($defaults); $routes->addRequirements($requirements); $routes->addOptions($options);