[Config] Fallback to regular import when glob fails

This commit is contained in:
Nicolas Grekas 2017-05-29 10:09:00 +02:00 committed by Fabien Potencier
parent daac6dbb41
commit 7b4066e8ab
2 changed files with 15 additions and 8 deletions

View File

@ -83,18 +83,17 @@ abstract class FileLoader extends Loader
*/
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);
}
/**

View File

@ -66,6 +66,14 @@ class FileLoaderTest extends TestCase
$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