Skip to content

Commit 3c0d934

Browse files
authored
Merge pull request #3009 from stof/fix_event_dispatching
Migrate to the new event dispatching signature
2 parents 66498d6 + cfcd2e8 commit 3c0d934

6 files changed

+40
-33
lines changed

Controller/ChangePasswordController.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use FOS\UserBundle\Model\UserManagerInterface;
2121
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
2222
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2324
use Symfony\Component\HttpFoundation\RedirectResponse;
2425
use Symfony\Component\HttpFoundation\Request;
2526
use Symfony\Component\HttpFoundation\Response;
@@ -41,7 +42,7 @@ class ChangePasswordController extends Controller
4142

4243
public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager)
4344
{
44-
$this->eventDispatcher = $eventDispatcher;
45+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
4546
$this->formFactory = $formFactory;
4647
$this->userManager = $userManager;
4748
}
@@ -59,7 +60,7 @@ public function changePasswordAction(Request $request)
5960
}
6061

6162
$event = new GetResponseUserEvent($user, $request);
62-
$this->eventDispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event);
63+
$this->eventDispatcher->dispatch($event, FOSUserEvents::CHANGE_PASSWORD_INITIALIZE);
6364

6465
if (null !== $event->getResponse()) {
6566
return $event->getResponse();
@@ -72,7 +73,7 @@ public function changePasswordAction(Request $request)
7273

7374
if ($form->isSubmitted() && $form->isValid()) {
7475
$event = new FormEvent($form, $request);
75-
$this->eventDispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_SUCCESS, $event);
76+
$this->eventDispatcher->dispatch($event, FOSUserEvents::CHANGE_PASSWORD_SUCCESS);
7677

7778
$this->userManager->updateUser($user);
7879

@@ -81,7 +82,7 @@ public function changePasswordAction(Request $request)
8182
$response = new RedirectResponse($url);
8283
}
8384

84-
$this->eventDispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
85+
$this->eventDispatcher->dispatch(new FilterUserResponseEvent($user, $request, $response), FOSUserEvents::CHANGE_PASSWORD_COMPLETED);
8586

8687
return $response;
8788
}

Controller/GroupController.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use FOS\UserBundle\Model\GroupManagerInterface;
2424
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
2525
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
26+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2627
use Symfony\Component\HttpFoundation\RedirectResponse;
2728
use Symfony\Component\HttpFoundation\Request;
2829
use Symfony\Component\HttpFoundation\Response;
@@ -44,7 +45,7 @@ class GroupController extends Controller
4445

4546
public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, GroupManagerInterface $groupManager)
4647
{
47-
$this->eventDispatcher = $eventDispatcher;
48+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
4849
$this->formFactory = $formFactory;
4950
$this->groupManager = $groupManager;
5051
}
@@ -85,7 +86,7 @@ public function editAction(Request $request, $groupName)
8586
$group = $this->findGroupBy('name', $groupName);
8687

8788
$event = new GetResponseGroupEvent($group, $request);
88-
$this->eventDispatcher->dispatch(FOSUserEvents::GROUP_EDIT_INITIALIZE, $event);
89+
$this->eventDispatcher->dispatch($event, FOSUserEvents::GROUP_EDIT_INITIALIZE);
8990

9091
if (null !== $event->getResponse()) {
9192
return $event->getResponse();
@@ -98,7 +99,7 @@ public function editAction(Request $request, $groupName)
9899

99100
if ($form->isSubmitted() && $form->isValid()) {
100101
$event = new FormEvent($form, $request);
101-
$this->eventDispatcher->dispatch(FOSUserEvents::GROUP_EDIT_SUCCESS, $event);
102+
$this->eventDispatcher->dispatch($event, FOSUserEvents::GROUP_EDIT_SUCCESS);
102103

103104
$this->groupManager->updateGroup($group);
104105

@@ -107,7 +108,7 @@ public function editAction(Request $request, $groupName)
107108
$response = new RedirectResponse($url);
108109
}
109110

110-
$this->eventDispatcher->dispatch(FOSUserEvents::GROUP_EDIT_COMPLETED, new FilterGroupResponseEvent($group, $request, $response));
111+
$this->eventDispatcher->dispatch(new FilterGroupResponseEvent($group, $request, $response), FOSUserEvents::GROUP_EDIT_COMPLETED);
111112

112113
return $response;
113114
}
@@ -127,7 +128,7 @@ public function newAction(Request $request)
127128
{
128129
$group = $this->groupManager->createGroup('');
129130

130-
$this->eventDispatcher->dispatch(FOSUserEvents::GROUP_CREATE_INITIALIZE, new GroupEvent($group, $request));
131+
$this->eventDispatcher->dispatch(new GroupEvent($group, $request), FOSUserEvents::GROUP_CREATE_INITIALIZE);
131132

132133
$form = $this->formFactory->createForm();
133134
$form->setData($group);
@@ -136,7 +137,7 @@ public function newAction(Request $request)
136137

137138
if ($form->isSubmitted() && $form->isValid()) {
138139
$event = new FormEvent($form, $request);
139-
$this->eventDispatcher->dispatch(FOSUserEvents::GROUP_CREATE_SUCCESS, $event);
140+
$this->eventDispatcher->dispatch($event, FOSUserEvents::GROUP_CREATE_SUCCESS);
140141

141142
$this->groupManager->updateGroup($group);
142143

@@ -145,7 +146,7 @@ public function newAction(Request $request)
145146
$response = new RedirectResponse($url);
146147
}
147148

148-
$this->eventDispatcher->dispatch(FOSUserEvents::GROUP_CREATE_COMPLETED, new FilterGroupResponseEvent($group, $request, $response));
149+
$this->eventDispatcher->dispatch(new FilterGroupResponseEvent($group, $request, $response), FOSUserEvents::GROUP_CREATE_COMPLETED);
149150

150151
return $response;
151152
}
@@ -169,7 +170,7 @@ public function deleteAction(Request $request, $groupName)
169170

170171
$response = new RedirectResponse($this->generateUrl('fos_user_group_list'));
171172

172-
$this->eventDispatcher->dispatch(FOSUserEvents::GROUP_DELETE_COMPLETED, new FilterGroupResponseEvent($group, $request, $response));
173+
$this->eventDispatcher->dispatch(new FilterGroupResponseEvent($group, $request, $response), FOSUserEvents::GROUP_DELETE_COMPLETED);
173174

174175
return $response;
175176
}

Controller/ProfileController.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use FOS\UserBundle\Model\UserManagerInterface;
2121
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
2222
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2324
use Symfony\Component\HttpFoundation\RedirectResponse;
2425
use Symfony\Component\HttpFoundation\Request;
2526
use Symfony\Component\HttpFoundation\Response;
@@ -40,7 +41,7 @@ class ProfileController extends Controller
4041

4142
public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager)
4243
{
43-
$this->eventDispatcher = $eventDispatcher;
44+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
4445
$this->formFactory = $formFactory;
4546
$this->userManager = $userManager;
4647
}
@@ -73,7 +74,7 @@ public function editAction(Request $request)
7374
}
7475

7576
$event = new GetResponseUserEvent($user, $request);
76-
$this->eventDispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event);
77+
$this->eventDispatcher->dispatch($event, FOSUserEvents::PROFILE_EDIT_INITIALIZE);
7778

7879
if (null !== $event->getResponse()) {
7980
return $event->getResponse();
@@ -86,7 +87,7 @@ public function editAction(Request $request)
8687

8788
if ($form->isSubmitted() && $form->isValid()) {
8889
$event = new FormEvent($form, $request);
89-
$this->eventDispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
90+
$this->eventDispatcher->dispatch($event, FOSUserEvents::PROFILE_EDIT_SUCCESS);
9091

9192
$this->userManager->updateUser($user);
9293

@@ -95,7 +96,7 @@ public function editAction(Request $request)
9596
$response = new RedirectResponse($url);
9697
}
9798

98-
$this->eventDispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
99+
$this->eventDispatcher->dispatch(new FilterUserResponseEvent($user, $request, $response), FOSUserEvents::PROFILE_EDIT_COMPLETED);
99100

100101
return $response;
101102
}

Controller/RegistrationController.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use FOS\UserBundle\Model\UserManagerInterface;
2121
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
2222
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2324
use Symfony\Component\HttpFoundation\RedirectResponse;
2425
use Symfony\Component\HttpFoundation\Request;
2526
use Symfony\Component\HttpFoundation\Response;
@@ -44,7 +45,7 @@ class RegistrationController extends Controller
4445

4546
public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, TokenStorageInterface $tokenStorage)
4647
{
47-
$this->eventDispatcher = $eventDispatcher;
48+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
4849
$this->formFactory = $formFactory;
4950
$this->userManager = $userManager;
5051
$this->tokenStorage = $tokenStorage;
@@ -59,7 +60,7 @@ public function registerAction(Request $request)
5960
$user->setEnabled(true);
6061

6162
$event = new GetResponseUserEvent($user, $request);
62-
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
63+
$this->eventDispatcher->dispatch($event, FOSUserEvents::REGISTRATION_INITIALIZE);
6364

6465
if (null !== $event->getResponse()) {
6566
return $event->getResponse();
@@ -73,7 +74,7 @@ public function registerAction(Request $request)
7374
if ($form->isSubmitted()) {
7475
if ($form->isValid()) {
7576
$event = new FormEvent($form, $request);
76-
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
77+
$this->eventDispatcher->dispatch($event, FOSUserEvents::REGISTRATION_SUCCESS);
7778

7879
$this->userManager->updateUser($user);
7980

@@ -82,13 +83,13 @@ public function registerAction(Request $request)
8283
$response = new RedirectResponse($url);
8384
}
8485

85-
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
86+
$this->eventDispatcher->dispatch(new FilterUserResponseEvent($user, $request, $response), FOSUserEvents::REGISTRATION_COMPLETED);
8687

8788
return $response;
8889
}
8990

9091
$event = new FormEvent($form, $request);
91-
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event);
92+
$this->eventDispatcher->dispatch($event, FOSUserEvents::REGISTRATION_FAILURE);
9293

9394
if (null !== $response = $event->getResponse()) {
9495
return $response;
@@ -144,7 +145,7 @@ public function confirmAction(Request $request, $token)
144145
$user->setEnabled(true);
145146

146147
$event = new GetResponseUserEvent($user, $request);
147-
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRM, $event);
148+
$this->eventDispatcher->dispatch($event, FOSUserEvents::REGISTRATION_CONFIRM);
148149

149150
$userManager->updateUser($user);
150151

@@ -153,7 +154,7 @@ public function confirmAction(Request $request, $token)
153154
$response = new RedirectResponse($url);
154155
}
155156

156-
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRMED, new FilterUserResponseEvent($user, $request, $response));
157+
$this->eventDispatcher->dispatch(new FilterUserResponseEvent($user, $request, $response), FOSUserEvents::REGISTRATION_CONFIRMED);
157158

158159
return $response;
159160
}

Controller/ResettingController.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use FOS\UserBundle\Util\TokenGeneratorInterface;
2323
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
2424
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
25+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2526
use Symfony\Component\HttpFoundation\RedirectResponse;
2627
use Symfony\Component\HttpFoundation\Request;
2728
use Symfony\Component\HttpFoundation\Response;
@@ -52,7 +53,7 @@ class ResettingController extends Controller
5253
*/
5354
public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, TokenGeneratorInterface $tokenGenerator, MailerInterface $mailer, $retryTtl)
5455
{
55-
$this->eventDispatcher = $eventDispatcher;
56+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
5657
$this->formFactory = $formFactory;
5758
$this->userManager = $userManager;
5859
$this->tokenGenerator = $tokenGenerator;
@@ -80,15 +81,15 @@ public function sendEmailAction(Request $request)
8081
$user = $this->userManager->findUserByUsernameOrEmail($username);
8182

8283
$event = new GetResponseNullableUserEvent($user, $request);
83-
$this->eventDispatcher->dispatch(FOSUserEvents::RESETTING_SEND_EMAIL_INITIALIZE, $event);
84+
$this->eventDispatcher->dispatch($event, FOSUserEvents::RESETTING_SEND_EMAIL_INITIALIZE);
8485

8586
if (null !== $event->getResponse()) {
8687
return $event->getResponse();
8788
}
8889

8990
if (null !== $user && !$user->isPasswordRequestNonExpired($this->retryTtl)) {
9091
$event = new GetResponseUserEvent($user, $request);
91-
$this->eventDispatcher->dispatch(FOSUserEvents::RESETTING_RESET_REQUEST, $event);
92+
$this->eventDispatcher->dispatch($event, FOSUserEvents::RESETTING_RESET_REQUEST);
9293

9394
if (null !== $event->getResponse()) {
9495
return $event->getResponse();
@@ -99,7 +100,7 @@ public function sendEmailAction(Request $request)
99100
}
100101

101102
$event = new GetResponseUserEvent($user, $request);
102-
$this->eventDispatcher->dispatch(FOSUserEvents::RESETTING_SEND_EMAIL_CONFIRM, $event);
103+
$this->eventDispatcher->dispatch($event, FOSUserEvents::RESETTING_SEND_EMAIL_CONFIRM);
103104

104105
if (null !== $event->getResponse()) {
105106
return $event->getResponse();
@@ -110,7 +111,7 @@ public function sendEmailAction(Request $request)
110111
$this->userManager->updateUser($user);
111112

112113
$event = new GetResponseUserEvent($user, $request);
113-
$this->eventDispatcher->dispatch(FOSUserEvents::RESETTING_SEND_EMAIL_COMPLETED, $event);
114+
$this->eventDispatcher->dispatch($event, FOSUserEvents::RESETTING_SEND_EMAIL_COMPLETED);
114115

115116
if (null !== $event->getResponse()) {
116117
return $event->getResponse();
@@ -155,7 +156,7 @@ public function resetAction(Request $request, $token)
155156
}
156157

157158
$event = new GetResponseUserEvent($user, $request);
158-
$this->eventDispatcher->dispatch(FOSUserEvents::RESETTING_RESET_INITIALIZE, $event);
159+
$this->eventDispatcher->dispatch($event, FOSUserEvents::RESETTING_RESET_INITIALIZE);
159160

160161
if (null !== $event->getResponse()) {
161162
return $event->getResponse();
@@ -168,7 +169,7 @@ public function resetAction(Request $request, $token)
168169

169170
if ($form->isSubmitted() && $form->isValid()) {
170171
$event = new FormEvent($form, $request);
171-
$this->eventDispatcher->dispatch(FOSUserEvents::RESETTING_RESET_SUCCESS, $event);
172+
$this->eventDispatcher->dispatch($event, FOSUserEvents::RESETTING_RESET_SUCCESS);
172173

173174
$this->userManager->updateUser($user);
174175

@@ -178,8 +179,8 @@ public function resetAction(Request $request, $token)
178179
}
179180

180181
$this->eventDispatcher->dispatch(
181-
FOSUserEvents::RESETTING_RESET_COMPLETED,
182-
new FilterUserResponseEvent($user, $request, $response)
182+
new FilterUserResponseEvent($user, $request, $response),
183+
FOSUserEvents::RESETTING_RESET_COMPLETED
183184
);
184185

185186
return $response;

EventListener/AuthenticationListener.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use FOS\UserBundle\Security\LoginManagerInterface;
1818
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1919
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
20+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2021
use Symfony\Component\Security\Core\Exception\AccountStatusException;
2122

2223
class AuthenticationListener implements EventSubscriberInterface
@@ -59,10 +60,11 @@ public static function getSubscribedEvents()
5960
*/
6061
public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
6162
{
63+
$eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
6264
try {
6365
$this->loginManager->logInUser($this->firewallName, $event->getUser(), $event->getResponse());
6466

65-
$eventDispatcher->dispatch(FOSUserEvents::SECURITY_IMPLICIT_LOGIN, new UserEvent($event->getUser(), $event->getRequest()));
67+
$eventDispatcher->dispatch(new UserEvent($event->getUser(), $event->getRequest()), FOSUserEvents::SECURITY_IMPLICIT_LOGIN);
6668
} catch (AccountStatusException $ex) {
6769
// We simply do not authenticate users which do not pass the user
6870
// checker (not enabled, expired, etc.).

0 commit comments

Comments
 (0)