-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Adding Symfony4 support #2639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Symfony4 support #2639
Changes from all commits
1783fa8
8a89160
5a46b13
5206257
2b8abad
bcbe7d1
7c10a15
b0dba21
890c25c
9007625
af2b38f
41a9fd8
e89b9ba
f2133be
eaffd1d
255d13c
f9d8e00
676e594
a5dbd62
8421644
9d0f356
9e6405b
6f3c49c
3543471
bad2716
c63ae31
96b222a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,8 @@ | |
|
|
||
| namespace FOS\UserBundle\Command; | ||
|
|
||
| use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
| use FOS\UserBundle\Util\UserManipulator; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputArgument; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
@@ -20,8 +21,19 @@ | |
| /** | ||
| * @author Antoine Hérault <[email protected]> | ||
| */ | ||
| class ActivateUserCommand extends ContainerAwareCommand | ||
| class ActivateUserCommand extends Command | ||
| { | ||
| protected static $defaultName = 'fos:user:activate'; | ||
|
|
||
| private $userManipulator; | ||
|
|
||
| public function __construct(UserManipulator $userManipulator) | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| $this->userManipulator = $userManipulator; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
|
|
@@ -48,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
| { | ||
| $username = $input->getArgument('username'); | ||
|
|
||
| $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); | ||
| $manipulator = $this->userManipulator; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to make the diff as small as possible, to help review this and get a faster merge. I can definitely make these changes if you want.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@weaverryan Yes please :) |
||
| $manipulator->activate($username); | ||
|
|
||
| $output->writeln(sprintf('User "%s" has been activated.', $username)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,8 @@ | |
|
|
||
| namespace FOS\UserBundle\Command; | ||
|
|
||
| use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
| use FOS\UserBundle\Util\UserManipulator; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputArgument; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
|
|
@@ -23,8 +24,19 @@ | |
| * @author Thibault Duplessis <[email protected]> | ||
| * @author Luis Cordova <[email protected]> | ||
| */ | ||
| class CreateUserCommand extends ContainerAwareCommand | ||
| class CreateUserCommand extends Command | ||
| { | ||
| protected static $defaultName = 'fos:user:create'; | ||
|
|
||
| private $userManipulator; | ||
|
|
||
| public function __construct(UserManipulator $userManipulator) | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| $this->userManipulator = $userManipulator; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
|
|
@@ -74,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
| $inactive = $input->getOption('inactive'); | ||
| $superadmin = $input->getOption('super-admin'); | ||
|
|
||
| $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); | ||
| $manipulator = $this->userManipulator; | ||
| $manipulator->create($username, $password, $email, !$inactive, $superadmin); | ||
|
|
||
| $output->writeln(sprintf('Created user <comment>%s</comment>', $username)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,8 @@ | |
|
|
||
| namespace FOS\UserBundle\Command; | ||
|
|
||
| use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
| use FOS\UserBundle\Util\UserManipulator; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputArgument; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
@@ -20,8 +21,19 @@ | |
| /** | ||
| * @author Antoine Hérault <[email protected]> | ||
| */ | ||
| class DeactivateUserCommand extends ContainerAwareCommand | ||
| class DeactivateUserCommand extends Command | ||
| { | ||
| protected static $defaultName = 'fos:user:deactivate'; | ||
|
|
||
| private $userManipulator; | ||
|
|
||
| public function __construct(UserManipulator $userManipulator) | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| $this->userManipulator = $userManipulator; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
|
|
@@ -48,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
| { | ||
| $username = $input->getArgument('username'); | ||
|
|
||
| $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); | ||
| $manipulator = $this->userManipulator; | ||
| $manipulator->deactivate($username); | ||
|
|
||
| $output->writeln(sprintf('User "%s" has been deactivated.', $username)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| namespace FOS\UserBundle\Command; | ||
|
|
||
| use FOS\UserBundle\Util\UserManipulator; | ||
| use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputArgument; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
|
|
@@ -22,8 +22,17 @@ | |
| /** | ||
| * @author Lenar Lõhmus <[email protected]> | ||
| */ | ||
| abstract class RoleCommand extends ContainerAwareCommand | ||
| abstract class RoleCommand extends Command | ||
| { | ||
| private $userManipulator; | ||
|
|
||
| public function __construct(UserManipulator $userManipulator) | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| $this->userManipulator = $userManipulator; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
|
|
@@ -54,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
| throw new \RuntimeException('Not enough arguments.'); | ||
| } | ||
|
|
||
| $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); | ||
| $manipulator = $this->userManipulator; | ||
| $this->executeRoleCommand($manipulator, $output, $username, $super, $role); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| use FOS\UserBundle\FOSUserEvents; | ||
| use FOS\UserBundle\Model\UserInterface; | ||
| use FOS\UserBundle\Model\UserManagerInterface; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
| use Symfony\Component\HttpFoundation\RedirectResponse; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
@@ -31,8 +31,19 @@ | |
| * @author Thibault Duplessis <[email protected]> | ||
| * @author Christophe Coevoet <[email protected]> | ||
| */ | ||
| class ChangePasswordController extends Controller | ||
| class ChangePasswordController extends AbstractController | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why extend the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're still using some of the shortcut methods - e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about injecting Instead of making this controller as hybrid, isn't it better to make all dependencies explicit ? |
||
| { | ||
| private $eventDispatcher; | ||
| private $formFactory; | ||
| private $userManager; | ||
|
|
||
| public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager) | ||
| { | ||
| $this->eventDispatcher = $eventDispatcher; | ||
| $this->formFactory = $formFactory; | ||
| $this->userManager = $userManager; | ||
| } | ||
|
|
||
| /** | ||
| * Change user password. | ||
| * | ||
|
|
@@ -47,8 +58,7 @@ public function changePasswordAction(Request $request) | |
| throw new AccessDeniedException('This user does not have access to this section.'); | ||
| } | ||
|
|
||
| /** @var $dispatcher EventDispatcherInterface */ | ||
| $dispatcher = $this->get('event_dispatcher'); | ||
| $dispatcher = $this->eventDispatcher; | ||
|
|
||
| $event = new GetResponseUserEvent($user, $request); | ||
| $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event); | ||
|
|
@@ -57,22 +67,16 @@ public function changePasswordAction(Request $request) | |
| return $event->getResponse(); | ||
| } | ||
|
|
||
| /** @var $formFactory FactoryInterface */ | ||
| $formFactory = $this->get('fos_user.change_password.form.factory'); | ||
|
|
||
| $form = $formFactory->createForm(); | ||
| $form = $this->formFactory->createForm(); | ||
| $form->setData($user); | ||
|
|
||
| $form->handleRequest($request); | ||
|
|
||
| if ($form->isSubmitted() && $form->isValid()) { | ||
| /** @var $userManager UserManagerInterface */ | ||
| $userManager = $this->get('fos_user.user_manager'); | ||
|
|
||
| $event = new FormEvent($form, $request); | ||
| $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_SUCCESS, $event); | ||
|
|
||
| $userManager->updateUser($user); | ||
| $this->userManager->updateUser($user); | ||
|
|
||
| if (null === $response = $event->getResponse()) { | ||
| $url = $this->generateUrl('fos_user_profile_show'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this local variable?