Skip to content

Commit 55f7f17

Browse files
authored
Readding logging support (#78)
* Readding logging support * Applied changes from StyleCI
1 parent db7eb5d commit 55f7f17

File tree

6 files changed

+58
-8
lines changed

6 files changed

+58
-8
lines changed

Diff for: src/CacheBundle.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public function build(ContainerBuilder $container)
3030
$container->addCompilerPass(new Compiler\CacheTaggingPass());
3131
$container->addCompilerPass(new Compiler\SessionSupportCompilerPass());
3232
$container->addCompilerPass(new Compiler\DoctrineCompilerPass());
33-
34-
if ($container->getParameter('kernel.debug')) {
35-
$container->addCompilerPass(new Compiler\DataCollectorCompilerPass());
36-
}
33+
$container->addCompilerPass(new Compiler\LoggerPass());
34+
$container->addCompilerPass(new Compiler\DataCollectorCompilerPass());
3735
}
3836
}

Diff for: src/DataCollector/CacheProxyInterface.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
namespace Cache\CacheBundle\DataCollector;
1313

14+
use Psr\Cache\CacheItemPoolInterface;
15+
1416
/**
1517
* An interface for a cache proxy. A cache proxy is created when we profile a cache pool.
1618
*
1719
* @author Tobias Nyholm <[email protected]>
1820
*/
19-
interface CacheProxyInterface
21+
interface CacheProxyInterface extends CacheItemPoolInterface
2022
{
2123
public function __getCalls();
2224

Diff for: src/DataCollector/DecoratingFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(ProxyFactory $proxyFactory)
3737
/**
3838
* @param CacheItemPoolInterface $originalObject original class
3939
*
40-
* @return CacheProxyInterface|CacheItemPoolInterface
40+
* @return CacheProxyInterface
4141
*/
4242
public function create($originalObject)
4343
{

Diff for: src/DependencyInjection/CacheExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function load(array $configs, ContainerBuilder $container)
5656

5757
$this->registerServices($container, $config);
5858

59-
// Add toolbar and data collector if we are debuging
59+
// Add toolbar and data collector if we are debugging
6060
if (!isset($config['data_collector']['enabled'])) {
6161
$config['data_collector']['enabled'] = $container->getParameter('kernel.debug');
6262
}

Diff for: src/DependencyInjection/Compiler/LoggerPass.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\cache-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\CacheBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
/**
19+
* Add logging to pool implementing LoggerAwareInterface.
20+
*
21+
* @author Tobias Nyholm <[email protected]>
22+
*/
23+
class LoggerPass implements CompilerPassInterface
24+
{
25+
/**
26+
* @param ContainerBuilder $container
27+
*
28+
* @throws \Exception
29+
*/
30+
public function process(ContainerBuilder $container)
31+
{
32+
if (!$container->hasParameter('cache.logging')) {
33+
return;
34+
}
35+
36+
$config = $container->getParameter('cache.logging');
37+
if (!$config['enabled']) {
38+
return;
39+
}
40+
41+
$serviceIds = $container->findTaggedServiceIds('cache.provider');
42+
43+
foreach (array_keys($serviceIds) as $id) {
44+
$poolDefinition = $container->getDefinition($id);
45+
if (!method_exists($poolDefinition->getClass(), 'setLogger')) {
46+
continue;
47+
}
48+
$poolDefinition->addMethodCall('setLogger', [new Reference($config['logger'])]);
49+
}
50+
}
51+
}

Diff for: src/DependencyInjection/Configuration.php

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ private function addLoggingSection()
148148
->addDefaultsIfNotSet()
149149
->children()
150150
->scalarNode('logger')->defaultValue('logger')->end()
151-
->scalarNode('level')->defaultValue('info')->end()
152151
->end();
153152

154153
return $node;

0 commit comments

Comments
 (0)