Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1783fa8
Bumping deps to Symfony4
weaverryan Nov 9, 2017
8a89160
making services and aliases explicitly public where needed
weaverryan Nov 29, 2017
5a46b13
updating ChangePassword to a service controller
weaverryan Dec 6, 2017
5206257
converting GroupController to service
weaverryan Dec 6, 2017
2b8abad
updating ProfileController to a service
weaverryan Dec 6, 2017
bcbe7d1
converting RegistrationController to services
weaverryan Dec 6, 2017
7c10a15
updating ResettingController
weaverryan Dec 6, 2017
b0dba21
removing extra argument
weaverryan Dec 6, 2017
890c25c
changing 2 missed base classes
weaverryan Dec 6, 2017
9007625
updating SecurityController to a service
weaverryan Dec 6, 2017
af2b38f
Refactoring all commands away from using the service locator
weaverryan Dec 6, 2017
41a9fd8
reverting some public services
weaverryan Dec 6, 2017
e89b9ba
adding dependency on symfony/validator - needed by ValidationPass
weaverryan Dec 6, 2017
f2133be
adding the missing Action route suffixes!
weaverryan Dec 7, 2017
eaffd1d
removing dev changes
weaverryan Dec 7, 2017
255d13c
Adding a new compiler pass to notify that the session is required
weaverryan Dec 8, 2017
f9d8e00
removing duplicate symfony/validator in require-dev
weaverryan Dec 8, 2017
676e594
Adding a check for the mailer service
weaverryan Dec 8, 2017
a5dbd62
fixing all command tests
weaverryan Dec 8, 2017
8421644
moving mailer loader back: its parameters need to be loaded first
weaverryan Dec 8, 2017
9d0f356
fixing cs
weaverryan Dec 8, 2017
9e6405b
Adding missing check for mailer
weaverryan Dec 9, 2017
6f3c49c
fixing wrong hasDefinition check
weaverryan Dec 15, 2017
3543471
fixing duplicate travis job
weaverryan Dec 15, 2017
bad2716
removing variables that are only used once + fixing 2 bugs with
weaverryan Dec 17, 2017
c63ae31
Making more updates after a new feature was merged
weaverryan Dec 18, 2017
96b222a
removing duplicated route from #2612 and fixing other controller
weaverryan Dec 18, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ php:
- 5.6
- 7.0
- 7.1
- hhvm

env:
global:
Expand All @@ -19,9 +18,9 @@ matrix:
- php: 5.5
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 5.6
env: SYMFONY_VERSION=2.8.*
allow_failures:
- php: hhvm
env: DEPENDENCIES="symfony/lts:^2"
- php: 7.1
env: DEPENDENCIES="symfony/lts:^3"

sudo: false

Expand All @@ -30,8 +29,8 @@ cache:
- $HOME/.composer/cache

before_install:
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi;
- if [[ -v $DEPENDENCIES ]]; then composer require --no-update $DEPENDENCIES; fi;
- echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS

Expand Down
18 changes: 15 additions & 3 deletions Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
*/
Expand All @@ -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;
Copy link

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->userManipulator->activate($username);

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

@XWB XWB Dec 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can definitely make these changes if you want.

@weaverryan Yes please :)

$manipulator->activate($username);

$output->writeln(sprintf('User "%s" has been activated.', $username));
Expand Down
18 changes: 15 additions & 3 deletions Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,8 +21,19 @@
/**
* ChangePasswordCommand.
*/
class ChangePasswordCommand extends ContainerAwareCommand
class ChangePasswordCommand extends Command
{
protected static $defaultName = 'fos:user:change-password';

private $userManipulator;

public function __construct(UserManipulator $userManipulator)
{
parent::__construct();

$this->userManipulator = $userManipulator;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -57,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$username = $input->getArgument('username');
$password = $input->getArgument('password');

$manipulator = $this->getContainer()->get('fos_user.util.user_manipulator');
$manipulator = $this->userManipulator;
$manipulator->changePassword($username, $password);

$output->writeln(sprintf('Changed password for user <comment>%s</comment>', $username));
Expand Down
18 changes: 15 additions & 3 deletions Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
*/
Expand Down Expand Up @@ -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));
Expand Down
18 changes: 15 additions & 3 deletions Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
*/
Expand All @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions Command/DemoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
class DemoteUserCommand extends RoleCommand
{
protected static $defaultName = 'fos:user:demote';

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 2 additions & 0 deletions Command/PromoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
class PromoteUserCommand extends RoleCommand
{
protected static $defaultName = 'fos:user:promote';

/**
* {@inheritdoc}
*/
Expand Down
15 changes: 12 additions & 3 deletions Command/RoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
*/
Expand Down Expand Up @@ -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);
}

Expand Down
28 changes: 16 additions & 12 deletions Controller/ChangePasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,8 +31,19 @@
* @author Thibault Duplessis <[email protected]>
* @author Christophe Coevoet <[email protected]>
*/
class ChangePasswordController extends Controller
class ChangePasswordController extends AbstractController
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why extend the AbstractController as you are injecting the services ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're still using some of the shortcut methods - e.g. generateUrl(). And those are more than just shortcuts - using the shortcut methods gives you lazy services - e.g. no need to inject a Router service if only 1 of 4 method needs it. By using generateUrl() it's only loaded when needed. Ok, router is a bad example - but that's the idea :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about injecting lazy Router service then ?

Instead of making this controller as hybrid, isn't it better to make all dependencies explicit ?
just curious.

{
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.
*
Expand All @@ -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);
Expand All @@ -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');
Expand Down
Loading