PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / symfony / console / Input / ArrayInput.php
independent-analytics / vendor / symfony / console / Input Last commit date
ArgvInput.php 2 years ago ArrayInput.php 2 years ago Input.php 2 years ago InputArgument.php 2 years ago InputAwareInterface.php 2 years ago InputDefinition.php 2 years ago InputInterface.php 2 years ago InputOption.php 2 years ago StreamableInputInterface.php 2 years ago StringInput.php 2 years ago
ArrayInput.php
182 lines
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 namespace IAWP_SCOPED\Symfony\Component\Console\Input;
12
13 use IAWP_SCOPED\Symfony\Component\Console\Exception\InvalidArgumentException;
14 use IAWP_SCOPED\Symfony\Component\Console\Exception\InvalidOptionException;
15 /**
16 * ArrayInput represents an input provided as an array.
17 *
18 * Usage:
19 *
20 * $input = new ArrayInput(['command' => 'foo:bar', 'foo' => 'bar', '--bar' => 'foobar']);
21 *
22 * @author Fabien Potencier <fabien@symfony.com>
23 * @internal
24 */
25 class ArrayInput extends Input
26 {
27 private $parameters;
28 public function __construct(array $parameters, InputDefinition $definition = null)
29 {
30 $this->parameters = $parameters;
31 parent::__construct($definition);
32 }
33 /**
34 * {@inheritdoc}
35 */
36 public function getFirstArgument()
37 {
38 foreach ($this->parameters as $param => $value) {
39 if ($param && \is_string($param) && '-' === $param[0]) {
40 continue;
41 }
42 return $value;
43 }
44 return null;
45 }
46 /**
47 * {@inheritdoc}
48 */
49 public function hasParameterOption($values, bool $onlyParams = \false)
50 {
51 $values = (array) $values;
52 foreach ($this->parameters as $k => $v) {
53 if (!\is_int($k)) {
54 $v = $k;
55 }
56 if ($onlyParams && '--' === $v) {
57 return \false;
58 }
59 if (\in_array($v, $values)) {
60 return \true;
61 }
62 }
63 return \false;
64 }
65 /**
66 * {@inheritdoc}
67 */
68 public function getParameterOption($values, $default = \false, bool $onlyParams = \false)
69 {
70 $values = (array) $values;
71 foreach ($this->parameters as $k => $v) {
72 if ($onlyParams && ('--' === $k || \is_int($k) && '--' === $v)) {
73 return $default;
74 }
75 if (\is_int($k)) {
76 if (\in_array($v, $values)) {
77 return \true;
78 }
79 } elseif (\in_array($k, $values)) {
80 return $v;
81 }
82 }
83 return $default;
84 }
85 /**
86 * Returns a stringified representation of the args passed to the command.
87 *
88 * @return string
89 */
90 public function __toString()
91 {
92 $params = [];
93 foreach ($this->parameters as $param => $val) {
94 if ($param && \is_string($param) && '-' === $param[0]) {
95 $glue = '-' === $param[1] ? '=' : ' ';
96 if (\is_array($val)) {
97 foreach ($val as $v) {
98 $params[] = $param . ('' != $v ? $glue . $this->escapeToken($v) : '');
99 }
100 } else {
101 $params[] = $param . ('' != $val ? $glue . $this->escapeToken($val) : '');
102 }
103 } else {
104 $params[] = \is_array($val) ? \implode(' ', \array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);
105 }
106 }
107 return \implode(' ', $params);
108 }
109 /**
110 * {@inheritdoc}
111 */
112 protected function parse()
113 {
114 foreach ($this->parameters as $key => $value) {
115 if ('--' === $key) {
116 return;
117 }
118 if (\str_starts_with($key, '--')) {
119 $this->addLongOption(\substr($key, 2), $value);
120 } elseif (\str_starts_with($key, '-')) {
121 $this->addShortOption(\substr($key, 1), $value);
122 } else {
123 $this->addArgument($key, $value);
124 }
125 }
126 }
127 /**
128 * Adds a short option value.
129 *
130 * @throws InvalidOptionException When option given doesn't exist
131 */
132 private function addShortOption(string $shortcut, $value)
133 {
134 if (!$this->definition->hasShortcut($shortcut)) {
135 throw new InvalidOptionException(\sprintf('The "-%s" option does not exist.', $shortcut));
136 }
137 $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
138 }
139 /**
140 * Adds a long option value.
141 *
142 * @throws InvalidOptionException When option given doesn't exist
143 * @throws InvalidOptionException When a required value is missing
144 */
145 private function addLongOption(string $name, $value)
146 {
147 if (!$this->definition->hasOption($name)) {
148 if (!$this->definition->hasNegation($name)) {
149 throw new InvalidOptionException(\sprintf('The "--%s" option does not exist.', $name));
150 }
151 $optionName = $this->definition->negationToName($name);
152 $this->options[$optionName] = \false;
153 return;
154 }
155 $option = $this->definition->getOption($name);
156 if (null === $value) {
157 if ($option->isValueRequired()) {
158 throw new InvalidOptionException(\sprintf('The "--%s" option requires a value.', $name));
159 }
160 if (!$option->isValueOptional()) {
161 $value = \true;
162 }
163 }
164 $this->options[$name] = $value;
165 }
166 /**
167 * Adds an argument value.
168 *
169 * @param string|int $name The argument name
170 * @param mixed $value The value for the argument
171 *
172 * @throws InvalidArgumentException When argument given doesn't exist
173 */
174 private function addArgument($name, $value)
175 {
176 if (!$this->definition->hasArgument($name)) {
177 throw new InvalidArgumentException(\sprintf('The "%s" argument does not exist.', $name));
178 }
179 $this->arguments[$name] = $value;
180 }
181 }
182