Skip to content

Commit 8ecef90

Browse files
authored
Merge pull request #2639 from weaverryan/patch-1
Adding Symfony4 support
2 parents 287a090 + 96b222a commit 8ecef90

41 files changed

Lines changed: 463 additions & 282 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ php:
55
- 5.6
66
- 7.0
77
- 7.1
8-
- hhvm
98

109
env:
1110
global:
@@ -19,9 +18,9 @@ matrix:
1918
- php: 5.5
2019
env: COMPOSER_FLAGS="--prefer-lowest"
2120
- php: 5.6
22-
env: SYMFONY_VERSION=2.8.*
23-
allow_failures:
24-
- php: hhvm
21+
env: DEPENDENCIES="symfony/lts:^2"
22+
- php: 7.1
23+
env: DEPENDENCIES="symfony/lts:^3"
2524

2625
sudo: false
2726

@@ -30,8 +29,8 @@ cache:
3029
- $HOME/.composer/cache
3130

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

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

Command/ActivateUserCommand.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace FOS\UserBundle\Command;
1313

14-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14+
use FOS\UserBundle\Util\UserManipulator;
15+
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -20,8 +21,19 @@
2021
/**
2122
* @author Antoine Hérault <antoine.herault@gmail.com>
2223
*/
23-
class ActivateUserCommand extends ContainerAwareCommand
24+
class ActivateUserCommand extends Command
2425
{
26+
protected static $defaultName = 'fos:user:activate';
27+
28+
private $userManipulator;
29+
30+
public function __construct(UserManipulator $userManipulator)
31+
{
32+
parent::__construct();
33+
34+
$this->userManipulator = $userManipulator;
35+
}
36+
2537
/**
2638
* {@inheritdoc}
2739
*/
@@ -48,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4860
{
4961
$username = $input->getArgument('username');
5062

51-
$manipulator = $this->getContainer()->get('fos_user.util.user_manipulator');
63+
$manipulator = $this->userManipulator;
5264
$manipulator->activate($username);
5365

5466
$output->writeln(sprintf('User "%s" has been activated.', $username));

Command/ChangePasswordCommand.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace FOS\UserBundle\Command;
1313

14-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14+
use FOS\UserBundle\Util\UserManipulator;
15+
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -20,8 +21,19 @@
2021
/**
2122
* ChangePasswordCommand.
2223
*/
23-
class ChangePasswordCommand extends ContainerAwareCommand
24+
class ChangePasswordCommand extends Command
2425
{
26+
protected static $defaultName = 'fos:user:change-password';
27+
28+
private $userManipulator;
29+
30+
public function __construct(UserManipulator $userManipulator)
31+
{
32+
parent::__construct();
33+
34+
$this->userManipulator = $userManipulator;
35+
}
36+
2537
/**
2638
* {@inheritdoc}
2739
*/
@@ -57,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5769
$username = $input->getArgument('username');
5870
$password = $input->getArgument('password');
5971

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

6375
$output->writeln(sprintf('Changed password for user <comment>%s</comment>', $username));

Command/CreateUserCommand.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace FOS\UserBundle\Command;
1313

14-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14+
use FOS\UserBundle\Util\UserManipulator;
15+
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Input\InputOption;
@@ -23,8 +24,19 @@
2324
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
2425
* @author Luis Cordova <cordoval@gmail.com>
2526
*/
26-
class CreateUserCommand extends ContainerAwareCommand
27+
class CreateUserCommand extends Command
2728
{
29+
protected static $defaultName = 'fos:user:create';
30+
31+
private $userManipulator;
32+
33+
public function __construct(UserManipulator $userManipulator)
34+
{
35+
parent::__construct();
36+
37+
$this->userManipulator = $userManipulator;
38+
}
39+
2840
/**
2941
* {@inheritdoc}
3042
*/
@@ -74,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7486
$inactive = $input->getOption('inactive');
7587
$superadmin = $input->getOption('super-admin');
7688

77-
$manipulator = $this->getContainer()->get('fos_user.util.user_manipulator');
89+
$manipulator = $this->userManipulator;
7890
$manipulator->create($username, $password, $email, !$inactive, $superadmin);
7991

8092
$output->writeln(sprintf('Created user <comment>%s</comment>', $username));

Command/DeactivateUserCommand.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace FOS\UserBundle\Command;
1313

14-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14+
use FOS\UserBundle\Util\UserManipulator;
15+
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -20,8 +21,19 @@
2021
/**
2122
* @author Antoine Hérault <antoine.herault@gmail.com>
2223
*/
23-
class DeactivateUserCommand extends ContainerAwareCommand
24+
class DeactivateUserCommand extends Command
2425
{
26+
protected static $defaultName = 'fos:user:deactivate';
27+
28+
private $userManipulator;
29+
30+
public function __construct(UserManipulator $userManipulator)
31+
{
32+
parent::__construct();
33+
34+
$this->userManipulator = $userManipulator;
35+
}
36+
2537
/**
2638
* {@inheritdoc}
2739
*/
@@ -48,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4860
{
4961
$username = $input->getArgument('username');
5062

51-
$manipulator = $this->getContainer()->get('fos_user.util.user_manipulator');
63+
$manipulator = $this->userManipulator;
5264
$manipulator->deactivate($username);
5365

5466
$output->writeln(sprintf('User "%s" has been deactivated.', $username));

Command/DemoteUserCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
class DemoteUserCommand extends RoleCommand
2222
{
23+
protected static $defaultName = 'fos:user:demote';
24+
2325
/**
2426
* {@inheritdoc}
2527
*/

Command/PromoteUserCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
class PromoteUserCommand extends RoleCommand
2424
{
25+
protected static $defaultName = 'fos:user:promote';
26+
2527
/**
2628
* {@inheritdoc}
2729
*/

Command/RoleCommand.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace FOS\UserBundle\Command;
1313

1414
use FOS\UserBundle\Util\UserManipulator;
15-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15+
use Symfony\Component\Console\Command\Command;
1616
use Symfony\Component\Console\Input\InputArgument;
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Input\InputOption;
@@ -22,8 +22,17 @@
2222
/**
2323
* @author Lenar Lõhmus <lenar@city.ee>
2424
*/
25-
abstract class RoleCommand extends ContainerAwareCommand
25+
abstract class RoleCommand extends Command
2626
{
27+
private $userManipulator;
28+
29+
public function __construct(UserManipulator $userManipulator)
30+
{
31+
parent::__construct();
32+
33+
$this->userManipulator = $userManipulator;
34+
}
35+
2736
/**
2837
* {@inheritdoc}
2938
*/
@@ -54,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5463
throw new \RuntimeException('Not enough arguments.');
5564
}
5665

57-
$manipulator = $this->getContainer()->get('fos_user.util.user_manipulator');
66+
$manipulator = $this->userManipulator;
5867
$this->executeRoleCommand($manipulator, $output, $username, $super, $role);
5968
}
6069

Controller/ChangePasswordController.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use FOS\UserBundle\FOSUserEvents;
1919
use FOS\UserBundle\Model\UserInterface;
2020
use FOS\UserBundle\Model\UserManagerInterface;
21-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
21+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2222
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2323
use Symfony\Component\HttpFoundation\RedirectResponse;
2424
use Symfony\Component\HttpFoundation\Request;
@@ -31,8 +31,19 @@
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

Comments
 (0)