1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Psh\ScriptRuntime\Execution; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Process\Process; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Create representation of the current environment variables and constants |
9
|
|
|
*/ |
10
|
|
|
class ProcessEnvironment |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var ValueProvider[] |
14
|
|
|
*/ |
15
|
|
|
private $constants; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var ValueProvider[] |
19
|
|
|
*/ |
20
|
|
|
private $variables; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Template[] |
24
|
|
|
*/ |
25
|
|
|
private $templates; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param array $constants |
29
|
|
|
* @param array $variables |
30
|
|
|
* @param array $templates |
31
|
|
|
*/ |
32
|
|
|
public function __construct(array $constants, array $variables, array $templates) |
33
|
|
|
{ |
34
|
|
|
$this->constants = $this->initializeConstants($constants); |
35
|
|
|
$this->variables = $this->initializeVariables($variables); |
36
|
|
|
$this->templates = $this->initializeTemplates($templates); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param array $constants |
41
|
|
|
* @return ValueProvider[] |
42
|
|
|
*/ |
43
|
|
|
private function initializeConstants(array $constants): array |
44
|
|
|
{ |
45
|
|
|
$resolvedValues = []; |
46
|
|
|
foreach ($constants as $name => $value) { |
47
|
|
|
$resolvedValues[$name] = new SimpleValueProvider((string) $value); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $resolvedValues; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $variables |
55
|
|
|
* @return ValueProvider[] |
56
|
|
|
*/ |
57
|
|
|
private function initializeVariables(array $variables): array |
58
|
|
|
{ |
59
|
|
|
$resolvedVariables = []; |
60
|
|
|
foreach ($variables as $name => $shellCommand) { |
61
|
|
|
$process = $this->createProcess($shellCommand); |
62
|
|
|
$resolvedVariables[$name] = new ProcessValueProvider($process); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $resolvedVariables; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param array $templates |
70
|
|
|
* @return ValueProvider[] |
71
|
|
|
*/ |
72
|
|
|
private function initializeTemplates(array $templates): array |
73
|
|
|
{ |
74
|
|
|
$resolvedVariables = []; |
75
|
|
|
foreach ($templates as $template) { |
76
|
|
|
$resolvedVariables[] = new Template($template['source'], $template['destination']); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $resolvedVariables; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return ValueProvider[] |
84
|
|
|
*/ |
85
|
|
|
public function getAllValues(): array |
86
|
|
|
{ |
87
|
|
|
return array_merge( |
88
|
|
|
$this->constants, |
89
|
|
|
$this->variables |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return Template[] |
95
|
|
|
*/ |
96
|
|
|
public function getTemplates(): array |
97
|
|
|
{ |
98
|
|
|
return $this->templates; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param string $shellCommand |
103
|
|
|
* @return Process |
104
|
|
|
*/ |
105
|
|
|
public function createProcess(string $shellCommand): Process |
106
|
|
|
{ |
107
|
|
|
return new Process($shellCommand); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..