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