|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkMultiUserBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
final class CreateUserCommand extends UserCommand |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var UserRepositoryCollection |
|
15
|
|
|
*/ |
|
16
|
|
|
private $userRepositoryCollection; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var CreateUserHandler |
|
20
|
|
|
*/ |
|
21
|
|
|
private $handler; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* CreateUserCommand constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param UserRepositoryCollection $userRepositoryCollection |
|
27
|
|
|
* @param CreateUserHandler $handler |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(UserRepositoryCollection $userRepositoryCollection, CreateUserHandler $handler) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
$this->userRepositoryCollection = $userRepositoryCollection; |
|
33
|
|
|
$this->handler = $handler; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function configure() |
|
37
|
|
|
{ |
|
38
|
|
|
$this |
|
39
|
|
|
->setName('sumocoders:multiuser:create') |
|
40
|
|
|
->setDescription('Create a user entity') |
|
41
|
|
|
->addArgument( |
|
42
|
|
|
'username', |
|
43
|
|
|
InputArgument::REQUIRED, |
|
44
|
|
|
'The username of the user' |
|
45
|
|
|
) |
|
46
|
|
|
->addArgument( |
|
47
|
|
|
'password', |
|
48
|
|
|
InputArgument::REQUIRED, |
|
49
|
|
|
'The password for the user' |
|
50
|
|
|
) |
|
51
|
|
|
->addArgument( |
|
52
|
|
|
'displayName', |
|
53
|
|
|
InputArgument::REQUIRED, |
|
54
|
|
|
'The display name for the user' |
|
55
|
|
|
) |
|
56
|
|
|
->addOption( |
|
57
|
|
|
'class', |
|
58
|
|
|
null, |
|
59
|
|
|
InputOption::VALUE_OPTIONAL, |
|
60
|
|
|
'The class off the user' |
|
61
|
|
|
) |
|
62
|
|
|
; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
66
|
|
|
{ |
|
67
|
|
|
$availableUserClasses = $this->getAllValidUserClasses($this->userRepositoryCollection); |
|
68
|
|
|
|
|
69
|
|
|
$userClass = $this->getUserClass($input, $output, $availableUserClasses); |
|
70
|
|
|
|
|
71
|
|
|
$username = $input->getArgument('username'); |
|
72
|
|
|
$password = $input->getArgument('password'); |
|
73
|
|
|
$displayName = $input->getArgument('displayName'); |
|
74
|
|
|
|
|
75
|
|
|
$command = new CreateUser($username, $password, $displayName); |
|
76
|
|
|
|
|
77
|
|
|
$this->handler->handle($command, $userClass); |
|
78
|
|
|
|
|
79
|
|
|
$output->writeln($username . ' has been created'); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|