From 86329e3d4050694de8cf16da50f71c1fcd8c78e2 Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Mon, 30 Jan 2017 22:37:40 -0500 Subject: [PATCH] implement comprehensive container logging for compiler passes --- .../Compiler/AbstractCompilerPass.php | 36 +++++++++++++++++++ .../Compiler/FiltersCompilerPass.php | 4 +-- .../Compiler/LoadersCompilerPass.php | 4 +-- .../Compiler/MetadataReaderCompilerPass.php | 20 ++--------- .../Compiler/PostProcessorsCompilerPass.php | 4 +-- .../Compiler/ResolversCompilerPass.php | 4 +-- 6 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 DependencyInjection/Compiler/AbstractCompilerPass.php diff --git a/DependencyInjection/Compiler/AbstractCompilerPass.php b/DependencyInjection/Compiler/AbstractCompilerPass.php new file mode 100644 index 000000000..4e2bb4df2 --- /dev/null +++ b/DependencyInjection/Compiler/AbstractCompilerPass.php @@ -0,0 +1,36 @@ + 0) { + $message = vsprintf($message, $replacements); + } + + if (method_exists($container, 'log')) { + $container->log($this, $message); + } else { + $compiler = $container->getCompiler(); + $formatter = $compiler->getLoggingFormatter(); + $compiler->addLogMessage($formatter->format($this, $message)); + } + } +} diff --git a/DependencyInjection/Compiler/FiltersCompilerPass.php b/DependencyInjection/Compiler/FiltersCompilerPass.php index 2fd52d42c..1f4c1d31b 100644 --- a/DependencyInjection/Compiler/FiltersCompilerPass.php +++ b/DependencyInjection/Compiler/FiltersCompilerPass.php @@ -11,11 +11,10 @@ namespace Liip\ImagineBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -class FiltersCompilerPass implements CompilerPassInterface +class FiltersCompilerPass extends AbstractCompilerPass { /** * {@inheritdoc} @@ -28,6 +27,7 @@ public function process(ContainerBuilder $container) $manager = $container->getDefinition('liip_imagine.filter.manager'); foreach ($tags as $id => $tag) { + $this->log($container, 'Registering imagine filter loader: %s', array($id)); $manager->addMethodCall('addLoader', array($tag[0]['loader'], new Reference($id))); } } diff --git a/DependencyInjection/Compiler/LoadersCompilerPass.php b/DependencyInjection/Compiler/LoadersCompilerPass.php index 8800f3cc8..4e37cfee9 100644 --- a/DependencyInjection/Compiler/LoadersCompilerPass.php +++ b/DependencyInjection/Compiler/LoadersCompilerPass.php @@ -11,11 +11,10 @@ namespace Liip\ImagineBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -class LoadersCompilerPass implements CompilerPassInterface +class LoadersCompilerPass extends AbstractCompilerPass { /** * {@inheritdoc} @@ -28,6 +27,7 @@ public function process(ContainerBuilder $container) $manager = $container->getDefinition('liip_imagine.data.manager'); foreach ($tags as $id => $tag) { + $this->log($container, 'Registering imagine binary loader: %s', array($id)); $manager->addMethodCall('addLoader', array($tag[0]['loader'], new Reference($id))); } } diff --git a/DependencyInjection/Compiler/MetadataReaderCompilerPass.php b/DependencyInjection/Compiler/MetadataReaderCompilerPass.php index ee10a8466..43deede5c 100644 --- a/DependencyInjection/Compiler/MetadataReaderCompilerPass.php +++ b/DependencyInjection/Compiler/MetadataReaderCompilerPass.php @@ -11,7 +11,6 @@ namespace Liip\ImagineBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; /** @@ -19,7 +18,7 @@ * This compiler pass checks if the extension is loaded an switches to a simpler * implementation if not. */ -class MetadataReaderCompilerPass implements CompilerPassInterface +class MetadataReaderCompilerPass extends AbstractCompilerPass { const METADATA_READER_PARAM = 'liip_imagine.meta_data.reader.class'; @@ -34,7 +33,7 @@ public function process(ContainerBuilder $container) { if (!$this->extExifIsAvailable() && $this->isDefaultMetadataReader($container)) { $container->setParameter(self::METADATA_READER_PARAM, self::DEFAULT_METADATA_READER_CLASS); - $this->logMetadataReaderReplaced($container); + $this->log($container, 'Replacing imagine metadata reader: missing "exif" extension (installing this extension is suggested).'); } } @@ -50,21 +49,6 @@ protected function isDefaultMetadataReader(ContainerBuilder $container) return $currentMetadataReaderParameter === self::EXIF_METADATA_READER_CLASS; } - /** - * @param ContainerBuilder $container - */ - protected function logMetadataReaderReplaced(ContainerBuilder $container) - { - $compiler = $container->getCompiler(); - $formatter = $compiler->getLoggingFormatter(); - $message = 'Automatically replaced Imagine ExifMetadataReader with DefaultMetadataReader; '. - 'you might experience issues with LiipImagineBundle; reason: PHP extension "exif" is missing; solution: '. - 'for advanced metadata extraction install the PHP extension "exif" or set a custom MetadataReader '. - 'through the "liip_imagine.meta_data.reader.class" parameter'; - - $compiler->addLogMessage($formatter->format($this, $message)); - } - /** * @return bool */ diff --git a/DependencyInjection/Compiler/PostProcessorsCompilerPass.php b/DependencyInjection/Compiler/PostProcessorsCompilerPass.php index ddab772b2..ff5828da6 100644 --- a/DependencyInjection/Compiler/PostProcessorsCompilerPass.php +++ b/DependencyInjection/Compiler/PostProcessorsCompilerPass.php @@ -11,7 +11,6 @@ namespace Liip\ImagineBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -20,7 +19,7 @@ * * @author Konstantin Tjuterev */ -class PostProcessorsCompilerPass implements CompilerPassInterface +class PostProcessorsCompilerPass extends AbstractCompilerPass { /** * {@inheritdoc} @@ -33,6 +32,7 @@ public function process(ContainerBuilder $container) $manager = $container->getDefinition('liip_imagine.filter.manager'); foreach ($tags as $id => $tag) { + $this->log($container, 'Registering imagine filter post-processor: %s', array($id)); $manager->addMethodCall('addPostProcessor', array($tag[0]['post_processor'], new Reference($id))); } } diff --git a/DependencyInjection/Compiler/ResolversCompilerPass.php b/DependencyInjection/Compiler/ResolversCompilerPass.php index 61d598c51..4899b7111 100644 --- a/DependencyInjection/Compiler/ResolversCompilerPass.php +++ b/DependencyInjection/Compiler/ResolversCompilerPass.php @@ -11,11 +11,10 @@ namespace Liip\ImagineBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -class ResolversCompilerPass implements CompilerPassInterface +class ResolversCompilerPass extends AbstractCompilerPass { /** * {@inheritdoc} @@ -28,6 +27,7 @@ public function process(ContainerBuilder $container) $manager = $container->getDefinition('liip_imagine.cache.manager'); foreach ($tags as $id => $tag) { + $this->log($container, 'Registering imagine cache resolver: %s', array($id)); $manager->addMethodCall('addResolver', array($tag[0]['resolver'], new Reference($id))); } }