1 | <?php declare(strict_types=1); |
||
18 | class ProcessEnvironment |
||
19 | { |
||
20 | /** |
||
21 | * @var ValueProvider[] |
||
22 | */ |
||
23 | private $constants; |
||
24 | |||
25 | /** |
||
26 | * @var ValueProvider[] |
||
27 | */ |
||
28 | private $variables; |
||
29 | |||
30 | /** |
||
31 | * @var Template[] |
||
32 | */ |
||
33 | private $templates; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | private $dotenvVariables; |
||
39 | |||
40 | /** |
||
41 | * @param array $constants |
||
42 | * @param array $variables |
||
43 | * @param array $templates |
||
44 | * @param ScriptsPath[] $dotenvPaths |
||
45 | */ |
||
46 | public function __construct(array $constants, array $variables, array $templates, array $dotenvPaths) |
||
47 | { |
||
48 | $this->constants = $this->initializeConstants($constants); |
||
49 | $this->variables = $this->initializeVariables($variables); |
||
50 | $this->templates = $this->initializeTemplates($templates); |
||
51 | $this->dotenvVariables = $this->initializeDotenvVariables($dotenvPaths); |
||
|
|||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param array $constants |
||
56 | * @return ValueProvider[] |
||
57 | */ |
||
58 | private function initializeConstants(array $constants): array |
||
59 | { |
||
60 | $resolvedValues = []; |
||
61 | foreach ($constants as $name => $value) { |
||
62 | $resolvedValues[$name] = new SimpleValueProvider((string) $value); |
||
63 | } |
||
64 | |||
65 | return $resolvedValues; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param array $variables |
||
70 | * @return ValueProvider[] |
||
71 | */ |
||
72 | private function initializeVariables(array $variables): array |
||
73 | { |
||
74 | $resolvedVariables = []; |
||
75 | foreach ($variables as $name => $shellCommand) { |
||
76 | $process = $this->createProcess($shellCommand); |
||
77 | $resolvedVariables[$name] = new ProcessValueProvider($process); |
||
78 | } |
||
79 | |||
80 | return $resolvedVariables; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param DotenvFile[] $dotenvPaths |
||
85 | * @return ValueProvider[] |
||
86 | */ |
||
87 | private function initializeDotenvVariables(array $dotenvPaths): array |
||
88 | { |
||
89 | $variables = []; |
||
90 | |||
91 | foreach ($dotenvPaths as $dotenvPath) { |
||
92 | $dotenvVariables = $this->loadDotenvVariables($dotenvPath); |
||
93 | |||
94 | foreach ($dotenvVariables as $variableKey => $variableValue) { |
||
95 | $variables[$variableKey] = new SimpleValueProvider($variableValue); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | return $variables; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param array $templates |
||
104 | * @return Template[] |
||
105 | */ |
||
106 | private function initializeTemplates(array $templates): array |
||
107 | { |
||
108 | $resolvedVariables = []; |
||
109 | foreach ($templates as $template) { |
||
110 | $resolvedVariables[] = new Template($template['source'], $template['destination']); |
||
111 | } |
||
112 | |||
113 | return $resolvedVariables; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @return ValueProvider[] |
||
118 | */ |
||
119 | public function getAllValues(): array |
||
120 | { |
||
121 | return array_merge( |
||
122 | $this->constants, |
||
123 | $this->dotenvVariables, |
||
124 | $this->variables |
||
125 | ); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @return Template[] |
||
130 | */ |
||
131 | public function getTemplates(): array |
||
132 | { |
||
133 | return $this->templates; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @param string $shellCommand |
||
138 | * @return Process |
||
139 | */ |
||
140 | public function createProcess(string $shellCommand): Process |
||
141 | { |
||
142 | return new Process($shellCommand); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @param DotenvFile $dotenvPath |
||
147 | * @return array |
||
148 | */ |
||
149 | private function loadDotenvVariables(DotenvFile $dotenvPath): array |
||
156 | |||
157 | /** |
||
158 | * @param DotenvFile $dotenvPath |
||
159 | * @param DotenvFactory $dotenvFactory |
||
160 | * @return array |
||
161 | */ |
||
162 | private function loadDotenvFile(DotenvFile $dotenvPath, DotenvFactory $dotenvFactory): array |
||
173 | |||
174 | /** |
||
175 | * @param array $fileData |
||
176 | * @param DotenvFactory $dotenvFactory |
||
177 | * @return array |
||
178 | */ |
||
179 | private function diffDotenvVarsWithEnv(array $fileData, DotenvFactory $dotenvFactory): array |
||
191 | } |
||
192 |
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: