|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of tenside/core. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Schiffler <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* This project is provided in good faith and hope to be usable by anyone. |
|
12
|
|
|
* |
|
13
|
|
|
* @package tenside/core |
|
14
|
|
|
* @author Christian Schiffler <[email protected]> |
|
15
|
|
|
* @copyright 2015 Christian Schiffler <[email protected]> |
|
16
|
|
|
* @license https://github.com/tenside/core/blob/master/LICENSE MIT |
|
17
|
|
|
* @link https://github.com/tenside/core |
|
18
|
|
|
* @filesource |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Tenside\Core\Config; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Main tenside configuration (abstraction over tenside.json). |
|
25
|
|
|
*/ |
|
26
|
|
|
class TensideJsonConfig extends SourceJson |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Retrieve the secret. |
|
30
|
|
|
* |
|
31
|
|
|
* @return string|null |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getSecret() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->getIfNotNull('secret', null); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Set the secret. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $secret The new secret. |
|
42
|
|
|
* |
|
43
|
|
|
* @return TensideJsonConfig |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setSecret($secret) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->set('secret', (string) $secret); |
|
48
|
|
|
|
|
49
|
|
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Retrieve the domain. |
|
54
|
|
|
* |
|
55
|
|
|
* @return string|null |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getLocalDomain() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getIfNotNull('domain', null); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Set the domain. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $domain The new domain. |
|
66
|
|
|
* |
|
67
|
|
|
* @return TensideJsonConfig |
|
68
|
|
|
*/ |
|
69
|
|
|
public function setLocalDomain($domain) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->set('domain', (string) $domain); |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get the interpreter to use. |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getPhpCliBinary() |
|
82
|
|
|
{ |
|
83
|
|
|
// If defined, override the php-cli interpreter. |
|
84
|
|
|
return $this->getIfNotNull('php_cli', 'php'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Set the interpreter to use. |
|
89
|
|
|
* |
|
90
|
|
|
* @param string $binary The new interpreter to use. |
|
91
|
|
|
* |
|
92
|
|
|
* @return TensideJsonConfig |
|
93
|
|
|
*/ |
|
94
|
|
|
public function setPhpCliBinary($binary) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->set('php_cli', (string) $binary); |
|
97
|
|
|
|
|
98
|
|
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Retrieve the arguments to pass to the php process |
|
103
|
|
|
* |
|
104
|
|
|
* @return array|null |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getPhpCliArguments() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->getIfNotNull('php_cli_arguments', null); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Set the arguments to use. |
|
113
|
|
|
* |
|
114
|
|
|
* @param array $arguments The new arguments to use. |
|
115
|
|
|
* |
|
116
|
|
|
* @return TensideJsonConfig |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setPhpCliArguments($arguments) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->set('php_cli_arguments', (array) $arguments); |
|
121
|
|
|
|
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Add a command line argument. |
|
127
|
|
|
* |
|
128
|
|
|
* @param string $argument The argument to add. |
|
129
|
|
|
* |
|
130
|
|
|
* @return TensideJsonConfig |
|
131
|
|
|
*/ |
|
132
|
|
|
public function addCommandLineArgument($argument) |
|
133
|
|
|
{ |
|
134
|
|
|
$args = (array) $this->getPhpCliArguments(); |
|
135
|
|
|
$this->setPhpCliArguments(array_merge($args, [$argument])); |
|
136
|
|
|
|
|
137
|
|
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Retrieve the additional environment variables. |
|
142
|
|
|
* |
|
143
|
|
|
* @return array|null |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getPhpCliEnvironment() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->getIfNotNull('php_cli_environment', null); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Set the additional environment variables. |
|
152
|
|
|
* |
|
153
|
|
|
* @param array $variables The new arguments to use. |
|
154
|
|
|
* |
|
155
|
|
|
* @return TensideJsonConfig |
|
156
|
|
|
*/ |
|
157
|
|
|
public function setPhpCliEnvironment($variables) |
|
158
|
|
|
{ |
|
159
|
|
|
$this->set('php_cli_environment', (array) $variables); |
|
160
|
|
|
|
|
161
|
|
|
return $this; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Check if forking is available. |
|
166
|
|
|
* |
|
167
|
|
|
* @return string|null |
|
168
|
|
|
*/ |
|
169
|
|
|
public function isForkingAvailable() |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->getIfNotNull('php_can_fork', false); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Set if forking is available. |
|
176
|
|
|
* |
|
177
|
|
|
* @param bool $available The new arguments to use. |
|
178
|
|
|
* |
|
179
|
|
|
* @return TensideJsonConfig |
|
180
|
|
|
*/ |
|
181
|
|
|
public function setForkingAvailable($available) |
|
182
|
|
|
{ |
|
183
|
|
|
$this->set('php_can_fork', (bool) $available); |
|
184
|
|
|
|
|
185
|
|
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Check if force to background is enabled. |
|
190
|
|
|
* |
|
191
|
|
|
* @return string|null |
|
192
|
|
|
*/ |
|
193
|
|
|
public function isForceToBackgroundEnabled() |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->getIfNotNull('php_force_background', false); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Set if force to background is enabled. |
|
200
|
|
|
* |
|
201
|
|
|
* @param bool $enabled The new arguments to use. |
|
202
|
|
|
* |
|
203
|
|
|
* @return TensideJsonConfig |
|
204
|
|
|
*/ |
|
205
|
|
|
public function setForceToBackground($enabled) |
|
206
|
|
|
{ |
|
207
|
|
|
$this->set('php_force_background', (bool) $enabled); |
|
208
|
|
|
|
|
209
|
|
|
return $this; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Obtain a value from if it is set or return the default value otherwise. |
|
214
|
|
|
* |
|
215
|
|
|
* @param string $key The key to obtain. |
|
216
|
|
|
* |
|
217
|
|
|
* @param mixed $default The default value to return if not set. |
|
218
|
|
|
* |
|
219
|
|
|
* @return mixed |
|
220
|
|
|
*/ |
|
221
|
|
|
private function getIfNotNull($key, $default = null) |
|
222
|
|
|
{ |
|
223
|
|
|
return $this->has($key) ? $this->get($key) : $default; |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|