Skip to content

Commit

Permalink
bug #34024 [Routing] fix route loading with wildcard, but dir or file…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
nicolas-grekas committed Oct 19, 2019
1 parent a054d88 commit a54ecb0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Expand Up @@ -39,7 +39,8 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Expand Up @@ -146,7 +146,8 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $

$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];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Loader/YamlFileLoader.php
Expand Up @@ -158,7 +158,7 @@ protected function parseImport(RouteCollection $collection, array $config, $path

$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];
Expand Down

0 comments on commit a54ecb0

Please sign in to comment.