8000 [Config] Fallback to regular import when glob fails · symfony/symfony@29802a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 29802a2

Browse files
[Config] Fallback to regular import when glob fails
1 parent daac6db commit 29802a2

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/Symfony/Component/Config/Loader/FileLoader.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,17 @@ public function getLocator()
8383
*/
8484
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
8585
{
86-
$ret = array();
87-
$ct = 0;
88-
if (!is_string($resource) || false === strpbrk($resource, '*?{[')) {
89-
$ret[] = $this->doImport($resource, $type, $ignoreErrors, $sourceResource);
90-
} else {
91-
foreach ($this->glob($resource, false, $_, $ignoreErrors) as $path => $info) {
92-
++$ct;
86+
if (is_string($resource) && false !== strpbrk($resource, '*?{[')) {
87+
$ret = array();
88+
foreach ($this->glob($resource, false, $_, true) as $path => $info) {
9389
$ret[] = $this->doImport($path, $type, $ignoreErrors, $sourceResource);
9490
}
91+
if ($ret) {
92+
return count($ret) > 1 ? $ret : $ret[0];
93+
}
9594
}
9695

97-
return $ct > 1 ? $ret : (isset($ret[0]) ? $ret[0] : null);
96+
return $this->doImport($resource, $type, $ignoreErrors, $sourceResource);
9897
}
9998

10099
/**

src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ public function testImportWithFileLocatorDelegation()
6666
$this->assertInstanceOf('Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException', $e, '->import() throws a FileLoaderImportCircularReferenceException if the resource is already loading');
6767
}
6868
}
69+
70+
public function testImportWithGlobLikeResource()
71+
{
72+
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
73+
$loader = new TestFileLoader($locatorMock);
74+
75+
$this->assertSame('[foo]', $loader->import('[foo]'));
76+
}
6977
}
7078

7179
class TestFileLoader extends FileLoader

0 commit comments

Comments
 (0)
0