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 / InputOption.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
InputOption.php
197 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\LogicException;
15 /**
16 * Represents a command line option.
17 *
18 * @author Fabien Potencier <fabien@symfony.com>
19 * @internal
20 */
21 class InputOption
22 {
23 /**
24 * Do not accept input for the option (e.g. --yell). This is the default behavior of options.
25 */
26 public const VALUE_NONE = 1;
27 /**
28 * A value must be passed when the option is used (e.g. --iterations=5 or -i5).
29 */
30 public const VALUE_REQUIRED = 2;
31 /**
32 * The option may or may not have a value (e.g. --yell or --yell=loud).
33 */
34 public const VALUE_OPTIONAL = 4;
35 /**
36 * The option accepts multiple values (e.g. --dir=/foo --dir=/bar).
37 */
38 public const VALUE_IS_ARRAY = 8;
39 /**
40 * The option may have either positive or negative value (e.g. --ansi or --no-ansi).
41 */
42 public const VALUE_NEGATABLE = 16;
43 private $name;
44 private $shortcut;
45 private $mode;
46 private $default;
47 private $description;
48 /**
49 * @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
50 * @param int|null $mode The option mode: One of the VALUE_* constants
51 * @param string|bool|int|float|array|null $default The default value (must be null for self::VALUE_NONE)
52 *
53 * @throws InvalidArgumentException If option mode is invalid or incompatible
54 */
55 public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
56 {
57 if (\str_starts_with($name, '--')) {
58 $name = \substr($name, 2);
59 }
60 if (empty($name)) {
61 throw new InvalidArgumentException('An option name cannot be empty.');
62 }
63 if (empty($shortcut)) {
64 $shortcut = null;
65 }
66 if (null !== $shortcut) {
67 if (\is_array($shortcut)) {
68 $shortcut = \implode('|', $shortcut);
69 }
70 $shortcuts = \preg_split('{(\\|)-?}', \ltrim($shortcut, '-'));
71 $shortcuts = \array_filter($shortcuts);
72 $shortcut = \implode('|', $shortcuts);
73 if (empty($shortcut)) {
74 throw new InvalidArgumentException('An option shortcut cannot be empty.');
75 }
76 }
77 if (null === $mode) {
78 $mode = self::VALUE_NONE;
79 } elseif ($mode >= self::VALUE_NEGATABLE << 1 || $mode < 1) {
80 throw new InvalidArgumentException(\sprintf('Option mode "%s" is not valid.', $mode));
81 }
82 $this->name = $name;
83 $this->shortcut = $shortcut;
84 $this->mode = $mode;
85 $this->description = $description;
86 if ($this->isArray() && !$this->acceptValue()) {
87 throw new InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
88 }
89 if ($this->isNegatable() && $this->acceptValue()) {
90 throw new InvalidArgumentException('Impossible to have an option mode VALUE_NEGATABLE if the option also accepts a value.');
91 }
92 $this->setDefault($default);
93 }
94 /**
95 * Returns the option shortcut.
96 *
97 * @return string|null
98 */
99 public function getShortcut()
100 {
101 return $this->shortcut;
102 }
103 /**
104 * Returns the option name.
105 *
106 * @return string
107 */
108 public function getName()
109 {
110 return $this->name;
111 }
112 /**
113 * Returns true if the option accepts a value.
114 *
115 * @return bool true if value mode is not self::VALUE_NONE, false otherwise
116 */
117 public function acceptValue()
118 {
119 return $this->isValueRequired() || $this->isValueOptional();
120 }
121 /**
122 * Returns true if the option requires a value.
123 *
124 * @return bool true if value mode is self::VALUE_REQUIRED, false otherwise
125 */
126 public function isValueRequired()
127 {
128 return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
129 }
130 /**
131 * Returns true if the option takes an optional value.
132 *
133 * @return bool true if value mode is self::VALUE_OPTIONAL, false otherwise
134 */
135 public function isValueOptional()
136 {
137 return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
138 }
139 /**
140 * Returns true if the option can take multiple values.
141 *
142 * @return bool true if mode is self::VALUE_IS_ARRAY, false otherwise
143 */
144 public function isArray()
145 {
146 return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
147 }
148 public function isNegatable() : bool
149 {
150 return self::VALUE_NEGATABLE === (self::VALUE_NEGATABLE & $this->mode);
151 }
152 /**
153 * @param string|bool|int|float|array|null $default
154 */
155 public function setDefault($default = null)
156 {
157 if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
158 throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
159 }
160 if ($this->isArray()) {
161 if (null === $default) {
162 $default = [];
163 } elseif (!\is_array($default)) {
164 throw new LogicException('A default value for an array option must be an array.');
165 }
166 }
167 $this->default = $this->acceptValue() || $this->isNegatable() ? $default : \false;
168 }
169 /**
170 * Returns the default value.
171 *
172 * @return string|bool|int|float|array|null
173 */
174 public function getDefault()
175 {
176 return $this->default;
177 }
178 /**
179 * Returns the description text.
180 *
181 * @return string
182 */
183 public function getDescription()
184 {
185 return $this->description;
186 }
187 /**
188 * Checks whether the given option equals this one.
189 *
190 * @return bool
191 */
192 public function equals(self $option)
193 {
194 return $option->getName() === $this->getName() && $option->getShortcut() === $this->getShortcut() && $option->getDefault() === $this->getDefault() && $option->isNegatable() === $this->isNegatable() && $option->isArray() === $this->isArray() && $option->isValueRequired() === $this->isValueRequired() && $option->isValueOptional() === $this->isValueOptional();
195 }
196 }
197