|
18 | 18 |
|
19 | 19 | namespace Drupal\Console\Command\Chain; |
20 | 20 |
|
21 | | -use Symfony\Component\Console\Input\InputArgument; |
22 | | -use Symfony\Component\Console\Input\InputOption; |
| 21 | +use Symfony\Component\Console\Input\ArrayInput; |
23 | 22 | use Symfony\Component\Console\Input\InputInterface; |
24 | 23 | use Symfony\Component\Console\Output\OutputInterface; |
25 | | -use Symfony\Component\Yaml\Parser; |
26 | | -use Symfony\Component\Console\Application; |
27 | | -use Drupal\Console\Utils\ConfigurationManager; |
| 24 | +use Symfony\Component\Console\Input\InputOption; |
28 | 25 | use Symfony\Component\Console\Command\Command; |
29 | 26 | use Drupal\Console\Command\Shared\ChainFilesTrait; |
30 | | -use Drupal\Console\Style\DrupalStyle; |
| 27 | +use Drupal\Console\Command\Shared\CommandTrait; |
| 28 | + |
31 | 29 | /** |
32 | 30 | * Class ChainRegister |
33 | 31 | * |
34 | 32 | * @package Drupal\Console\Command\ChainRegister |
35 | 33 | */ |
36 | | -class ChainRegister extends ChainCommand { |
37 | | - use ChainFilesTrait; |
| 34 | +class ChainRegister extends Command |
| 35 | +{ |
| 36 | + use CommandTrait; |
| 37 | + use ChainFilesTrait; |
38 | 38 |
|
39 | | - /** |
| 39 | + protected $name; |
| 40 | + |
| 41 | + protected $file; |
| 42 | + |
| 43 | + /** |
40 | 44 | * ChainRegister constructor. |
41 | 45 | * |
42 | | - * @param $name Chain name |
43 | | - * @param $file File name |
| 46 | + * @param $name |
| 47 | + * @param $file |
44 | 48 | */ |
45 | | - public function __construct($name, $file) { |
46 | | - $this->setName($name); |
47 | | - $this->setFile($file); |
| 49 | + public function __construct($name, $file) |
| 50 | + { |
| 51 | + $this->name = $name; |
| 52 | + $this->file = $file; |
48 | 53 |
|
49 | | - parent::__construct(); |
50 | | - } |
| 54 | + parent::__construct(); |
| 55 | + } |
51 | 56 |
|
52 | | - /** |
| 57 | + /** |
53 | 58 | * {@inheritdoc} |
54 | 59 | */ |
55 | | - protected function configure() { |
56 | | - parent::configure(); |
57 | | - } |
| 60 | + protected function configure() |
| 61 | + { |
| 62 | + $this |
| 63 | + ->setName($this->name) |
| 64 | + ->setDescription(sprintf('Custom chain command (%s)', $this->name)) |
| 65 | + ->addOption( |
| 66 | + 'placeholder', |
| 67 | + null, |
| 68 | + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, |
| 69 | + $this->trans('commands.chain.options.placeholder') |
| 70 | + ); |
| 71 | + } |
58 | 72 |
|
59 | | - /** |
| 73 | + /** |
60 | 74 | * {@inheritdoc} |
61 | 75 | */ |
62 | | - protected function execute(InputInterface $input, OutputInterface $output) { |
63 | | - parent::interact($input, $output); |
64 | | - |
65 | | - $io = new DrupalStyle($input, $output); |
66 | | - |
67 | | - // Populate placeholders. |
68 | | - $placeholders = ''; |
69 | | - foreach ($input->getOption('placeholder') as $placeholder) { |
70 | | - $placeholders .= sprintf('--placeholder="%s" ', |
71 | | - $placeholder |
72 | | - ); |
73 | | - } |
74 | | - |
75 | | - $command = sprintf('drupal chain --file %s %s', |
76 | | - $this->file, |
77 | | - $placeholders |
78 | | - ); |
| 76 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 77 | + { |
| 78 | + $command = $this->getApplication()->find('chain'); |
79 | 79 |
|
80 | | - // Run. |
81 | | - $shellProcess = $this->get('shell_process'); |
| 80 | + $arguments = [ |
| 81 | + 'command' => 'chain', |
| 82 | + '--file' => $this->file, |
| 83 | + '--placeholder' => $input->getOption('placeholder'), |
| 84 | + '--generate-inline' => $input->hasOption('generate-inline'), |
| 85 | + '--no-interaction' => $input->hasOption('no-interaction') |
| 86 | + ]; |
82 | 87 |
|
83 | | - if (!$shellProcess->exec($command, TRUE)) { |
84 | | - $io->error( |
85 | | - sprintf( |
86 | | - $this->trans('commands.exec.messages.invalid-bin') |
87 | | - ) |
88 | | - ); |
| 88 | + $commandInput = new ArrayInput($arguments); |
89 | 89 |
|
90 | | - return 1; |
| 90 | + return $command->run($commandInput, $output); |
91 | 91 | } |
92 | | - } |
93 | 92 | } |
0 commit comments