|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BrainExe\Core\Console; |
|
4
|
|
|
|
|
5
|
|
|
use BrainExe\Core\Authentication\Register; |
|
6
|
|
|
use BrainExe\Core\Authentication\UserVO; |
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; |
|
13
|
|
|
use BrainExe\Core\Annotations\Command as CommandAnnotation; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @CommandAnnotation |
|
17
|
|
|
*/ |
|
18
|
|
|
class CreateUserCommand extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Register |
|
23
|
|
|
*/ |
|
24
|
|
|
private $register; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
2 |
|
protected function configure() |
|
30
|
|
|
{ |
|
31
|
2 |
|
$this->setName('user:create') |
|
32
|
2 |
|
->setDescription('Create user') |
|
33
|
2 |
|
->addArgument('username', InputArgument::REQUIRED, 'username') |
|
34
|
2 |
|
->addArgument('password', InputArgument::REQUIRED, 'PLAIN password') |
|
35
|
2 |
|
->addArgument('roles', InputArgument::OPTIONAL, 'roles (comma-separated)'); |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param Register $register |
|
40
|
|
|
*/ |
|
41
|
2 |
|
public function __construct(Register $register) |
|
42
|
|
|
{ |
|
43
|
2 |
|
$this->register = $register; |
|
44
|
|
|
|
|
45
|
2 |
|
parent::__construct(); |
|
46
|
2 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
52
|
|
|
{ |
|
53
|
1 |
|
$username = $input->getArgument('username'); |
|
54
|
1 |
|
$password = $input->getArgument('password'); |
|
55
|
1 |
|
$roles = explode(',', $input->getArgument('roles')); |
|
56
|
|
|
|
|
57
|
1 |
|
$user = new UserVO(); |
|
58
|
1 |
|
$user->username = $username; |
|
59
|
1 |
|
$user->password = $password; |
|
60
|
1 |
|
$user->roles = $roles; |
|
61
|
|
|
|
|
62
|
1 |
|
$session = new Session(new MockArraySessionStorage()); |
|
63
|
1 |
|
$userId = $this->register->registerUser($user, $session, null); |
|
64
|
|
|
|
|
65
|
1 |
|
$output->writeln(sprintf('New user-id: <info>%d</info>', $userId)); |
|
66
|
1 |
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|