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 {
30 protected $interactive;
32 public function __construct($arguments, $options, $command = false, $interactive = true)
34 $this->arguments = $arguments;
35 $this->options = $options;
37 // If a command name is provided as a parameter, then push
38 // it onto the front of the arguments list as a service
40 $this->arguments = array_merge(
41 [ 'command' => $command ],
45 // Is it interactive, or is it not interactive?
46 // Call drush_get_option() here if value not passed in?
47 $this->interactive = $interactive;
53 public function getFirstArgument()
55 return reset($arguments);
61 public function hasParameterOption($values)
63 $values = (array) $values;
65 foreach ($values as $value) {
66 if (array_key_exists($value, $this->options)) {
77 public function getParameterOption($values, $default = false)
79 $values = (array) $values;
81 foreach ($values as $value) {
82 if (array_key_exists($value, $this->options)) {
83 return $this->getOption($value);
93 public function bind(InputDefinition $definition)
95 // no-op: this class exists to avoid validation
101 public function validate()
103 // no-op: this class exists to avoid validation
109 public function getArguments()
111 return $this->arguments;
117 public function getArgument($name)
119 // TODO: better to throw if an argument that does not exist is requested?
120 return isset($this->arguments[$name]) ? $this->arguments[$name] : '';
126 public function setArgument($name, $value)
128 $this->arguments[$name] = $value;
134 public function hasArgument($name)
136 return isset($this->arguments[$name]);
142 public function getOptions()
144 return $this->options;
150 public function getOption($name)
152 return $this->options[$name];
158 public function setOption($name, $value)
160 $this->options[$name] = $value;
166 public function hasOption($name)
168 return isset($this->options[$name]);
174 public function isInteractive()
176 return $this->interactive;
182 public function setInteractive($interactive)
184 $this->interactive = $interactive;