Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e9fea7c

Browse filesBrowse files
committed
[DIC] Add a explode env var processor
1 parent 482c357 commit e9fea7c
Copy full SHA for e9fea7c

File tree

4 files changed

+20
-0
lines changed
Filter options

4 files changed

+20
-0
lines changed

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated support for short factories and short configurators in Yaml
8+
* added `%env(explode:...)%` processor to `explode` a string into an array
89

910
4.3.0
1011
-----

‎src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static function getProvidedTypes()
4848
'string' => 'string',
4949
'trim' => 'string',
5050
'require' => 'bool|int|float|string|array',
51+
'explode' => 'array',
5152
];
5253
}
5354

@@ -243,6 +244,10 @@ public function getEnv($prefix, $name, \Closure $getEnv)
243244
return trim($env);
244245
}
245246

247+
if ('explode' === $prefix) {
248+
return explode(',', $env);
249+
}
250+
246251
throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
247252
}
248253
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function testSimpleProcessor()
4646
'string' => ['string'],
4747
'trim' => ['string'],
4848
'require' => ['bool', 'int', 'float', 'string', 'array'],
49+
'explode' => ['array'],
4950
];
5051

5152
$this->assertSame($expected, $container->getParameterBag()->getProvidedTypes());

‎src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,17 @@ public function testRequireFile()
486486

487487
$this->assertEquals('foo', $result);
488488
}
489+
490+
public function testGetEnvExplode()
491+
{
492+
$processor = new EnvVarProcessor(new Container());
493+
494+
$result = $processor->getEnv('explode', 'foo', function ($name) {
495+
$this->assertSame('foo', $name);
496+
497+
return 'one,two,three';
498+
});
499+
500+
$this->assertSame(['one', 'two', 'three'], $result);
501+
}
489502
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.