diff --git a/src/CacheBundle.php b/src/CacheBundle.php index 5780815..65cb7c3 100644 --- a/src/CacheBundle.php +++ b/src/CacheBundle.php @@ -30,9 +30,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new Compiler\CacheTaggingPass()); $container->addCompilerPass(new Compiler\SessionSupportCompilerPass()); $container->addCompilerPass(new Compiler\DoctrineCompilerPass()); - - if ($container->getParameter('kernel.debug')) { - $container->addCompilerPass(new Compiler\DataCollectorCompilerPass()); - } + $container->addCompilerPass(new Compiler\LoggerPass()); + $container->addCompilerPass(new Compiler\DataCollectorCompilerPass()); } } diff --git a/src/DataCollector/CacheProxyInterface.php b/src/DataCollector/CacheProxyInterface.php index c592ec3..e1d395a 100644 --- a/src/DataCollector/CacheProxyInterface.php +++ b/src/DataCollector/CacheProxyInterface.php @@ -11,12 +11,14 @@ namespace Cache\CacheBundle\DataCollector; +use Psr\Cache\CacheItemPoolInterface; + /** * An interface for a cache proxy. A cache proxy is created when we profile a cache pool. * * @author Tobias Nyholm */ -interface CacheProxyInterface +interface CacheProxyInterface extends CacheItemPoolInterface { public function __getCalls(); diff --git a/src/DataCollector/DecoratingFactory.php b/src/DataCollector/DecoratingFactory.php index 781f39c..84e2824 100644 --- a/src/DataCollector/DecoratingFactory.php +++ b/src/DataCollector/DecoratingFactory.php @@ -37,7 +37,7 @@ public function __construct(ProxyFactory $proxyFactory) /** * @param CacheItemPoolInterface $originalObject original class * - * @return CacheProxyInterface|CacheItemPoolInterface + * @return CacheProxyInterface */ public function create($originalObject) { diff --git a/src/DependencyInjection/CacheExtension.php b/src/DependencyInjection/CacheExtension.php index 35bfd16..5902c69 100644 --- a/src/DependencyInjection/CacheExtension.php +++ b/src/DependencyInjection/CacheExtension.php @@ -56,7 +56,7 @@ public function load(array $configs, ContainerBuilder $container) $this->registerServices($container, $config); - // Add toolbar and data collector if we are debuging + // Add toolbar and data collector if we are debugging if (!isset($config['data_collector']['enabled'])) { $config['data_collector']['enabled'] = $container->getParameter('kernel.debug'); } diff --git a/src/DependencyInjection/Compiler/LoggerPass.php b/src/DependencyInjection/Compiler/LoggerPass.php new file mode 100644 index 0000000..c567f52 --- /dev/null +++ b/src/DependencyInjection/Compiler/LoggerPass.php @@ -0,0 +1,51 @@ +, Tobias Nyholm + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Cache\CacheBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +/** + * Add logging to pool implementing LoggerAwareInterface. + * + * @author Tobias Nyholm + */ +class LoggerPass implements CompilerPassInterface +{ + /** + * @param ContainerBuilder $container + * + * @throws \Exception + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasParameter('cache.logging')) { + return; + } + + $config = $container->getParameter('cache.logging'); + if (!$config['enabled']) { + return; + } + + $serviceIds = $container->findTaggedServiceIds('cache.provider'); + + foreach (array_keys($serviceIds) as $id) { + $poolDefinition = $container->getDefinition($id); + if (!method_exists($poolDefinition->getClass(), 'setLogger')) { + continue; + } + $poolDefinition->addMethodCall('setLogger', [new Reference($config['logger'])]); + } + } +} diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7da184b..4f02e4c 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -148,7 +148,6 @@ private function addLoggingSection() ->addDefaultsIfNotSet() ->children() ->scalarNode('logger')->defaultValue('logger')->end() - ->scalarNode('level')->defaultValue('info')->end() ->end(); return $node;