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

Appearance settings

Commit d4ea072

Browse filesBrowse files
[Config] Fix looking for single files in phars with GlobResource
1 parent 265d58a commit d4ea072
Copy full SHA for d4ea072

File tree

3 files changed

+38
-4
lines changed
Filter options

3 files changed

+38
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Resource/GlobResource.php
+13-4Lines 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
throw new \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 = new Finder();
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;
Binary file not shown.

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php
+25Lines 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+
public function testPhar()
213+
{
214+
$s = \DIRECTORY_SEPARATOR;
215+
$cwd = getcwd();
216+
chdir(\dirname(__DIR__).'/Fixtures');
217+
try {
218+
$resource = new GlobResource('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 = new GlobResource("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+
public function testFilePrefix()
231+
{
232+
$resource = new GlobResource(__FILE__, '/**/', true);
233+
$files = array_keys(iterator_to_array($resource));
234+
$this->assertSame([], $files);
235+
}
211236
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.