PluginProbe
Depicter — Popup & Slider Builder / 1.3.2
Depicter — Popup & Slider Builder v1.3.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Input / Input.php

Input.php in Depicter — Popup & Slider Builder 1.3.2, at vendor/symfony/console/Input/Input.php

202 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Console\Input;
13
14 use Symfony\Component\Console\Exception\InvalidArgumentException;
15 use Symfony\Component\Console\Exception\RuntimeException;
16
17 /**
18 * Input is the base class for all concrete Input classes.
19 *
20 * Three concrete classes are provided by default:
21 *
22 * * `ArgvInput`: The input comes from the CLI arguments (argv)
23 * * `StringInput`: The input is provided as a string
24 * * `ArrayInput`: The input is provided as an array
25 *
26 * @author Fabien Potencier <fabien@symfony.com>
27 */
28 abstract class Input implements InputInterface, StreamableInputInterface
29 {
30 protected $definition;
31 protected $stream;
32 protected $options = [];
33 protected $arguments = [];
34 protected $interactive = true;
35
36 public function __construct(InputDefinition $definition = null)
37 {
38 if (null === $definition) {
39 $this->definition = new InputDefinition();
40 } else {
41 $this->bind($definition);
42 $this->validate();
43 }
44 }
45
46 /**
47 * {@inheritdoc}
48 */
49 public function bind(InputDefinition $definition)
50 {
51 $this->arguments = [];
52 $this->options = [];
53 $this->definition = $definition;
54
55 $this->parse();
56 }
57
58 /**
59 * Processes command line arguments.
60 */
61 abstract protected function parse();
62
63 /**
64 * {@inheritdoc}
65 */
66 public function validate()
67 {
68 $definition = $this->definition;
69 $givenArguments = $this->arguments;
70
71 $missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) {
72 return !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired();
73 });
74
75 if (\count($missingArguments) > 0) {
76 throw new RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments)));
77 }
78 }
79
80 /**
81 * {@inheritdoc}
82 */
83 public function isInteractive()
84 {
85 return $this->interactive;
86 }
87
88 /**
89 * {@inheritdoc}
90 */
91 public function setInteractive(bool $interactive)
92 {
93 $this->interactive = $interactive;
94 }
95
96 /**
97 * {@inheritdoc}
98 */
99 public function getArguments()
100 {
101 return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
102 }
103
104 /**
105 * {@inheritdoc}
106 */
107 public function getArgument(string $name)
108 {
109 if (!$this->definition->hasArgument($name)) {
110 throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
111 }
112
113 return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault();
114 }
115
116 /**
117 * {@inheritdoc}
118 */
119 public function setArgument(string $name, $value)
120 {
121 if (!$this->definition->hasArgument($name)) {
122 throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
123 }
124
125 $this->arguments[$name] = $value;
126 }
127
128 /**
129 * {@inheritdoc}
130 */
131 public function hasArgument($name)
132 {
133 return $this->definition->hasArgument($name);
134 }
135
136 /**
137 * {@inheritdoc}
138 */
139 public function getOptions()
140 {
141 return array_merge($this->definition->getOptionDefaults(), $this->options);
142 }
143
144 /**
145 * {@inheritdoc}
146 */
147 public function getOption(string $name)
148 {
149 if (!$this->definition->hasOption($name)) {
150 throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
151 }
152
153 return \array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
154 }
155
156 /**
157 * {@inheritdoc}
158 */
159 public function setOption(string $name, $value)
160 {
161 if (!$this->definition->hasOption($name)) {
162 throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
163 }
164
165 $this->options[$name] = $value;
166 }
167
168 /**
169 * {@inheritdoc}
170 */
171 public function hasOption(string $name)
172 {
173 return $this->definition->hasOption($name);
174 }
175
176 /**
177 * Escapes a token through escapeshellarg if it contains unsafe chars.
178 *
179 * @return string
180 */
181 public function escapeToken(string $token)
182 {
183 return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
184 }
185
186 /**
187 * {@inheritdoc}
188 */
189 public function setStream($stream)
190 {
191 $this->stream = $stream;
192 }
193
194 /**
195 * {@inheritdoc}
196 */
197 public function getStream()
198 {
199 return $this->stream;
200 }
201 }
202