1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the awurth/silex-user package. |
5
|
|
|
* |
6
|
|
|
* (c) Alexis Wurth <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace AWurth\Silex\User\Command; |
13
|
|
|
|
14
|
|
|
use AWurth\Silex\User\Util\UserManipulator; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Matthieu Bontemps <[email protected]> |
19
|
|
|
* @author Thibault Duplessis <[email protected]> |
20
|
|
|
* @author Luis Cordova <[email protected]> |
21
|
|
|
* @author Lenar Lõhmus <[email protected]> |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
class PromoteUserCommand extends RoleCommand |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function configure() |
29
|
|
|
{ |
30
|
|
|
parent::configure(); |
31
|
|
|
|
32
|
|
|
$this |
33
|
|
|
->setName('silex-user:promote') |
34
|
|
|
->setDescription('Promotes a user by adding a role') |
35
|
|
|
->setHelp(<<<'EOT' |
36
|
|
|
The <info>silex-user:promote</info> command promotes a user by adding a role |
37
|
|
|
|
38
|
|
|
<info>php %command.full_name% matthieu ROLE_CUSTOM</info> |
39
|
|
|
<info>php %command.full_name% --super matthieu</info> |
40
|
|
|
EOT |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
protected function executeRoleCommand(UserManipulator $manipulator, OutputInterface $output, $username, $super, $role) |
48
|
|
|
{ |
49
|
|
|
if ($super) { |
50
|
|
|
$manipulator->promote($username); |
51
|
|
|
$output->writeln(sprintf('User "%s" has been promoted as a super administrator. This change will not apply until the user logs out and back in again.', $username)); |
52
|
|
|
} else { |
53
|
|
|
if ($manipulator->addRole($username, $role)) { |
54
|
|
|
$output->writeln(sprintf('Role "%s" has been added to user "%s". This change will not apply until the user logs out and back in again.', $role, $username)); |
55
|
|
|
} else { |
56
|
|
|
$output->writeln(sprintf('User "%s" did already have "%s" role.', $username, $role)); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.