8000 Keep existing behaviour when loading a config and the glob doesn't match · symfony/symfony@1a5955b · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a5955b

Browse files
committed
Keep existing behaviour when loading a config and the glob doesn't match
1 parent 429163f commit 1a5955b

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

src/Symfony/Component/Config/FileLocator.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ public function locate($name, $currentPath = null, $first = true)
4242
}
4343

4444
if ($this->isAbsolutePath($name)) {
45-
if (array() === $files = glob($name, GLOB_BRACE)) {
45+
if (file_exists($name)) {
46+
return $name;
47+
}
48+
49+
if (array() === $files = glob($name, defined('GLOB_BRACE') ? GLOB_BRACE : 0)) {
4650
throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist.', $name));
4751
}
4852

49-
if ($first) {
53+
if (true === $first) {
5054
return array_shift($files);
5155
}
5256

@@ -62,28 +66,20 @@ public function locate($name, $currentPath = null, $first = true)
6266
$paths = array_unique($paths);
6367
$filepaths = array();
6468

65-
$load = function ($file) use (&$filepaths) {
66-
if (@file_exists($file)) {
67-
$filepaths[] = $file;
68-
}
69-
};
70-
7169
foreach ($paths as $path) {
72-
if (array() !== $files = glob($path.DIRECTORY_SEPARATOR.$name)) {
73-
array_walk($files, $load);
74-
} else {
75-
$load($path.DIRECTORY_SEPARATOR.$name);
70+
$files = glob($path.DIRECTORY_SEPARATOR.$name, defined('GLOB_BRACE') ? GLOB_BRACE : 0);
71+
72+
if (true === $first && $files) {
73+
return array_shift($files);
7674
}
75+
76+
$filepaths = array_merge($filepaths, $files);
7777
}
7878

7979
if (!$filepaths) {
8080
throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
8181
}
8282

83-
if (true === $first) {
84-
return array_shift($filepaths);
85-
}
86-
8783
return $filepaths;
8884
}
8985

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ private function parseImports(\DOMDocument $xml, $file)
112112
$resourceFile = $defaultDirectory.DIRECTORY_SEPARATOR.$resourceFile;
113113
}
114114

115-
$files = glob($resourceFile, GLOB_BRACE);
116-
117-
foreach ($files as $resource) {
118-
$this->import($resource, XmlUtils::phpize($import->getAttribute('type')) ?: null, (bool) XmlUtils::phpize($import->getAttribute('ignore-errors')), $file);
115+
$type = XmlUtils::phpize($import->getAttribute('type')) ?: null;
116+
$ignoreErrors = (bool) XmlUtils::phpize($import->getAttribute('ignore-errors'));
117+
if (array() !== $files = glob($resourceFile, defined('GLOB_BRACE') ? GLOB_BRACE : 0)) {
118+
foreach ($files as $resource) {
119+
$this->import($resource, $type, $ignoreErrors, $file);
120+
}
121+
} else {
122+
$this->import($resourceFile, $type, $ignoreErrors, $file);
119123
}
120124
}
121125
}

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@ private function parseImports($content, $file)
143143
$import['resource'] = $defaultDirectory.DIRECTORY_SEPARATOR.$import['resource'];
144144
}
145145

146-
$files = glob($import['resource'], GLOB_BRACE);
147-
148-
foreach ($files as $resource) {
149-
$this->import($resource, isset($import['type']) ? $import['type'] : null, isset($import['ignore_errors']) ? (bool) $import['ignore_errors'] : false, $file);
146+
$type = isset($import['type']) ? $import['type'] : null;
147+
$ignoreErrors = isset($import['ignore_errors']) ? (bool) $import['ignore_errors'] : false;
148+
if (array() !== $files = glob($import['resource'], defined('GLOB_BRACE') ? GLOB_BRACE : 0)) {
149+
foreach ($files as $resource) {
150+
$this->import($resource, $type, $ignoreErrors, $file);
151+
}
152+
} else {
153+
$this->import($import['resource'], $type, $ignoreErrors, $file);
150154
}
151155
}
152156
}

0 commit comments

Comments
 (0)
0