Permalink
Browse files

bug #22940 [Config] Fallback to regular import when glob fails (nicol…

…as-grekas)

This PR was submitted for the master branch but it was merged into the 3.3 branch instead (closes #22940).

Discussion
----------

[Config] Fallback to regular import when glob fails

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22938
| License       | MIT
| Doc PR        | -

Fixes a BC break as reported in linked issue.

Commits
-------

7b4066e [Config] Fallback to regular import when glob fails
  • Loading branch information...
fabpot committed May 29, 2017
2 parents daac6db + 7b4066e commit f7b09e9bbf52eda1a8d62e0d34149cd9d0d10b88
@@ -83,18 +83,17 @@ public function getLocator()
*/
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
{
$ret = array();
$ct = 0;
if (!is_string($resource) || false === strpbrk($resource, '*?{[')) {
$ret[] = $this->doImport($resource, $type, $ignoreErrors, $sourceResource);
} else {
foreach ($this->glob($resource, false, $_, $ignoreErrors) as $path => $info) {
++$ct;
if (is_string($resource) && false !== strpbrk($resource, '*?{[')) {
$ret = array();
foreach ($this->glob($resource, false, $_, true) as $path => $info) {
$ret[] = $this->doImport($path, $type, $ignoreErrors, $sourceResource);
}
if ($ret) {
return count($ret) > 1 ? $ret : $ret[0];
}
}
return $ct > 1 ? $ret : (isset($ret[0]) ? $ret[0] : null);
return $this->doImport($resource, $type, $ignoreErrors, $sourceResource);
}
/**
@@ -66,6 +66,14 @@ public function testImportWithFileLocatorDelegation()
$this->assertInstanceOf('Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException', $e, '->import() throws a FileLoaderImportCircularReferenceException if the resource is already loading');
}
}
public function testImportWithGlobLikeResource()
{
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
$loader = new TestFileLoader($locatorMock);
$this->assertSame('[foo]', $loader->import('[foo]'));
}
}
class TestFileLoader extends FileLoader

0 comments on commit f7b09e9

Please sign in to comment.