-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathConfigFileCollector.php
More file actions
98 lines (81 loc) · 2.49 KB
/
Copy pathConfigFileCollector.php
File metadata and controls
98 lines (81 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* (c) shopware AG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ShopwareCli;
use ShopwareCli\Services\PathProvider\PathProvider;
class ConfigFileCollector
{
/**
* @var PathProvider
*/
private $pathProvider;
public function __construct(PathProvider $pathProvider)
{
$this->pathProvider = $pathProvider;
}
/**
* Iterate the extension directories and return config.yaml files
*
* @return string[]
*/
public function collectConfigFiles()
{
$files = [];
// Load config.yaml.dist as latest - this way the fallback config options are defined
$files[] = $this->pathProvider->getCliToolPath() . '/config.yaml.dist';
$extensionPath = $this->pathProvider->getExtensionPath();
$files = \array_merge($files, $this->iterateVendors($extensionPath));
$files = \array_merge($files, $this->iterateVendors(__DIR__ . '/Extensions'));
// Load user file first. Its config values cannot be overwritten
$userConfig = $this->pathProvider->getConfigPath() . '/config.yaml';
if (\file_exists($userConfig)) {
$files[] = $userConfig;
}
return $files;
}
/**
* @param string $extensionPath
*
* @return string[]
*/
private function iterateVendors($extensionPath): array
{
$files = [];
if (!\is_dir($extensionPath)) {
return [];
}
$iter = new DirectoryFilterIterator(new \DirectoryIterator($extensionPath));
foreach ($iter as $vendorFileInfo) {
$file = $vendorFileInfo->getPathname() . '/config.yaml';
if (\file_exists($file)) {
$files[] = $file;
}
$files = \array_merge(
$files,
$this->iterateExtensions($vendorFileInfo->getPathname())
);
}
return $files;
}
/**
* @param string $vendorPath
*
* @return string[]
*/
private function iterateExtensions($vendorPath): array
{
$files = [];
$iter = new DirectoryFilterIterator(new \DirectoryIterator($vendorPath));
foreach ($iter as $extensionFileInfo) {
$file = $extensionFileInfo->getPathname() . '/config.yaml';
if (\file_exists($file)) {
$files[] = $file;
}
}
return $files;
}
}