9 namespace Drupal\Console\Core\Command\Chain;
11 use Drupal\Console\Core\Command\Command;
12 use Drupal\Console\Core\Utils\ChainDiscovery;
13 use Symfony\Component\Console\Input\InputInterface;
14 use Symfony\Component\Console\Input\InputOption;
15 use Symfony\Component\Console\Output\OutputInterface;
17 class BaseCommand extends Command
22 protected $chainDiscovery;
25 * BaseCommand constructor.
27 * @param ChainDiscovery $chainDiscovery
29 public function __construct(
30 ChainDiscovery $chainDiscovery
32 $this->chainDiscovery = $chainDiscovery;
33 parent::__construct();
34 $this->ignoreValidationErrors();
37 protected function initialize(
38 InputInterface $input,
39 OutputInterface $output
41 parent::initialize($input, $output);
44 foreach ($_SERVER['argv'] as $index => $element) {
49 if (substr($element, 0, 2) !== "--") {
53 $element = substr($element, 2);
54 $exploded = explode("=", $element);
57 $exploded = explode(" ", $element);
60 if (count($exploded)>1) {
61 $options[trim($exploded[0])] = trim($exploded[1]);
65 $file = $input->getOption('file');
66 $file = calculateRealPath($file);
67 $content = $this->chainDiscovery->getFileContents($file);
68 $variables = $this->chainDiscovery->extractInlinePlaceHolderNames($content);
70 foreach ($variables as $variable) {
71 if (!array_key_exists($variable, $options)) {
72 $options[$variable] = null;
76 foreach ($options as $optionName => $optionValue) {
77 if ($input->hasOption($optionName)) {
84 InputOption::VALUE_OPTIONAL,
91 protected function getFileOption()
93 $input = $this->getIo()->getInput();
94 $file = $input->getOption('file');
97 $files = array_keys($this->chainDiscovery->getFiles());
99 $file = $this->getIo()->choice(
100 $this->trans('commands.chain.questions.chain-file'),
105 $file = calculateRealPath($file);
106 $input->setOption('file', $file);
111 protected function getOptionsAsArray()
113 $input = $this->getIo()->getInput();
115 foreach ($input->getOptions() as $option => $value) {
116 $options[$option] = $value;