8000 [DI] Remove LazyString from 4.4, before adding back to the String component by nicolas-grekas · Pull Request #34290 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Remove LazyString from 4.4, before adding back to the String component #34290

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

Merged
merged 1 commit into from
Nov 8, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1473,9 +1473,13 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c
}

if ($config['decryption_env_var']) {
$container->getDefinition('secrets.decryption_key')->replaceArgument(1, $config['decryption_env_var']);
if (!preg_match('/^(?:\w*+:)*+\w++$/', $config['decryption_env_var'])) {
throw new InvalidArgumentException(sprintf('Invalid value "%s" set as "decryption_env_var": only "word" characters are allowed.', $config['decryption_env_var']));
}

$container->getDefinition('secrets.vault')->replaceArgument(1, "%env({$config['decryption_env_var']})%");
} else {
$container->removeDefinition('secrets.decryption_key');
$container->getDefinition('secrets.vault')->replaceArgument(1, null);
}
}

Expand Down
20 changes: 1 addition & 19 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/secrets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,7 @@
<services>
<service id="secrets.vault" class="Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault">
<argument>%kernel.project_dir%/config/secrets/%kernel.environment%</argument>
<argument type="service" id="secrets.decryption_key" on-invalid="ignore" />
</service>

<!--
LazyString::fromCallable() is used as a wrapper to lazily read the SYMFONY_DECRYPTION_SECRET var from the env.
By overriding this service and using the same strategy, the decryption key can be fetched lazily from any other service if needed.
-->
<service id="secrets.decryption_key" class="Symfony\Component\DependencyInjection\LazyString">
<factory class="Symfony\Component\DependencyInjection\LazyString" method="fromCallable" />
<argument type="service">
<service class="Closure">
<factory class="Closure" method="fromCallable" />
<argument type="collection">
<argument type="service" id="service_container" />
<argument>getEnv</argument>
</argument>
</service>
</argument>
<argument>base64:default::SYMFONY_DECRYPTION_SECRET</argument>
<argument>%env(base64:default::SYMFONY_DECRYPTION_SECRET)%</argument>
</service>

<service id="secrets. 8000 local_vault" class="Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault">
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpClient\ScopingHttpClient;
Expand Down Expand Up @@ -1403,20 +1403,6 @@ public function testCacheDefaultRedisProvider()
$this->assertSame($redisUrl, $url);
}

public function testCacheDefaultRedisProviderWithEnvVar()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is just wrong :)

{
$container = $this->createContainerFromFile('cache_env_var');

$redisUrl = 'redis://paas.com';
$providerId = '.cache_connection.'.ContainerBuilder::hash($redisUrl);

$this->assertTrue($container->hasDefinition($providerId));

$url = $container->getDefinition($providerId)->getArgument(0);

$this->assertSame($redisUrl, $url);
}

public function testCachePoolServices()
{
$container = $this->createContainerFromFile('cache', [], true, false);
Expand Down Expand Up @@ -1584,7 +1570,7 @@ public function testMailer(): void

protected function createContainer(array $data = [])
{
return new ContainerBuilder(new ParameterBag(array_merge([
return new ContainerBuilder(new EnvPlaceholderParameterBag(array_merge([
'kernel.bundles' => ['FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'],
'kernel.bundles_metadata' => ['FrameworkBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..']],
'kernel.cache_dir' => __DIR__,
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ CHANGELOG
* made singly-implemented interfaces detection be scoped by file
* added ability to define a static priority method for tagged service
* added support for improved syntax to define method calls in Yaml
* added `LazyString` for lazy computation of string values injected into services
* made the `%env(base64:...)%` processor able to decode base64url
* added ability to choose behavior of decorations on non existent decorated services

Expand Down
112 changes: 0 additions & 112 deletions src/Symfony/Component/DependencyInjection/LazyString.php

This file was deleted.

72 changes: 0 additions & 72 deletions src/Symfony/Component/DependencyInjection/Tests/LazyStringTest.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Symfony/Component/DependencyInjection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"require-dev": {
"symfony/yaml": "^3.4|^4.0|^5.0",
"symfony/config": "^4.3|^5.0",
"symfony/error-handler": "^4.4|^5.0",
"symfony/expression-language": "^3.4|^4.0|^5.0"
},
"suggest": {
Expand Down
0