Skip to content

Commit a54ecb0

Browse files
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 ------- 217058b [Routing] fix route loading with wildcard, but dir or file is empty
1 parent a054d88 commit a54ecb0

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
3939
final public function import($resource, $type = null, $ignoreErrors = false)
4040
{
4141
$this->loader->setCurrentDir(\dirname($this->path));
42-
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
42+
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file) ?: [];
43+
4344
if (!\is_array($imported)) {
4445
return new ImportConfigurator($this->collection, $imported);
4546
}

src/Symfony/Component/Routing/Loader/XmlFileLoader.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
146146

147147
$this->setCurrentDir(\dirname($path));
148148

149-
$imported = $this->import($resource, ('' !== $type ? $type : null), false, $file);
149+
/** @var RouteCollection[] $imported */
150+
$imported = $this->import($resource, ('' !== $type ? $type : null), false, $file) ?: [];
150151

151152
if (!\is_array($imported)) {
152153
$imported = [$imported];

src/Symfony/Component/Routing/Loader/YamlFileLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected function parseImport(RouteCollection $collection, array $config, $path
158158

159159
$this->setCurrentDir(\dirname($path));
160160

161-
$imported = $this->import($config['resource'], $type, false, $file);
161+
$imported = $this->import($config['resource'], $type, false, $file) ?: [];
162162

163163
if (!\is_array($imported)) {
164164
$imported = [$imported];

0 commit comments

Comments
 (0)