Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb136719

Browse files
committed
bug#22985 [Config] Allow empty globs (nicolas-grekas)
This PR was merged into the 3.3 branch.Discussion----------[Config] Allow empty globs| Q | A| ------------- | ---| Branch? | 3.3| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#22950| License | MIT| Doc PR | -This considers globs as valid even if they return no matches when they have a prefix (and when that prefix exists, according to `$ignoreErrors`).This means there is an edge-case:`*.abc` with at least one match is OK, but when it has no match, it falls back to regular import, then usually will fil.But rewriting this to `./*.abc` resolves the ambiguity and turns this into a glob that won't fail if no matches are found.This should provide the expected behavior in most cases (but ambiguous described one of course).Commits-------c5b9c1a [Config] Allow empty globs
2 parentse879945 +c5b9c1a commitb136719

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

‎src/Symfony/Component/Config/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
publicfunctionimport($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-
returncount($ret) >1 ?$ret :$ret[0];
95+
96+
if ($isSubpath) {
97+
returnisset($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 {

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

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

1414
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Config\FileLocator;
1516
useSymfony\Component\Config\Loader\FileLoader;
1617
useSymfony\Component\Config\Loader\LoaderResolver;
1718

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

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

7995
class TestFileLoaderextends FileLoader

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp