8000 [DIC] Add a explode env var processor · symfony/symfony@44461c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44461c1

Browse files
committed
[DIC] Add a explode env var processor
1 parent 075076f commit 44461c1

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
-----
1212

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

1516
4.3.0
1617
-----

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines 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

Lines 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

Lines 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