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

Commitd4ea072

Browse files
[Config] Fix looking for single files in phars with GlobResource
1 parent265d58a commitd4ea072

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

‎src/Symfony/Component/Config/Resource/GlobResource.php‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ public function getIterator()
111111
$prefix =str_replace('\\','/',$this->prefix);
112112
$paths =null;
113113

114-
if (!str_starts_with($this->prefix,'phar://') && !str_contains($this->pattern,'/**/')) {
114+
if ('' ===$this->pattern &&is_file($prefix)) {
115+
$paths = [$this->prefix];
116+
}elseif (!str_starts_with($this->prefix,'phar://') && !str_contains($this->pattern,'/**/')) {
115117
if ($this->globBrace || !str_contains($this->pattern,'{')) {
116118
$paths =glob($this->prefix.$this->pattern, \GLOB_NOSORT |$this->globBrace);
117119
}elseif (!str_contains($this->pattern,'\\') || !preg_match('/\\\\[,{}]/',$this->pattern)) {
@@ -172,14 +174,21 @@ function (\SplFileInfo $file, $path) {
172174
thrownew \LogicException(sprintf('Extended glob pattern "%s" cannot be used as the Finder component is not installed.',$this->pattern));
173175
}
174176

177+
if (is_file($prefix =$this->prefix)) {
178+
$prefix =\dirname($prefix);
179+
$pattern =basename($prefix).$this->pattern;
180+
}else {
181+
$pattern =$this->pattern;
182+
}
183+
175184
$finder =newFinder();
176-
$regex = Glob::toRegex($this->pattern);
185+
$regex = Glob::toRegex($pattern);
177186
if ($this->recursive) {
178187
$regex =substr_replace($regex,'(/|$)', -2,1);
179188
}
180189

181-
$prefixLen =\strlen($this->prefix);
182-
foreach ($finder->followLinks()->sortByName()->in($this->prefix)as$path =>$info) {
190+
$prefixLen =\strlen($prefix);
191+
foreach ($finder->followLinks()->sortByName()->in($prefix)as$path =>$info) {
183192
$normalizedPath =str_replace('\\','/',$path);
184193
if (!preg_match($regex,substr($normalizedPath,$prefixLen)) || !$info->isFile()) {
185194
continue;
1.16 KB
Binary file not shown.

‎src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,29 @@ public function testSerializeUnserialize()
208208

209209
$this->assertEquals($p->getValue($resource),$p->getValue($newResource));
210210
}
211+
212+
publicfunctiontestPhar()
213+
{
214+
$s = \DIRECTORY_SEPARATOR;
215+
$cwd =getcwd();
216+
chdir(\dirname(__DIR__).'/Fixtures');
217+
try {
218+
$resource =newGlobResource('phar://some.phar','*',true);
219+
$files =array_keys(iterator_to_array($resource));
220+
$this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php","phar://some.phar{$s}schema{$s}project-1.0.xsd"],$files);
221+
222+
$resource =newGlobResource("phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php",'',true);
223+
$files =array_keys(iterator_to_array($resource));
224+
$this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php"],$files);
225+
}finally {
226+
chdir($cwd);
227+
}
228+
}
229+
230+
publicfunctiontestFilePrefix()
231+
{
232+
$resource =newGlobResource(__FILE__,'/**/',true);
233+
$files =array_keys(iterator_to_array($resource));
234+
$this->assertSame([],$files);
235+
}
211236
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp