Skip to content

Commit e648856

Browse files
committed
Merge branch '3.4'
* 3.4: (31 commits) Using FQ name for PHP_VERSION_ID [EventDispatcher] Handle laziness internally instead of relying on ClosureProxyArgument Fix CacheCollectorPass priority [Form] Fix \IntlDateFormatter timezone parameter usage to bypass PHP bug #66323 [Routing] Allow GET requests to be redirected. Fixes #23004 [DI] Deal with inlined non-shared services [Cache] Ignore missing annotations.php [DI] Autowiring exception thrown when inlined service is removed Improving deprecation message when hitting the "deprecated type" lookup, but an alias is available Harden the debugging of Twig filters and functions Fixing a bug where an autowiring exception was thrown even when that service was removed Remove extra arg in call to TraceableAdapter::start() Support unknown compiler log format [Config] Allow empty globs Fix decorating TagAware adapters in dev [Profiler] Fix clicking on links inside toggle [Profiler] Fix text selection on exception pages bumped Symfony version to 3.3.1 updated VERSION for 3.3.0 updated CHANGELOG for 3.3.0 ...
2 parents bf8b666 + 6000d01 commit e648856

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

Loader/FileLoader.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,18 @@ public function getLocator()
8383
*/
8484
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
8585
{
86-
if (is_string($resource) && false !== strpbrk($resource, '*?{[')) {
86+
if (is_string($resource) && strlen($resource) !== $i = strcspn($resource, '*?{[')) {
8787
$ret = array();
88-
foreach ($this->glob($resource, false, $_, true) as $path => $info) {
89-
$ret[] = $this->doImport($path, $type, $ignoreErrors, $sourceResource);
88+
$isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/');
89+
foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath) as $path => $info) {
90+
if (null !== $res = $this->doImport($path, $type, $ignoreErrors, $sourceResource)) {
91+
$ret[] = $res;
92+
}
93+
$isSubpath = true;
9094
}
91-
if ($ret) {
92-
return count($ret) > 1 ? $ret : $ret[0];
95+
96+
if ($isSubpath) {
97+
return isset($ret[1]) ? $ret : (isset($ret[0]) ? $ret[0] : null);
9398
}
9499
}
95100

@@ -104,7 +109,7 @@ protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors =
104109
if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
105110
$prefix = $pattern;
106111
$pattern = '';
107-
} elseif (0 === $i) {
112+
} elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) {
108113
$prefix = '.';
109114
$pattern = '/'.$pattern;
110115
} else {

Tests/Loader/FileLoaderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Config\FileLocator;
1516
use Symfony\Component\Config\Loader\FileLoader;
1617
use Symfony\Component\Config\Loader\LoaderResolver;
1718

@@ -74,6 +75,21 @@ public function testImportWithGlobLikeResource()
7475

7576
$this->assertSame('[foo]', $loader->import('[foo]'));
7677
}
78+
79+
public function testImportWithNoGlobMatch()
80+
{
81+
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
82+
$loader = new TestFileLoader($locatorMock);
83+
84+
$this->assertNull($loader->import('./*.abc'));
85+
}
86+
87+
public function testImportWithSimpleGlob()
88+
{
89+
$loader = new TestFileLoader(new FileLocator(__DIR__));
90+
91+
$this->assertSame(__FILE__, strtr($loader->import('FileLoaderTest.*'), '/', DIRECTORY_SEPARATOR));
92+
}
7793
}
7894

7995
class TestFileLoader extends FileLoader

0 commit comments

Comments
 (0)