Skip to content

Commit 8b944c1

Browse files
Merge branch '6.0' into 6.1
* 6.0: [VarDumper] fix tests on PHP 8.2 [Mime] Add null check for EmailHeaderSame Add approriate description to CollectionToArrayTransformer::reverseTransform docblock [PropertyInfo] CS fixes [VarDumper] fix test on PHP 8.2 [Config] Fix looking for single files in phars with GlobResource Revert "bug #46327 [HttpKernel] Allow ErrorHandler ^5.0 to be used in HttpKernel 4.4 (mpdude)"
2 parents 6144727 + 203925b commit 8b944c1

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

Resource/GlobResource.php

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

109-
if (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) {
109+
if ('' === $this->pattern && is_file($prefix)) {
110+
$paths = [$this->prefix];
111+
} elseif (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) {
110112
if ($this->globBrace || !str_contains($this->pattern, '{')) {
111113
$paths = glob($this->prefix.$this->pattern, \GLOB_NOSORT | $this->globBrace);
112114
} elseif (!str_contains($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) {
@@ -167,12 +169,19 @@ function (\SplFileInfo $file, $path) {
167169
throw new \LogicException(sprintf('Extended glob pattern "%s" cannot be used as the Finder component is not installed.', $this->pattern));
168170
}
169171

170-
$regex = Glob::toRegex($this->pattern);
172+
if (is_file($prefix = $this->prefix)) {
173+
$prefix = \dirname($prefix);
174+
$pattern = basename($prefix).$this->pattern;
175+
} else {
176+
$pattern = $this->pattern;
177+
}
178+
179+
$regex = Glob::toRegex($pattern);
171180
if ($this->recursive) {
172181
$regex = substr_replace($regex, '(/|$)', -2, 1);
173182
}
174183

175-
$prefixLen = \strlen($this->prefix);
184+
$prefixLen = \strlen($prefix);
176185

177186
yield from (new Finder())
178187
->followLinks()
@@ -190,7 +199,7 @@ function (\SplFileInfo $file, $path) {
190199
}
191200
})
192201
->sortByName()
193-
->in($this->prefix)
202+
->in($prefix)
194203
;
195204
}
196205

Tests/Fixtures/some.phar

1.16 KB
Binary file not shown.

Tests/Resource/GlobResourceTest.php

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

206206
$this->assertEquals($p->getValue($resource), $p->getValue($newResource));
207207
}
208+
209+
public function testPhar()
210+
{
211+
$s = \DIRECTORY_SEPARATOR;
212+
$cwd = getcwd();
213+
chdir(\dirname(__DIR__).'/Fixtures');
214+
try {
215+
$resource = new GlobResource('phar://some.phar', '*', true);
216+
$files = array_keys(iterator_to_array($resource));
217+
$this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", "phar://some.phar{$s}schema{$s}project-1.0.xsd"], $files);
218+
219+
$resource = new GlobResource("phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", '', true);
220+
$files = array_keys(iterator_to_array($resource));
221+
$this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php"], $files);
222+
} finally {
223+
chdir($cwd);
224+
}
225+
}
226+
227+
public function testFilePrefix()
228+
{
229+
$resource = new GlobResource(__FILE__, '/**/', true);
230+
$files = array_keys(iterator_to_array($resource));
231+
$this->assertSame([], $files);
232+
}
208233
}

0 commit comments

Comments
 (0)