From 1c0d213d6f15d2cbb843ee7f0d7edc9c9e65e878 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 31 Jul 2017 09:46:37 +0200 Subject: [PATCH 1/2] Readding logging support --- src/CacheBundle.php | 5 +- src/DataCollector/CacheProxyInterface.php | 4 +- src/DataCollector/DecoratingFactory.php | 2 +- src/DependencyInjection/CacheExtension.php | 2 +- .../Compiler/LoggerPass.php | 51 +++++++++++++++++++ src/DependencyInjection/Configuration.php | 1 - 6 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 src/DependencyInjection/Compiler/LoggerPass.php diff --git a/src/CacheBundle.php b/src/CacheBundle.php index 5780815..bd35de5 100644 --- a/src/CacheBundle.php +++ b/src/CacheBundle.php @@ -30,9 +30,8 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new Compiler\CacheTaggingPass()); $container->addCompilerPass(new Compiler\SessionSupportCompilerPass()); $container->addCompilerPass(new Compiler\DoctrineCompilerPass()); + $container->addCompilerPass(new Compiler\LoggerPass()); + $container->addCompilerPass(new Compiler\DataCollectorCompilerPass()); - if ($container->getParameter('kernel.debug')) { - $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..2eedb23 --- /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; From 218573eb48c71e6b9c015adc37c1f81d684782d1 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 31 Jul 2017 09:50:50 +0200 Subject: [PATCH 2/2] Applied changes from StyleCI --- src/CacheBundle.php | 1 - src/DependencyInjection/Compiler/LoggerPass.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CacheBundle.php b/src/CacheBundle.php index bd35de5..65cb7c3 100644 --- a/src/CacheBundle.php +++ b/src/CacheBundle.php @@ -32,6 +32,5 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new Compiler\DoctrineCompilerPass()); $container->addCompilerPass(new Compiler\LoggerPass()); $container->addCompilerPass(new Compiler\DataCollectorCompilerPass()); - } } diff --git a/src/DependencyInjection/Compiler/LoggerPass.php b/src/DependencyInjection/Compiler/LoggerPass.php index 2eedb23..c567f52 100644 --- a/src/DependencyInjection/Compiler/LoggerPass.php +++ b/src/DependencyInjection/Compiler/LoggerPass.php @@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\Reference; /** - * Add logging to pool implementing LoggerAwareInterface + * Add logging to pool implementing LoggerAwareInterface. * * @author Tobias Nyholm */