34
34
use Symfony \Component \Cache \DependencyInjection \CachePoolPass ;
35
35
use Symfony \Component \Cache \DependencyInjection \CachePoolPrunerPass ;
36
36
use Symfony \Component \Config \Resource \ClassExistenceResource ;
37
+ use Symfony \Component \Console \ConsoleEvents ;
37
38
use Symfony \Component \Console \DependencyInjection \AddConsoleCommandPass ;
38
39
use Symfony \Component \DependencyInjection \Compiler \PassConfig ;
39
40
use Symfony \Component \DependencyInjection \Compiler \RegisterReverseContainerPass ;
@@ -103,13 +104,21 @@ public function build(ContainerBuilder $container)
103
104
{
104
105
parent ::build ($ container );
105
106
106
- $ hotPathEvents = [
107
+ $ registerListenersPass = new RegisterListenersPass ();
108
+ $ registerListenersPass ->setHotPathEvents ([
107
109
KernelEvents::REQUEST ,
108
110
KernelEvents::CONTROLLER ,
109
111
KernelEvents::CONTROLLER_ARGUMENTS ,
110
112
KernelEvents::RESPONSE ,
111
113
KernelEvents::FINISH_REQUEST ,
112
- ];
114
+ ]);
115
+ if (class_exists (ConsoleEvents::class)) {
116
+ $ registerListenersPass ->setNoPreloadEvents ([
117
+ ConsoleEvents::COMMAND ,
118
+ ConsoleEvents::TERMINATE ,
119
+ ConsoleEvents::ERROR ,
120
+ ]);
121
+ }
113
122
114
123
$ container ->addCompilerPass (new LoggerPass (), PassConfig::TYPE_BEFORE_OPTIMIZATION , -32 );
115
124
$ container ->addCompilerPass (new RegisterControllerArgumentLocatorsPass ());
@@ -118,7 +127,7 @@ public function build(ContainerBuilder $container)
118
127
$ container ->addCompilerPass (new ProfilerPass ());
119
128
// must be registered before removing private services as some might be listeners/subscribers
120
129
// but as late as possible to get resolved parameters
121
- $ container ->addCompilerPass (( new RegisterListenersPass ())-> setHotPathEvents ( $ hotPathEvents ) , PassConfig::TYPE_BEFORE_REMOVING );
130
+ $ container ->addCompilerPass ($ registerListenersPass , PassConfig::TYPE_BEFORE_REMOVING );
122
131
$ this ->addCompilerPassIfExists ($ container , AddConstraintValidatorsPass::class);
123
132
$ container ->addCompilerPass (new AddAnnotationsCachedReaderPass (), PassConfig::TYPE_AFTER_REMOVING , -255 );
124
133
$ this ->addCompilerPassIfExists ($ container , AddValidatorInitializersPass::class);
0 commit comments