|
9 | 9 | use MsgPhp\Domain\Infrastructure\Console\Definition\DomainContextDefinition; |
10 | 10 | use MsgPhp\User\Command\ChangeUserCredential; |
11 | 11 | use MsgPhp\User\Infrastructure\Console\Definition\UserDefinition; |
12 | | -use MsgPhp\User\Repository\UserRepository; |
| 12 | +use Symfony\Component\Console\Command\Command; |
13 | 13 | use Symfony\Component\Console\Input\ArrayInput; |
14 | 14 | use Symfony\Component\Console\Input\InputInterface; |
15 | 15 | use Symfony\Component\Console\Output\OutputInterface; |
|
18 | 18 | /** |
19 | 19 | * @author Roland Franssen <franssen.roland@gmail.com> |
20 | 20 | */ |
21 | | -final class ChangeUserCredentialCommand extends UserCommand |
| 21 | +final class ChangeUserCredentialCommand extends Command |
22 | 22 | { |
23 | 23 | protected static $defaultName = 'user:change-credential'; |
24 | 24 |
|
25 | | - /** @var DomainContextDefinition */ |
| 25 | + /** @var DomainObjectFactory */ |
| 26 | + private $factory; |
| 27 | + /** @var DomainMessageBus */ |
| 28 | + private $bus; |
| 29 | + /** @var UserDefinition */ |
26 | 30 | private $definition; |
| 31 | + /** @var DomainContextDefinition */ |
| 32 | + private $contextDefinition; |
27 | 33 | /** @var array<int, string> */ |
28 | 34 | private $fields = []; |
29 | 35 |
|
30 | | - public function __construct(DomainObjectFactory $factory, DomainMessageBus $bus, UserRepository $repository, DomainContextDefinition $definition) |
| 36 | + public function __construct(DomainObjectFactory $factory, DomainMessageBus $bus, UserDefinition $definition, DomainContextDefinition $contextDefinition) |
31 | 37 | { |
| 38 | + $this->factory = $factory; |
| 39 | + $this->bus = $bus; |
32 | 40 | $this->definition = $definition; |
| 41 | + $this->contextDefinition = $contextDefinition; |
33 | 42 |
|
34 | | - parent::__construct($factory, $bus, $repository); |
| 43 | + parent::__construct(); |
35 | 44 | } |
36 | 45 |
|
37 | 46 | protected function configure(): void |
38 | 47 | { |
39 | | - parent::configure(); |
40 | | - |
41 | 48 | $this->setDescription('Change a user credential'); |
42 | | - |
43 | | - $definition = $this->getDefinition(); |
44 | | - $currentFields = array_keys($definition->getOptions() + $definition->getArguments()); |
45 | | - |
46 | 49 | $this->definition->configure($this->getDefinition()); |
47 | | - $this->fields = array_values(array_diff(array_keys($definition->getOptions() + $definition->getArguments()), $currentFields)); |
| 50 | + |
| 51 | + $currentFields = array_keys($this->getDefinition()->getOptions() + $this->getDefinition()->getArguments()); |
| 52 | + $this->contextDefinition->configure($this->getDefinition()); |
| 53 | + $this->fields = array_values(array_diff(array_keys($this->getDefinition()->getOptions() + $this->getDefinition()->getArguments()), $currentFields)); |
48 | 54 | } |
49 | 55 |
|
50 | 56 | protected function execute(InputInterface $input, OutputInterface $output): int |
51 | 57 | { |
52 | 58 | $io = new SymfonyStyle($input, $output); |
53 | | - $user = $this->getUser($input, $io); |
| 59 | + $user = $this->definition->getUser($input, $io); |
54 | 60 | $userId = $user->getId(); |
55 | | - $fields = $this->definition->getContext($input, $io); |
| 61 | + $fields = $this->contextDefinition->getContext($input, $io); |
56 | 62 |
|
57 | 63 | if (!$fields) { |
58 | 64 | $field = $io->choice('Select a field to change', $this->fields); |
|
0 commit comments