[Config] Allow empty globs
This commit is contained in:
parent
adc39a2f57
commit
c5b9c1a8c8
@ -83,13 +83,18 @@ abstract class FileLoader extends Loader
|
|||||||
*/
|
*/
|
||||||
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
|
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();
|
$ret = array();
|
||||||
foreach ($this->glob($resource, false, $_, true) as $path => $info) {
|
$isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/');
|
||||||
$ret[] = $this->doImport($path, $type, $ignoreErrors, $sourceResource);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +109,7 @@ abstract class FileLoader extends Loader
|
|||||||
if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
|
if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
|
||||||
$prefix = $pattern;
|
$prefix = $pattern;
|
||||||
$pattern = '';
|
$pattern = '';
|
||||||
} elseif (0 === $i) {
|
} elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) {
|
||||||
$prefix = '.';
|
$prefix = '.';
|
||||||
$pattern = '/'.$pattern;
|
$pattern = '/'.$pattern;
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Config\Tests\Loader;
|
namespace Symfony\Component\Config\Tests\Loader;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\Config\Loader\FileLoader;
|
use Symfony\Component\Config\Loader\FileLoader;
|
||||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||||
|
|
||||||
@ -74,6 +75,21 @@ class FileLoaderTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame('[foo]', $loader->import('[foo]'));
|
$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
|
class TestFileLoader extends FileLoader
|
||||||
|
Reference in New Issue
Block a user