|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Shopware\Psh\Application; |
|
5
|
|
|
|
|
6
|
|
|
use Shopware\Psh\Config\Config; |
|
7
|
|
|
use Shopware\Psh\Config\ConfigBuilder; |
|
8
|
|
|
use Shopware\Psh\Config\ConfigFileFinder; |
|
9
|
|
|
use Shopware\Psh\Config\ConfigMerger; |
|
10
|
|
|
use Shopware\Psh\Config\XmlConfigFileLoader; |
|
11
|
|
|
use Shopware\Psh\Config\YamlConfigFileLoader; |
|
12
|
|
|
use Shopware\Psh\Listing\DescriptionReader; |
|
13
|
|
|
use Shopware\Psh\Listing\Script; |
|
14
|
|
|
use Shopware\Psh\Listing\ScriptFinder; |
|
15
|
|
|
use Shopware\Psh\ScriptRuntime\Command; |
|
16
|
|
|
use Shopware\Psh\ScriptRuntime\Execution\Logger; |
|
17
|
|
|
use Shopware\Psh\ScriptRuntime\Execution\ProcessEnvironment; |
|
18
|
|
|
use Shopware\Psh\ScriptRuntime\Execution\ProcessExecutor; |
|
19
|
|
|
use Shopware\Psh\ScriptRuntime\Execution\TemplateEngine; |
|
20
|
|
|
use Shopware\Psh\ScriptRuntime\ScriptLoader\BashScriptParser; |
|
21
|
|
|
use Shopware\Psh\ScriptRuntime\ScriptLoader\CommandBuilder; |
|
22
|
|
|
use Shopware\Psh\ScriptRuntime\ScriptLoader\PshScriptParser; |
|
23
|
|
|
use Shopware\Psh\ScriptRuntime\ScriptLoader\ScriptLoader; |
|
24
|
|
|
use Symfony\Component\Yaml\Parser; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create the various interdependent objects for the application. |
|
28
|
|
|
*/ |
|
29
|
|
|
class ApplicationFactory |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $rootDirectory |
|
33
|
|
|
* @param array $params |
|
34
|
|
|
* @return Config |
|
35
|
|
|
* @throws \RuntimeException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function createConfig(string $rootDirectory, array $params): Config |
|
38
|
|
|
{ |
|
39
|
|
|
$overwrittenConsts = (new ParameterParser())->parseParams($params); |
|
40
|
|
|
$configFinder = new ConfigFileFinder(); |
|
41
|
|
|
$configFiles = $configFinder->discoverFiles($rootDirectory); |
|
42
|
|
|
|
|
43
|
|
|
$configLoaders = [ |
|
44
|
|
|
new YamlConfigFileLoader(new Parser(), new ConfigBuilder(), $rootDirectory), |
|
45
|
|
|
new XmlConfigFileLoader(new ConfigBuilder(), $rootDirectory), |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$configs = []; |
|
49
|
|
|
foreach ($configFiles as $configFile) { |
|
50
|
|
|
foreach ($configLoaders as $configLoader) { |
|
51
|
|
|
if (!$configLoader->isSupported($configFile)) { |
|
52
|
|
|
continue; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$configs[] = $configLoader->load($configFile, $overwrittenConsts); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (count($configs) === 0) { |
|
60
|
|
|
throw new \RuntimeException('Unable to read any configuration from "' . implode(', ', $configFiles) . '"'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$merger = new ConfigMerger(); |
|
64
|
|
|
|
|
65
|
|
|
return $merger->merge(...$configs); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param Config $config |
|
70
|
|
|
* @return ScriptFinder |
|
71
|
|
|
*/ |
|
72
|
|
|
public function createScriptFinder(Config $config): ScriptFinder |
|
73
|
|
|
{ |
|
74
|
|
|
return new ScriptFinder($config->getAllScriptsPaths(), new DescriptionReader()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param Script $script |
|
79
|
|
|
* @param Config $config |
|
80
|
|
|
* @param Logger $logger |
|
81
|
|
|
* @param string $rootDirectory |
|
82
|
|
|
* @return ProcessExecutor |
|
83
|
|
|
*/ |
|
84
|
|
|
public function createProcessExecutor( |
|
85
|
|
|
Script $script, |
|
86
|
|
|
Config $config, |
|
87
|
|
|
Logger $logger, |
|
88
|
|
|
string $rootDirectory |
|
89
|
|
|
): ProcessExecutor { |
|
90
|
|
|
return new ProcessExecutor( |
|
91
|
|
|
new ProcessEnvironment( |
|
92
|
|
|
$config->getConstants($script->getEnvironment()), |
|
93
|
|
|
$config->getDynamicVariables($script->getEnvironment()), |
|
94
|
|
|
$config->getTemplates($script->getEnvironment()), |
|
95
|
|
|
$config->getDotenvPaths($script->getEnvironment()) |
|
96
|
|
|
), |
|
97
|
|
|
new TemplateEngine(), |
|
98
|
|
|
$logger, |
|
99
|
|
|
$rootDirectory |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param Script $script |
|
105
|
|
|
* @param ScriptFinder $scriptFinder |
|
106
|
|
|
* |
|
107
|
|
|
* @return Command[] |
|
108
|
|
|
*/ |
|
109
|
|
|
public function createCommands(Script $script, ScriptFinder $scriptFinder): array |
|
110
|
|
|
{ |
|
111
|
|
|
$scriptLoader = new ScriptLoader( |
|
112
|
|
|
new BashScriptParser(), |
|
113
|
|
|
new PshScriptParser(new CommandBuilder(), $scriptFinder) |
|
114
|
|
|
); |
|
115
|
|
|
return $scriptLoader->loadScript($script); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param $directory |
|
120
|
|
|
* @return array |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getConfigFiles(string $directory): array |
|
123
|
|
|
{ |
|
124
|
|
|
return (new ConfigFileFinder())->discoverFiles($directory); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: