8000 [DIC] Add a split env var processor by Orkin · Pull Request #31867 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DIC] Add a split env var processor #31867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* deprecated support for short factories and short configurators in Yaml
* deprecated `tagged` in favor of `tagged_iterator`
* added `%env(split:...)%` processor to `split` a string into an array

4.3.0
-----
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static function getProvidedTypes()
'string' => 'string',
'trim' => 'string',
'require' => 'bool|int|float|string|array',
'split' => 'array',
];
}

Expand Down Expand Up @@ -243,6 +244,10 @@ public function getEnv($prefix, $name, \Closure $getEnv)
return trim($env);
}

if ('split' === $prefix) {
return explode(',', $env);
}

throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function testSimpleProcessor()
'string' => ['string'],
'trim' => ['string'],
'require' => ['bool', 'int', 'float', 'string', 'array'],
'split' => ['array'],
];

$this->assertSame($expected, $container->getParameterBag()->getProvidedTypes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,17 @@ public function testRequireFile()

$this->assertEquals('foo', $result);
}

public function testGetEnvSplit()
{
$processor = new EnvVarProcessor(new Container());

$result = $processor->getEnv('split', 'foo', function ($name) {
$this->assertSame('foo', $name);

return 'one,two,three';
});

$this->assertSame(['one', 'two', 'three'], $result);
}
}
0