14
14
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
15
15
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
16
use Symfony \Component \DependencyInjection \Reference ;
17
- use Symfony \Component \HttpKernel \Log \Logger ;
18
17
19
18
class AddDebugLogProcessorPass implements CompilerPassInterface
20
19
{
@@ -23,38 +22,22 @@ public function process(ContainerBuilder $container)
23
22
if (!$ container ->hasDefinition ('profiler ' )) {
24
23
return ;
25
24
}
26
-
27
- if ($ container ->hasDefinition ('monolog.logger_prototype ' ) && $ container ->hasDefinition ('debug.log_processor ' )) {
28
- $ container ->getDefinition ('monolog.logger_prototype ' )
29
- ->setConfigurator ([__CLASS__ , 'configureMonologLogger ' ])
30
- ->addMethodCall ('pushProcessor ' , [new Reference ('debug.log_processor ' )])
31
- ;
32
-
25
+ if (!$ container ->hasDefinition ('monolog.logger_prototype ' )) {
33
26
return ;
34
27
}
35
-
36
- if (!$ container ->hasDefinition ('logger ' )) {
28
+ if (!$ container ->hasDefinition ('debug.log_processor ' )) {
37
29
return ;
38
30
}
39
31
40
- $ loggerDefinition = $ container ->getDefinition ('logger ' );
41
-
42
- if (Logger::class === $ loggerDefinition ->getClass ()) {
43
- $ loggerDefinition ->setConfigurator ([__CLASS__ , 'configureHttpKernelLogger ' ]);
44
- }
32
+ $ definition = $ container ->getDefinition ('monolog.logger_prototype ' );
33
+ $ definition ->setConfigurator ([__CLASS__ , 'configureLogger ' ]);
34
+ $ definition ->addMethodCall ('pushProcessor ' , [new Reference ('debug.log_processor ' )]);
45
35
}
46
36
47
- public static function configureMonologLogger (mixed $ logger )
37
+ public static function configureLogger (mixed $ logger )
48
38
{
49
- if (\in_array (\ PHP_SAPI , [ ' cli ' , ' phpdbg ' ], true ) && \is_object ($ logger ) && method_exists ( $ logger , ' removeDebugLogger ' )) {
39
+ if (\is_object ( $ logger ) && method_exists ($ logger, ' removeDebugLogger ' ) && \in_array (\ PHP_SAPI , [ ' cli ' , ' phpdbg ' ], true )) {
50
40
$ logger ->removeDebugLogger ();
51
41
}
52
42
}
53
-
54
- public static function configureHttpKernelLogger (Logger $ logger )
55
- {
56
- if (!\in_array (\PHP_SAPI , ['cli ' , 'phpdbg ' ], true ) && method_exists ($ logger , 'enableDebug ' )) {
57
- $ logger ->enableDebug ();
58
- }
59
- }
60
43
}
0 commit comments