From a54ecb0fae7ea9fbbf9bc9c6f5715d0ec235a9e5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 19 Oct 2019 15:04:41 +0200 Subject: [PATCH] bug #34024 [Routing] fix route loading with wildcard, but dir or file is empty (gseidel) This PR was merged into the 4.3 branch. Discussion ---------- [Routing] fix route loading with wildcard, but dir or file is empty | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | no ticket i see so far | License | MIT In my route config i have something like: ```yaml empty_wildcard: resource: ../controller/empty_wildcard/* prefix: /empty_wildcard ``` But ``empty_wildcard`` is empty or has no route configured. So i had this error: ``Call to a member function addPrefix() on null`` This PR take care if no route is configured, there will be no error. Commits ------- 217058b475 [Routing] fix route loading with wildcard, but dir or file is empty --- .../Routing/Loader/Configurator/RoutingConfigurator.php | 3 ++- src/Symfony/Component/Routing/Loader/XmlFileLoader.php | 3 ++- src/Symfony/Component/Routing/Loader/YamlFileLoader.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php index 7614caea3d..d0cc02d1c3 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php @@ -39,7 +39,8 @@ class RoutingConfigurator final public function import($resource, $type = null, $ignoreErrors = false) { $this->loader->setCurrentDir(\dirname($this->path)); - $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file); + $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file) ?: []; + if (!\is_array($imported)) { return new ImportConfigurator($this->collection, $imported); } diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index c114310fc3..29dfdb1665 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -146,7 +146,8 @@ class XmlFileLoader extends FileLoader $this->setCurrentDir(\dirname($path)); - $imported = $this->import($resource, ('' !== $type ? $type : null), false, $file); + /** @var RouteCollection[] $imported */ + $imported = $this->import($resource, ('' !== $type ? $type : null), false, $file) ?: []; if (!\is_array($imported)) { $imported = [$imported]; diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index bc21e9cb4d..568827695b 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -158,7 +158,7 @@ class YamlFileLoader extends FileLoader $this->setCurrentDir(\dirname($path)); - $imported = $this->import($config['resource'], $type, false, $file); + $imported = $this->import($config['resource'], $type, false, $file) ?: []; if (!\is_array($imported)) { $imported = [$imported];