5 * Definition of Drush\Command\DrushInputAdapter.
8 namespace Drush\Command;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputDefinition;
14 * Adapter for Symfony Console InputInterface
16 * This class can serve as a stand-in wherever an InputInterface
17 * is needed. It calls through to ordinary Drush procedural functions.
18 * This object should not be used directly; it exists only in
19 * the Drush 8.x branch.
21 * We use this class rather than using an ArrayInput for two reasons:
22 * 1) We do not want to convert our options array back to '--option=value'
23 * or '--option value' just to have them re-parsed again.
24 * 2) We do not want Symfony to attempt to validate our options or arguments
27 class DrushInputAdapter implements InputInterface
31 protected $interactive;
33 public function __construct($arguments, $options, $command = false, $interactive = true)
35 $this->arguments = $arguments;
36 $this->options = $options;
38 // If a command name is provided as a parameter, then push
39 // it onto the front of the arguments list as a service
41 $this->arguments = array_merge(
42 [ 'command' => $command ],
46 // Is it interactive, or is it not interactive?
47 // Call drush_get_option() here if value not passed in?
48 $this->interactive = $interactive;
54 public function getFirstArgument()
56 return reset($this->arguments);
62 public function hasParameterOption($values, $onlyParams = false)
64 $values = (array) $values;
66 foreach ($values as $value) {
67 if (array_key_exists($value, $this->options)) {
78 public function getParameterOption($values, $default = false, $onlyParams = false)
80 $values = (array) $values;
82 foreach ($values as $value) {
83 if (array_key_exists($value, $this->options)) {
84 return $this->getOption($value);
94 public function bind(InputDefinition $definition)
96 // no-op: this class exists to avoid validation
102 public function validate()
104 // no-op: this class exists to avoid validation
110 public function getArguments()
112 return $this->arguments;
118 public function getArgument($name)
120 // TODO: better to throw if an argument that does not exist is requested?
121 return isset($this->arguments[$name]) ? $this->arguments[$name] : '';
127 public function setArgument($name, $value)
129 $this->arguments[$name] = $value;
135 public function hasArgument($name)
137 return isset($this->arguments[$name]);
143 public function getOptions()
145 return $this->options;
151 public function getOption($name)
153 return $this->options[$name];
159 public function setOption($name, $value)
161 $this->options[$name] = $value;
167 public function hasOption($name)
169 return isset($this->options[$name]);
175 public function isInteractive()
177 return $this->interactive;
183 public function setInteractive($interactive)
185 $this->interactive = $interactive;