Skip to content

Commit 28e615a

Browse files
committed
Fix decorating TagAware adapters in dev
1 parent adc39a2 commit 28e615a

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
1415
use Symfony\Component\Cache\Adapter\TraceableAdapter;
16+
use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
1517
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1618
use Symfony\Component\DependencyInjection\ContainerBuilder;
1719
use Symfony\Component\DependencyInjection\Reference;
@@ -34,11 +36,12 @@ public function process(ContainerBuilder $container)
3436

3537
$collectorDefinition = $container->getDefinition('data_collector.cache');
3638
foreach ($container->findTaggedServiceIds('cache.pool') as $id => $attributes) {
37-
if ($container->getDefinition($id)->isAbstract()) {
39+
$definition = $container->getDefinition($id);
40+
if ($definition->isAbstract()) {
3841
continue;
3942
}
4043

41-
$container->register($id.'.recorder', TraceableAdapter::class)
44+
$container->register($id.'.recorder', is_subclass_of($definition->getClass(), TagAwareAdapterInterface::class) ? TraceableTagAwareAdapter::class : TraceableAdapter::class)
4245
->setDecoratedService($id)
4346
->addArgument(new Reference($id.'.recorder.inner'))
4447
->setPublic(false);

src/Symfony/Component/Cache/Adapter/TraceableAdapter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class TraceableAdapter implements AdapterInterface
2424
{
25-
private $pool;
25+
protected $pool;
2626
private $calls = array();
2727

2828
public function __construct(AdapterInterface $pool)
@@ -177,7 +177,7 @@ public function getCalls()
177177
}
178178
}
179179

180-
private function start($name)
180+
protected function start($name)
181181
{
182182
$this->calls[] = $event = new TraceableAdapterEvent();
183183
$event->name = $name;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
/**
15+
* @author Robin Chalas <robin.chalas@gmail.com>
16+
*/
17+
class TraceableTagAwareAdapter extends TraceableAdapter implements TagAwareAdapterInterface
18+
{
19+
public function __construct(TagAwareAdapterInterface $pool)
20+
{
21+
parent::__construct($pool);
22+
}
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function invalidateTags(array $tags)
28+
{
29+
$event = $this->start(__FUNCTION__);
30+
try {
31+
return $event->result = $this->pool->invalidateTags($tags);
32+
} finally {
33+
$event->end = microtime(true);
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter;
13+
14+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
15+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
16+
use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
17+
18+
class TraceableTagAwareAdapterTest extends TraceableAdapterTest
19+
{
20+
public function testInvalidateTags()
21+
{
22+
$pool = new TraceableTagAwareAdapter(new TagAwareAdapter(new FilesystemAdapter()));
23+
$pool->invalidateTags(array('foo'));
24+
$calls = $pool->getCalls();
25+
$this->assertCount(1, $calls);
26+
27+
$call = $calls[0];
28+
$this->assertSame('invalidateTags', $call->name);
29+
$this->assertSame(0, $call->hits);
30+
$this->assertSame(0, $call->misses);
31+
$this->assertNotEmpty($call->start);
32+
$this->assertNotEmpty($call->end);
33+
}
34+
}

0 commit comments

Comments
 (0)