comparison vendor/symfony/console/Input/InputOption.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
31 private $mode; 31 private $mode;
32 private $default; 32 private $default;
33 private $description; 33 private $description;
34 34
35 /** 35 /**
36 * @param string $name The option name 36 * @param string $name The option name
37 * @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts 37 * @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
38 * @param int $mode The option mode: One of the VALUE_* constants 38 * @param int|null $mode The option mode: One of the VALUE_* constants
39 * @param string $description A description text 39 * @param string $description A description text
40 * @param mixed $default The default value (must be null for self::VALUE_NONE) 40 * @param string|string[]|int|bool|null $default The default value (must be null for self::VALUE_NONE)
41 * 41 *
42 * @throws InvalidArgumentException If option mode is invalid or incompatible 42 * @throws InvalidArgumentException If option mode is invalid or incompatible
43 */ 43 */
44 public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null) 44 public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null)
45 { 45 {
54 if (empty($shortcut)) { 54 if (empty($shortcut)) {
55 $shortcut = null; 55 $shortcut = null;
56 } 56 }
57 57
58 if (null !== $shortcut) { 58 if (null !== $shortcut) {
59 if (is_array($shortcut)) { 59 if (\is_array($shortcut)) {
60 $shortcut = implode('|', $shortcut); 60 $shortcut = implode('|', $shortcut);
61 } 61 }
62 $shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-')); 62 $shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
63 $shortcuts = array_filter($shortcuts); 63 $shortcuts = array_filter($shortcuts);
64 $shortcut = implode('|', $shortcuts); 64 $shortcut = implode('|', $shortcuts);
68 } 68 }
69 } 69 }
70 70
71 if (null === $mode) { 71 if (null === $mode) {
72 $mode = self::VALUE_NONE; 72 $mode = self::VALUE_NONE;
73 } elseif (!is_int($mode) || $mode > 15 || $mode < 1) { 73 } elseif (!\is_int($mode) || $mode > 15 || $mode < 1) {
74 throw new InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode)); 74 throw new InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
75 } 75 }
76 76
77 $this->name = $name; 77 $this->name = $name;
78 $this->shortcut = $shortcut; 78 $this->shortcut = $shortcut;
87 } 87 }
88 88
89 /** 89 /**
90 * Returns the option shortcut. 90 * Returns the option shortcut.
91 * 91 *
92 * @return string The shortcut 92 * @return string|null The shortcut
93 */ 93 */
94 public function getShortcut() 94 public function getShortcut()
95 { 95 {
96 return $this->shortcut; 96 return $this->shortcut;
97 } 97 }
147 } 147 }
148 148
149 /** 149 /**
150 * Sets the default value. 150 * Sets the default value.
151 * 151 *
152 * @param mixed $default The default value 152 * @param string|string[]|int|bool|null $default The default value
153 * 153 *
154 * @throws LogicException When incorrect default value is given 154 * @throws LogicException When incorrect default value is given
155 */ 155 */
156 public function setDefault($default = null) 156 public function setDefault($default = null)
157 { 157 {
159 throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.'); 159 throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
160 } 160 }
161 161
162 if ($this->isArray()) { 162 if ($this->isArray()) {
163 if (null === $default) { 163 if (null === $default) {
164 $default = array(); 164 $default = [];
165 } elseif (!is_array($default)) { 165 } elseif (!\is_array($default)) {
166 throw new LogicException('A default value for an array option must be an array.'); 166 throw new LogicException('A default value for an array option must be an array.');
167 } 167 }
168 } 168 }
169 169
170 $this->default = $this->acceptValue() ? $default : false; 170 $this->default = $this->acceptValue() ? $default : false;
171 } 171 }
172 172
173 /** 173 /**
174 * Returns the default value. 174 * Returns the default value.
175 * 175 *
176 * @return mixed The default value 176 * @return string|string[]|int|bool|null The default value
177 */ 177 */
178 public function getDefault() 178 public function getDefault()
179 { 179 {
180 return $this->default; 180 return $this->default;
181 } 181 }