Skip to content

Commit

Permalink
Merge branch '3.3' into 3.4
Browse files Browse the repository at this point in the history
* 3.3: (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
  ...
  • Loading branch information
fabpot committed Jun 1, 2017
2 parents cd28548 + f6780ab commit 6000d01
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Loader/FileLoader.php
Expand Up @@ -83,13 +83,18 @@ public function getLocator()
*/
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
{
if (is_string($resource) && false !== strpbrk($resource, '*?{[')) {
if (is_string($resource) && strlen($resource) !== $i = strcspn($resource, '*?{[')) {
$ret = array();
foreach ($this->glob($resource, false, $_, true) as $path => $info) {
$ret[] = $this->doImport($path, $type, $ignoreErrors, $sourceResource);
$isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/');
foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath) as $path => $info) {
if (null !== $res = $this->doImport($path, $type, $ignoreErrors, $sourceResource)) {
$ret[] = $res;
}
$isSubpath = true;
}
if ($ret) {
return count($ret) > 1 ? $ret : $ret[0];

if ($isSubpath) {
return isset($ret[1]) ? $ret : (isset($ret[0]) ? $ret[0] : null);
}
}

Expand All @@ -104,7 +109,7 @@ protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors =
if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
$prefix = $pattern;
$pattern = '';
} elseif (0 === $i) {
} elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) {
$prefix = '.';
$pattern = '/'.$pattern;
} else {
Expand Down
16 changes: 16 additions & 0 deletions Tests/Loader/FileLoaderTest.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Config\Tests\Loader;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\FileLoader;
use Symfony\Component\Config\Loader\LoaderResolver;

Expand Down Expand Up @@ -74,6 +75,21 @@ public function testImportWithGlobLikeResource()

$this->assertSame('[foo]', $loader->import('[foo]'));
}

public function testImportWithNoGlobMatch()
{
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
$loader = new TestFileLoader($locatorMock);

$this->assertNull($loader->import('./*.abc'));
}

public function testImportWithSimpleGlob()
{
$loader = new TestFileLoader(new FileLocator(__DIR__));

$this->assertSame(__FILE__, strtr($loader->import('FileLoaderTest.*'), '/', DIRECTORY_SEPARATOR));
}
}

class TestFileLoader extends FileLoader
Expand Down

0 comments on commit 6000d01

Please sign in to comment.