Skip to content

Commit

Permalink
tag cache.app.taggable as a cache pool
Browse files Browse the repository at this point in the history
With this change the CacheCollectorPass will be able to decorate the
TagAwareAdapter and thus injects a traceable cache when a service
argument's type declaration asks for a TagAwareCacheInterface
implementation.
  • Loading branch information
xabbuh committed Jan 10, 2020
1 parent 2787024 commit 56e90f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Expand Up @@ -18,6 +18,7 @@

<service id="cache.app.taggable" class="Symfony\Component\Cache\Adapter\TagAwareAdapter">
<argument type="service" id="cache.app" />
<tag name="cache.pool" />
</service>

<service id="cache.system" parent="cache.adapter.system" public="true">
Expand Down
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -106,11 +107,12 @@ public function process(ContainerBuilder $container)
if ($tags[0][$attr]) {
$pool->addTag($this->kernelResetTag, ['method' => $tags[0][$attr]]);
}
} elseif ('namespace' !== $attr || ArrayAdapter::class !== $adapter->getClass()) {
} elseif (('namespace' !== $attr || ArrayAdapter::class !== $adapter->getClass()) && TagAwareAdapter::class !== $class && !is_subclass_of($class, TagAwareAdapter::class)) {
$pool->replaceArgument($i++, $tags[0][$attr]);
}
unset($tags[0][$attr]);
}

if (!empty($tags[0])) {
throw new InvalidArgumentException(sprintf('Invalid "%s" tag for service "%s": accepted attributes are "clearer", "provider", "name", "namespace", "default_lifetime" and "reset", found "%s".', $this->cachePoolTag, $id, implode('", "', array_keys($tags[0]))));
}
Expand Down

0 comments on commit 56e90f3

Please sign in to comment.