1818use FOS \UserBundle \FOSUserEvents ;
1919use FOS \UserBundle \Model \UserInterface ;
2020use FOS \UserBundle \Model \UserManagerInterface ;
21- use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
21+ use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
2222use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
2323use Symfony \Component \HttpFoundation \RedirectResponse ;
2424use Symfony \Component \HttpFoundation \Request ;
3131 * @author Thibault Duplessis <thibault.duplessis@gmail.com>
3232 * @author Christophe Coevoet <stof@notk.org>
3333 */
34- class ChangePasswordController extends Controller
34+ class ChangePasswordController extends AbstractController
3535{
36+ private $ eventDispatcher ;
37+ private $ formFactory ;
38+ private $ userManager ;
39+
40+ public function __construct (EventDispatcherInterface $ eventDispatcher , FactoryInterface $ formFactory , UserManagerInterface $ userManager )
41+ {
42+ $ this ->eventDispatcher = $ eventDispatcher ;
43+ $ this ->formFactory = $ formFactory ;
44+ $ this ->userManager = $ userManager ;
45+ }
46+
3647 /**
3748 * Change user password.
3849 *
@@ -47,8 +58,7 @@ public function changePasswordAction(Request $request)
4758 throw new AccessDeniedException ('This user does not have access to this section. ' );
4859 }
4960
50- /** @var $dispatcher EventDispatcherInterface */
51- $ dispatcher = $ this ->get ('event_dispatcher ' );
61+ $ dispatcher = $ this ->eventDispatcher ;
5262
5363 $ event = new GetResponseUserEvent ($ user , $ request );
5464 $ dispatcher ->dispatch (FOSUserEvents::CHANGE_PASSWORD_INITIALIZE , $ event );
@@ -57,22 +67,16 @@ public function changePasswordAction(Request $request)
5767 return $ event ->getResponse ();
5868 }
5969
60- /** @var $formFactory FactoryInterface */
61- $ formFactory = $ this ->get ('fos_user.change_password.form.factory ' );
62-
63- $ form = $ formFactory ->createForm ();
70+ $ form = $ this ->formFactory ->createForm ();
6471 $ form ->setData ($ user );
6572
6673 $ form ->handleRequest ($ request );
6774
6875 if ($ form ->isSubmitted () && $ form ->isValid ()) {
69- /** @var $userManager UserManagerInterface */
70- $ userManager = $ this ->get ('fos_user.user_manager ' );
71-
7276 $ event = new FormEvent ($ form , $ request );
7377 $ dispatcher ->dispatch (FOSUserEvents::CHANGE_PASSWORD_SUCCESS , $ event );
7478
75- $ userManager ->updateUser ($ user );
79+ $ this -> userManager ->updateUser ($ user );
7680
7781 if (null === $ response = $ event ->getResponse ()) {
7882 $ url = $ this ->generateUrl ('fos_user_profile_show ' );
0 commit comments