11
11
12
12
namespace Symfony \Bundle \MakerBundle ;
13
13
14
- use Symfony \Component \Console \Event \ConsoleCommandEvent ;
15
- use Symfony \Component \Console \Event \ConsoleErrorEvent ;
16
- use Symfony \Component \Console \Event \ConsoleTerminateEvent ;
14
+ use Symfony \Component \Console \ConsoleEvents ;
17
15
use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
18
- use Symfony \Component \HttpKernel \Event \ControllerArgumentsEvent ;
19
- use Symfony \Component \HttpKernel \Event \ControllerEvent ;
20
- use Symfony \Component \HttpKernel \Event \ExceptionEvent ;
21
- use Symfony \Component \HttpKernel \Event \FilterControllerArgumentsEvent ;
22
- use Symfony \Component \HttpKernel \Event \FilterControllerEvent ;
23
- use Symfony \Component \HttpKernel \Event \FilterResponseEvent ;
24
- use Symfony \Component \HttpKernel \Event \FinishRequestEvent ;
25
- use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
26
- use Symfony \Component \HttpKernel \Event \GetResponseForControllerResultEvent ;
27
- use Symfony \Component \HttpKernel \Event \GetResponseForExceptionEvent ;
28
- use Symfony \Component \HttpKernel \Event \PostResponseEvent ;
29
- use Symfony \Component \HttpKernel \Event \RequestEvent ;
30
- use Symfony \Component \HttpKernel \Event \ResponseEvent ;
31
- use Symfony \Component \HttpKernel \Event \TerminateEvent ;
32
- use Symfony \Component \HttpKernel \Event \ViewEvent ;
33
- use Symfony \Component \Security \Core \Event \AuthenticationFailureEvent ;
34
- use Symfony \Component \Security \Core \Event \AuthenticationSuccessEvent ;
35
- use Symfony \Component \Security \Http \Event \InteractiveLoginEvent ;
36
- use Symfony \Component \Security \Http \Event \SwitchUserEvent ;
16
+ use Symfony \Component \Form \FormEvents ;
17
+ use Symfony \Component \HttpKernel \KernelEvents ;
18
+ use Symfony \Component \Security \Core \AuthenticationEvents ;
19
+ use Symfony \Component \Security \Http \SecurityEvents ;
20
+ use Symfony \Component \Workflow \WorkflowEvents ;
37
21
38
22
/**
39
23
* @internal
40
24
*/
41
25
class EventRegistry
42
26
{
43
- // list of *known* events to always include (if they exist)
44
- private static array $ newEventsMap = [
45
- 'kernel.exception ' => ExceptionEvent::class,
46
- 'kernel.request ' => RequestEvent::class,
47
- 'kernel.response ' => ResponseEvent::class,
48
- 'kernel.view ' => ViewEvent::class,
49
- 'kernel.controller_arguments ' => ControllerArgumentsEvent::class,
50
- 'kernel.controller ' => ControllerEvent::class,
51
- 'kernel.terminate ' => TerminateEvent::class,
52
- ];
53
-
54
- private static array $ eventsMap = [
55
- 'console.command ' => ConsoleCommandEvent::class,
56
- 'console.terminate ' => ConsoleTerminateEvent::class,
57
- 'console.error ' => ConsoleErrorEvent::class,
58
- 'kernel.request ' => GetResponseEvent::class,
59
- 'kernel.exception ' => GetResponseForExceptionEvent::class,
60
- 'kernel.view ' => GetResponseForControllerResultEvent::class,
61
- 'kernel.controller ' => FilterControllerEvent::class,
62
- 'kernel.controller_arguments ' => FilterControllerArgumentsEvent::class,
63
- 'kernel.response ' => FilterResponseEvent::class,
64
- 'kernel.terminate ' => PostResponseEvent::class,
65
- 'kernel.finish_request ' => FinishRequestEvent::class,
66
- 'security.authentication.success ' => AuthenticationSuccessEvent::class,
67
- 'security.authentication.failure ' => AuthenticationFailureEvent::class,
68
- 'security.interactive_login ' => InteractiveLoginEvent::class,
69
- 'security.switch_user ' => SwitchUserEvent::class,
70
- ];
27
+ private static array $ eventsMap = [];
71
28
72
29
public function __construct (
73
30
private EventDispatcherInterface $ eventDispatcher ,
74
31
) {
75
- // Loop through the new event classes
76
- foreach (self ::$ newEventsMap as $ eventName => $ newEventClass ) {
77
- // Check if the new event classes exist, if so replace the old one with the new.
78
- if (isset (self ::$ eventsMap [$ eventName ]) && class_exists ($ newEventClass )) {
79
- self ::$ eventsMap [$ eventName ] = $ newEventClass ;
80
- }
81
- }
32
+ self ::$ eventsMap = array_flip ([
33
+ ...ConsoleEvents::ALIASES ,
34
+ ...KernelEvents::ALIASES ,
35
+ ...(class_exists (AuthenticationEvents::class) ? AuthenticationEvents::ALIASES : []),
36
+ ...(class_exists (SecurityEvents::class) ? SecurityEvents::ALIASES : []),
37
+ ...(class_exists (WorkflowEvents::class) ? WorkflowEvents::ALIASES : []),
38
+ ...(class_exists (FormEvents::class) ? FormEvents::ALIASES : []),
39
+ ]);
82
40
}
83
41
84
42
/**
@@ -97,12 +55,7 @@ public function getAllActiveEvents(): array
97
55
98
56
$ listeners = $ this ->eventDispatcher ->getListeners ();
99
57
100
- // Check if these listeners are part of the new events.
101
58
foreach (array_keys ($ listeners ) as $ listenerKey ) {
102
- if (isset (self ::$ newEventsMap [$ listenerKey ])) {
103
- unset($ listeners [$ listenerKey ]);
104
- }
105
-
106
59
if (!isset (self ::$ eventsMap [$ listenerKey ])) {
107
60
self ::$ eventsMap [$ listenerKey ] = $ this ->getEventClassName ($ listenerKey );
108
61
}
0 commit comments