8000 bug #21833 [Config] Sort "globbed" paths to make them predictable (ni… · symfony/symfony@e2e9c94 · GitHub
[go: up one dir, main page]

Skip to content

Commit e2e9c94

Browse files
committed
bug #21833 [Config] Sort "globbed" paths to make them predictable (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Config] Sort "globbed" paths to make them predictable | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Spotted while reviewing #21832 ping @jakzal FYI Note that glob already sorts its output, and Finder and glob skip dot dirs. Commits ------- ea1deff [Config] Sort "globbed" paths to make them predictable
2 parents 75dffd1 + ea1deff commit e2e9c94

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Symfony/Component/Config/Loader/FileLoader.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,18 @@ protected function glob($resource, $recursive, &$prefix = null, $ignoreErrors =
129129
if (false === strpos($resource, '/**/') && (defined('GLOB_BRACE') || false === strpos($resource, '{'))) {
130130
foreach (glob($prefix.$resource, defined('GLOB_BRACE') ? GLOB_BRACE : 0) as $path) {
131131
if ($recursive && is_dir($path)) {
132-
$flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS;
133-
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, $flags)) as $path => $info) {
132+
$files = iterator_to_array(new \RecursiveIteratorIterator(
133+
new \RecursiveCallbackFilterIterator(
134+
new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
135+
function (\SplFileInfo $file) { return 8000 '.' !== $file->getBasename()[0]; }
136+
),
137+
\RecursiveIteratorIterator::LEAVES_ONLY
138+
));
139+
usort($files, function (\SplFileInfo $a, \SplFileInfo $b) {
140+
return (string) $a > (string) $b ? 1 : -1;
141+
});
142+
143+
foreach ($files as $path => $info) {
134144
if ($info->isFile()) {
135145
yield $path => $info;
136146
}
@@ -154,7 +164,7 @@ protected function glob($resource, $recursive, &$prefix = null, $ignoreErrors =
154164
}
155165

156166
$prefixLen = strlen($prefix);
157-
foreach ($finder->followLinks()->in($prefix) as $path => $info) {
167+
foreach ($finder->followLinks()->sortByName()->in($prefix) as $path => $info) {
158168
if (preg_match($regex, substr($path, $prefixLen)) && $info->isFile()) {
159169
yield $path => $info;
160170
}

0 commit comments

Comments
 (0)
0