1 | <?php declare(strict_types=1); |
||
10 | class ConfigBuilder |
||
11 | { |
||
12 | const DEFAULT_ENV = '##default##'; |
||
13 | |||
14 | private $header = ''; |
||
15 | |||
16 | private $environments = []; |
||
17 | |||
18 | private $currentEnvironment; |
||
19 | |||
20 | private $currentCommandPaths; |
||
21 | |||
22 | private $currentDotenvPaths; |
||
23 | |||
24 | private $currentDynamicVariables; |
||
25 | |||
26 | private $templates; |
||
27 | |||
28 | private $currentConstants; |
||
29 | |||
30 | /** |
||
31 | * @param string|null $header |
||
32 | * @return ConfigBuilder |
||
33 | */ |
||
34 | public function setHeader(string $header = null): ConfigBuilder |
||
35 | { |
||
36 | $this->header = $header; |
||
37 | return $this; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param string|null $environment |
||
42 | * @return ConfigBuilder |
||
43 | */ |
||
44 | public function start(string $environment = null): ConfigBuilder |
||
45 | { |
||
46 | $this->reset(); |
||
47 | if (!$environment) { |
||
|
|||
48 | $environment = self::DEFAULT_ENV; |
||
49 | } |
||
50 | |||
51 | $this->currentEnvironment = $environment; |
||
52 | return $this; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param array $commandPaths |
||
57 | * @return ConfigBuilder |
||
58 | */ |
||
59 | public function setCommandPaths(array $commandPaths): ConfigBuilder |
||
60 | { |
||
61 | $this->currentCommandPaths = $commandPaths; |
||
62 | return $this; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param array $dotenvPaths |
||
67 | * @return ConfigBuilder |
||
68 | */ |
||
69 | public function setDotenvPaths(array $dotenvPaths): ConfigBuilder |
||
70 | { |
||
71 | $this->currentDotenvPaths = $dotenvPaths; |
||
72 | return $this; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param array $dynamicVariables |
||
77 | * @return ConfigBuilder |
||
78 | */ |
||
79 | public function setDynamicVariables(array $dynamicVariables): ConfigBuilder |
||
80 | { |
||
81 | $this->currentDynamicVariables = $dynamicVariables; |
||
82 | return $this; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @param array $constants |
||
87 | * @return ConfigBuilder |
||
88 | */ |
||
89 | public function setConstants(array $constants): ConfigBuilder |
||
90 | { |
||
91 | $this->currentConstants = $constants; |
||
92 | return $this; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @param array $templates |
||
97 | * @return ConfigBuilder |
||
98 | */ |
||
99 | public function setTemplates(array $templates): ConfigBuilder |
||
104 | |||
105 | /** |
||
106 | * @return Config |
||
107 | */ |
||
108 | public function create(array $params): Config |
||
114 | |||
115 | private function reset() |
||
116 | { |
||
117 | if ($this->currentEnvironment) { |
||
118 | $this->environments[$this->currentEnvironment] = new ConfigEnvironment( |
||
119 | $this->currentCommandPaths, |
||
120 | $this->currentDynamicVariables, |
||
133 | } |
||
134 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: