PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / console / Input / InputArgument.php
matomo / app / vendor / prefixed / symfony / console / Input Last commit date
ArgvInput.php 1 year ago ArrayInput.php 1 year ago Input.php 1 year ago InputArgument.php 2 years ago InputAwareInterface.php 2 years ago InputDefinition.php 1 year ago InputInterface.php 1 year ago InputOption.php 1 year ago StreamableInputInterface.php 2 years ago StringInput.php 2 years ago
InputArgument.php
116 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 Matomo\Dependencies\Symfony\Component\Console\Input;
12
13 use Matomo\Dependencies\Symfony\Component\Console\Exception\InvalidArgumentException;
14 use Matomo\Dependencies\Symfony\Component\Console\Exception\LogicException;
15 /**
16 * Represents a command line argument.
17 *
18 * @author Fabien Potencier <fabien@symfony.com>
19 */
20 class InputArgument
21 {
22 public const REQUIRED = 1;
23 public const OPTIONAL = 2;
24 public const IS_ARRAY = 4;
25 private $name;
26 private $mode;
27 private $default;
28 private $description;
29 /**
30 * @param string $name The argument name
31 * @param int|null $mode The argument mode: a bit mask of self::REQUIRED, self::OPTIONAL and self::IS_ARRAY
32 * @param string $description A description text
33 * @param string|bool|int|float|array|null $default The default value (for self::OPTIONAL mode only)
34 *
35 * @throws InvalidArgumentException When argument mode is not valid
36 */
37 public function __construct(string $name, ?int $mode = null, string $description = '', $default = null)
38 {
39 if (null === $mode) {
40 $mode = self::OPTIONAL;
41 } elseif ($mode > 7 || $mode < 1) {
42 throw new InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
43 }
44 $this->name = $name;
45 $this->mode = $mode;
46 $this->description = $description;
47 $this->setDefault($default);
48 }
49 /**
50 * Returns the argument name.
51 *
52 * @return string
53 */
54 public function getName()
55 {
56 return $this->name;
57 }
58 /**
59 * Returns true if the argument is required.
60 *
61 * @return bool true if parameter mode is self::REQUIRED, false otherwise
62 */
63 public function isRequired()
64 {
65 return self::REQUIRED === (self::REQUIRED & $this->mode);
66 }
67 /**
68 * Returns true if the argument can take multiple values.
69 *
70 * @return bool true if mode is self::IS_ARRAY, false otherwise
71 */
72 public function isArray()
73 {
74 return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
75 }
76 /**
77 * Sets the default value.
78 *
79 * @param string|bool|int|float|array|null $default
80 *
81 * @throws LogicException When incorrect default value is given
82 */
83 public function setDefault($default = null)
84 {
85 if ($this->isRequired() && null !== $default) {
86 throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
87 }
88 if ($this->isArray()) {
89 if (null === $default) {
90 $default = [];
91 } elseif (!\is_array($default)) {
92 throw new LogicException('A default value for an array argument must be an array.');
93 }
94 }
95 $this->default = $default;
96 }
97 /**
98 * Returns the default value.
99 *
100 * @return string|bool|int|float|array|null
101 */
102 public function getDefault()
103 {
104 return $this->default;
105 }
106 /**
107 * Returns the description text.
108 *
109 * @return string
110 */
111 public function getDescription()
112 {
113 return $this->description;
114 }
115 }
116