Skip to content

Commit

Permalink
bug #24635 [DI] Register default env var provided types (ro0NL)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Register default env var provided types

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23888 (comment)
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

cc @nicolas-grekas

Commits
-------

3cee7a6 [DI] Register default env var provided types
  • Loading branch information
fabpot committed Oct 23, 2017
2 parents dde192a + 3cee7a6 commit fe07c25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\EnvVarProcessor;
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
Expand Down Expand Up @@ -45,10 +46,16 @@ public function process(ContainerBuilder $container)
}
}

if ($processors) {
if ($bag instanceof EnvPlaceholderParameterBag) {
$bag->setProvidedTypes($types);
if ($bag instanceof EnvPlaceholderParameterBag) {
foreach (EnvVarProcessor::getProvidedTypes() as $prefix => $type) {
if (!isset($types[$prefix])) {
$types[$prefix] = self::validateProvidedTypes($type, EnvVarProcessor::class);
}
}
$bag->setProvidedTypes($types);
}

if ($processors) {
$container->register('container.env_var_processors_locator', ServiceLocator::class)
->setPublic(true)
->setArguments(array($processors))
Expand Down
Expand Up @@ -28,7 +28,20 @@ public function testSimpleProcessor()
$this->assertTrue($container->has('container.env_var_processors_locator'));
$this->assertInstanceof(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo'));

$this->assertSame(array('foo' => array('string')), $container->getParameterBag()->getProvidedTypes());
$expected = array(
'foo' => array('string'),
'base64' => array('string'),
'bool' => array('bool'),
'const' => array('bool', 'int', 'float', 'string', 'array'),
'file' => array('string'),
'float' => array('float'),
'int' => array('int'),
'json' => array('array'),
'resolve' => array('string'),
'string' => array('string'),
);

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

public function testNoProcessor()
Expand Down

0 comments on commit fe07c25

Please sign in to comment.