Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2bf776

Browse files
committed
[DependencyInjection] Add env() and EnvConfigurator in the PHP-DSL
1 parent 3f0f21c commit f2bf776

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
* Add support for per-env configuration in loaders
1313
* Add `ContainerBuilder::willBeAvailable()` to help with conditional configuration
1414
* Add support an integer return value for default_index_method
15+
* Add `env()` and `EnvConfigurator` in the PHP-DSL
1516

1617
5.2.0
1718
-----

src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public static function processValue($value, $allowServices = false)
8383
return $def;
8484
}
8585

86+
if ($value instanceof EnvConfigurator) {
87+
return (string) $value;
88+
}
89+
8690
if ($value instanceof self) {
8791
throw new InvalidArgumentException(sprintf('"%s()" can be used only at the root of service configuration files.', $value::FACTORY));
8892
}

src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,11 @@ function abstract_arg(string $description): AbstractArgument
201201
{
202202
return new AbstractArgument($description);
203203
}
204+
205+
/**
206+
* Creates an environment variable reference.
207+
*/
208+
function env(string $name): EnvConfigurator
209+
{
210+
return new EnvConfigurator($name);
211+
}
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[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+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
class EnvConfigurator
15+
{
16+
/**
17+
* @var string[]
18+
*/
19+
private $stack;
20+
21+
public function __construct(string $name)
22+
{
23+
$this->stack = explode(':', $name);
24+
}
25+
26+
/**
27+
* @return string
28+
*/
29+
public function __toString()
30+
{
31+
return '%env('.implode(':', $this->stack).')%';
32+
}
33+
34+
/**
35+
* @return $this
36+
*/
37+
public function custom(string $processor, ...$args): self
38+
{
39+
array_unshift($this->stack, $processor, ...$args);
40+
41+
return $this;
42+
}
43+
44+
/**
45+
* @return $this
46+
*/
47+
public function base64(): self
48+
{
49+
array_unshift($this->stack, 'base64');
50+
51+
return $this;
52+
}
53+
54+
/**
55+
* @return $this
56+
*/
57+
public function bool(): self
58+
{
59+
array_unshift($this->stack, 'bool');
60+
61+
return $this;
62+
}
63+
64+
/**
65+
* @return $this
66+
*/
67+
public function not(): self
68+
{
69+
array_unshift($this->stack, 'not');
70+
71+
return $this;
72+
}
73+
74+
/**
75+
* @return $this
76+
*/
77+
public function const(): self
78+
{
79+
array_unshift($this->stack, 'const');
80+
81+
return $this;
82+
}
83+
84+
/**
85+
* @return $this
86+
*/
87+
public function csv(): self
88+
{
89+
array_unshift($this->stack, 'csv');
90+
91+
return $this;
92+
}
93+
94+
/**
95+
* @return $this
96+
*/
97+
public function file(): self
98+
{
99+
array_unshift($this->stack, 'file');
100+
101+
return $this;
102+
}
103+
104+
/**
105+
* @return $this
106+
*/
107+
public function float(): self
108+
{
109+
array_unshift($this->stack, 'float');
110+
111+
return $this;
112+
}
113+
114+
/**
115+
* @return $this
116+
*/
117+
public function int(): self
118+
{
119+
array_unshift($this->stack, 'int');
120+
121+
return $this;
122+
}
123+
124+
/**
125+
* @return $this
126+
*/
127+
public function json(): self
128+
{
129+
array_unshift($this->stack, 'json');
130+
131+
return $this;
132+
}
133+
134+
/**
135+
* @return $this
136+
*/
137+
public function key(string $key): self
138+
{
139+
array_unshift($this->stack, 'key', $key);
140+
141+
return $this;
142+
}
143+
144+
/**
145+
* @return $this
146+
*/
147+
public function url(): self
148+
{
149+
array_unshift($this->stack, 'url');
150+
151+
return $this;
152+
}
153+
154+
/**
155+
* @return $this
156+
*/
157+
public function queryString(): self
158+
{
159+
array_unshift($this->stack, 'query_string');
160+
161+
return $this;
162+
}
163+
164+
/**
165+
* @return $this
166+
*/
167+
public function resolve(): self
168+
{
169+
array_unshift($this->stack, 'resolve');
170+
171+
return $this;
172+
}
173+
174+
/**
175+
* @return $this
176+
*/
177+
public function default(string $fallbackParam): self
178+
{
179+
array_unshift($this->stack, 'default', $fallbackParam);
180+
181+
return $this;
182+
}
183+
184+
/**
185+
* @return $this
186+
*/
187+
public function string(): self
188+
{
189+
array_unshift($this->stack, 'string');
190+
191+
return $this;
192+
}
193+
194+
/**
195+
* @return $this
196+
*/
197+
public function trim(): self
198+
{
199+
array_unshift($this->stack, 'trim');
200+
201+
return $this;
202+
}
203+
204+
/**
205+
* @return $this
206+
*/
207+
public function require(): self
208+
{
209+
array_unshift($this->stack, 'require');
210+
211+
return $this;
212+
}
213+
}

0 commit comments

Comments
 (0)