29126f19a071be08130c643495d1736ff1bb6916
[yaffs-website] / vendor / drush / drush / lib / Drush / Command / DrushInputAdapter.php
1 <?php
2
3 /**
4  * @file
5  * Definition of Drush\Command\DrushInputAdapter.
6  */
7
8 namespace Drush\Command;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputDefinition;
12
13 /**
14  * Adapter for Symfony Console InputInterface
15  *
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.
20  *
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
25  *    for us.
26  */
27 class DrushInputAdapter implements InputInterface {
28     protected $arguments;
29     protected $options;
30     protected $interactive;
31
32     public function __construct($arguments, $options, $command = false, $interactive = true)
33     {
34         $this->arguments = $arguments;
35         $this->options = $options;
36
37         // If a command name is provided as a parameter, then push
38         // it onto the front of the arguments list as a service
39         if ($command) {
40             $this->arguments = array_merge(
41                 [ 'command' => $command ],
42                 $this->arguments
43             );
44         }
45         // Is it interactive, or is it not interactive?
46         // Call drush_get_option() here if value not passed in?
47         $this->interactive = $interactive;
48     }
49
50     /**
51      *  {@inheritdoc}
52      */
53     public function getFirstArgument()
54     {
55         return reset($arguments);
56     }
57
58     /**
59      * {@inheritdoc}
60      */
61     public function hasParameterOption($values)
62     {
63         $values = (array) $values;
64
65         foreach ($values as $value) {
66             if (array_key_exists($value, $this->options)) {
67                 return true;
68             }
69         }
70
71         return false;
72     }
73
74     /**
75      *  {@inheritdoc}
76      */
77     public function getParameterOption($values, $default = false)
78     {
79         $values = (array) $values;
80
81         foreach ($values as $value) {
82             if (array_key_exists($value, $this->options)) {
83                 return $this->getOption($value);
84             }
85         }
86
87         return $default;
88     }
89
90     /**
91      *  {@inheritdoc}
92      */
93     public function bind(InputDefinition $definition)
94     {
95         // no-op: this class exists to avoid validation
96     }
97
98     /**
99      *  {@inheritdoc}
100      */
101     public function validate()
102     {
103         // no-op: this class exists to avoid validation
104     }
105
106     /**
107      *  {@inheritdoc}
108      */
109     public function getArguments()
110     {
111         return $this->arguments;
112     }
113
114     /**
115      *  {@inheritdoc}
116      */
117     public function getArgument($name)
118     {
119         // TODO: better to throw if an argument that does not exist is requested?
120         return isset($this->arguments[$name]) ? $this->arguments[$name] : '';
121     }
122
123     /**
124      *  {@inheritdoc}
125      */
126     public function setArgument($name, $value)
127     {
128         $this->arguments[$name] = $value;
129     }
130
131     /**
132      *  {@inheritdoc}
133      */
134     public function hasArgument($name)
135     {
136         return isset($this->arguments[$name]);
137     }
138
139     /**
140      *  {@inheritdoc}
141      */
142     public function getOptions()
143     {
144         return $this->options;
145     }
146
147     /**
148      *  {@inheritdoc}
149      */
150     public function getOption($name)
151     {
152         return $this->options[$name];
153     }
154
155     /**
156      *  {@inheritdoc}
157      */
158     public function setOption($name, $value)
159     {
160         $this->options[$name] = $value;
161     }
162
163     /**
164      *  {@inheritdoc}
165      */
166     public function hasOption($name)
167     {
168         return isset($this->options[$name]);
169     }
170
171     /**
172      *  {@inheritdoc}
173      */
174     public function isInteractive()
175     {
176         return $this->interactive;
177     }
178
179     /**
180      *  {@inheritdoc}
181      */
182     public function setInteractive($interactive)
183     {
184         $this->interactive = $interactive;
185     }
186 }