bug #31591 [FrameworkBundle] fix named autowiring aliases for TagAwareCacheInterface (nicolas-grekas)

This PR was merged into the 4.3 branch.

Discussion
----------

[FrameworkBundle] fix named autowiring aliases for TagAwareCacheInterface

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Doing a demo today, I realized that named autowiring aliases are missing for `TagAwareCacheInterface`, and that existing ones point to the wrong service. Here is the fix.

Commits
-------

d9082c2ae4 [FrameworkBundle] fix named autowiring aliases for TagAwareCacheInterface
This commit is contained in:
Nicolas Grekas 2019-05-23 09:02:13 +02:00
commit 77153b0ca2

View File

@ -117,6 +117,7 @@ use Symfony\Component\Workflow\WorkflowInterface;
use Symfony\Component\Yaml\Command\LintCommand as BaseYamlLintCommand;
use Symfony\Component\Yaml\Yaml;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\Service\ResetInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
@ -1819,10 +1820,6 @@ class FrameworkExtension extends Extension
$pool['adapter'] = '.'.$pool['adapter'].'.inner';
}
$definition = new ChildDefinition($pool['adapter']);
if (!\in_array($name, ['cache.app', 'cache.system'], true)) {
$container->registerAliasForArgument($name, CacheInterface::class);
$container->registerAliasForArgument($name, CacheItemPoolInterface::class);
}
if ($pool['tags']) {
if ($config['pools'][$pool['tags']]['tags'] ?? false) {
@ -1837,7 +1834,21 @@ class FrameworkExtension extends Extension
$pool['name'] = $name;
$pool['public'] = false;
$name = '.'.$name.'.inner';
if (!\in_array($pool['name'], ['cache.app', 'cache.system'], true)) {
$container->registerAliasForArgument($pool['name'], TagAwareCacheInterface::class);
$container->registerAliasForArgument($name, CacheInterface::class, $pool['name']);
$container->registerAliasForArgument($name, CacheItemPoolInterface::class, $pool['name']);
}
} elseif (!\in_array($name, ['cache.app', 'cache.system'], true)) {
$container->register('.'.$name.'.taggable', TagAwareAdapter::class)
->addArgument(new Reference($name))
;
$container->registerAliasForArgument('.'.$name.'.taggable', TagAwareCacheInterface::class, $name);
$container->registerAliasForArgument($name, CacheInterface::class);
$container->registerAliasForArgument($name, CacheItemPoolInterface::class);
}
$definition->setPublic($pool['public']);
unset($pool['adapter'], $pool['public'], $pool['tags']);