From 926f3deba682469ca4f4e67b7cd784dad230f4c1 Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Sat, 29 Oct 2022 11:24:19 +0200 Subject: [PATCH] [FrameworkBundle] Split loggers debug compiler pass --- .../Compiler/AddDebugLogProcessorPass.php | 31 ++++----------- .../Compiler/EnableLoggerDebugModePass.php | 39 +++++++++++++++++++ .../FrameworkBundle/FrameworkBundle.php | 2 + 3 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnableLoggerDebugModePass.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php index f1e64ca6c6a0b..a1bf0a80eadb0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php @@ -14,7 +14,6 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpKernel\Log\Logger; class AddDebugLogProcessorPass implements CompilerPassInterface { @@ -23,38 +22,22 @@ public function process(ContainerBuilder $container) if (!$container->hasDefinition('profiler')) { return; } - - if ($container->hasDefinition('monolog.logger_prototype') && $container->hasDefinition('debug.log_processor')) { - $container->getDefinition('monolog.logger_prototype') - ->setConfigurator([__CLASS__, 'configureMonologLogger']) - ->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]) - ; - + if (!$container->hasDefinition('monolog.logger_prototype')) { return; } - - if (!$container->hasDefinition('logger')) { + if (!$container->hasDefinition('debug.log_processor')) { return; } - $loggerDefinition = $container->getDefinition('logger'); - - if (Logger::class === $loggerDefinition->getClass()) { - $loggerDefinition->setConfigurator([__CLASS__, 'configureHttpKernelLogger']); - } + $definition = $container->getDefinition('monolog.logger_prototype'); + $definition->setConfigurator([__CLASS__, 'configureLogger']); + $definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]); } - public static function configureMonologLogger(mixed $logger) + public static function configureLogger(mixed $logger) { - if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && \is_object($logger) && method_exists($logger, 'removeDebugLogger')) { + if (\is_object($logger) && method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { $logger->removeDebugLogger(); } } - - public static function configureHttpKernelLogger(Logger $logger) - { - if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) { - $logger->enableDebug(); - } - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnableLoggerDebugModePass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnableLoggerDebugModePass.php new file mode 100644 index 0000000000000..3dad9d6b24031 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnableLoggerDebugModePass.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Log\Logger; + +final class EnableLoggerDebugModePass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('profiler') || !$container->hasDefinition('logger')) { + return; + } + + $loggerDefinition = $container->getDefinition('logger'); + + if (Logger::class === $loggerDefinition->getClass()) { + $loggerDefinition->setConfigurator([__CLASS__, 'configureLogger']); + } + } + + public static function configureLogger(Logger $logger): void + { + if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) { + $logger->enableDebug(); + } + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 3b86ea1344fcf..b51e19a5a2341 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -17,6 +17,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AssetsContextPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\EnableLoggerDebugModePass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass; @@ -165,6 +166,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass()); if ($container->getParameter('kernel.debug')) { + $container->addCompilerPass(new EnableLoggerDebugModePass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -33); $container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2); $container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy