Skip to content

Commit af9448d

Browse files
committed
Example of customer env var processor
1 parent 67227a6 commit af9448d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

configuration/external_parameters.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,40 @@ It is also possible to combine the processors:
237237
auth: '%env(file:resolve:AUTH_FILE)%'
238238
239239
240+
Custom Environment Variable Processors
241+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
242+
243+
Its possible to add further processors for environment variables. You just need
244+
to add an implementation of `Symfony\Component\DependencyInjection\EnvVarProcessorInterface`.
245+
246+
.. code-block:: php
247+
248+
class LowercasingEnvVarProcessor implements EnvVarProcessorInterface
249+
{
250+
private $container;
251+
252+
public function __construct(ContainerInterface $container)
253+
{
254+
$this->container = $container;
255+
}
256+
257+
public function getEnv($prefix, $name, \Closure $getEnv)
258+
{
259+
$env = $getEnv($name);
260+
261+
return strtolower($env);
262+
}
263+
264+
public static function getProvidedTypes()
265+
{
266+
return [
267+
'lowercase' => 'string',
268+
];
269+
}
270+
}
271+
272+
273+
240274
.. _configuration-env-var-in-prod:
241275

242276
Configuring Environment Variables in Production

0 commit comments

Comments
 (0)