Skip to content

Commit

Permalink
minor #34290 [DI] Remove LazyString from 4.4, before adding back to t…
Browse files Browse the repository at this point in the history
…he String component (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

In #34190 I'm proposing to move LazyString to the Service contracts, but String might be a better fit actually. Let's remove the class from 4.4 where it's not really needed, and add it back on 5.0 in the String component.

Commits
-------

b1a3ee7 [DI] Remove LazyString from 4.4, before adding back to the String component
  • Loading branch information
nicolas-grekas committed Nov 8, 2019
2 parents f459fd0 + b1a3ee7 commit 7c111bd
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 255 deletions.
Expand Up @@ -1476,9 +1476,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
Expand Up @@ -8,25 +8,7 @@
<service id="secrets.vault" class="Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault">
<tag name="container.env_var_loader" />
<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.local_vault" class="Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault">
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

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()
{
$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
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
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 comments on commit 7c111bd

Please sign in to comment.