Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console-core / src / Command / Chain / ChainCustomCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Core\Command\ChainCustomCommand.
6  */
7
8 namespace Drupal\Console\Core\Command\Chain;
9
10 use Symfony\Component\Console\Input\ArrayInput;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Input\InputOption;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Core\Command\Shared\InputTrait;
17
18 /**
19  * Class ChainCustomCommand
20  *
21  * @package Drupal\Console\Core\Command\ChainRegister
22  */
23 class ChainCustomCommand extends Command
24 {
25     use CommandTrait;
26     use InputTrait;
27
28     /**
29      * @var string
30      */
31     protected $name;
32
33     /**
34      * @var string
35      */
36     protected $description;
37
38     /**
39      * @var string
40      */
41     protected $file;
42
43     /**
44      * ChainRegister constructor.
45      *
46      * @param $name
47      * @param $description
48      * @param $file
49      */
50     public function __construct($name, $description, $file)
51     {
52         $this->name = $name;
53         $this->description = $description;
54         $this->file = $file;
55
56         parent::__construct();
57     }
58
59     /**
60      * {@inheritdoc}
61      */
62     protected function configure()
63     {
64         $this
65             ->setName($this->name)
66             ->setDescription($this->description)
67             ->addOption(
68                 'placeholder',
69                 null,
70                 InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
71                 $this->trans('commands.chain.options.placeholder')
72             );
73     }
74
75     /**
76      * {@inheritdoc}
77      */
78     protected function execute(InputInterface $input, OutputInterface $output)
79     {
80         $command = $this->getApplication()->find('chain');
81
82         $arguments = [
83             'command' => 'chain',
84             '--file'  => $this->file,
85         ];
86
87         if ($placeholder = $input->getOption('placeholder')) {
88             $arguments['--placeholder'] = $this->inlineValueAsArray($placeholder);
89         }
90
91         foreach ($input->getOptions() as $option => $value) {
92             if ($option != 'placeholder' && $value) {
93                 if (is_bool($value)) {
94                     $value = true;
95                 }
96                 $arguments['--'.$option] = $value;
97             }
98         }
99
100         $commandInput = new ArrayInput($arguments);
101         if (array_key_exists('--no-interaction', $arguments)) {
102             $commandInput->setInteractive(false);
103         }
104
105         return $command->run($commandInput, $output);
106     }
107 }