@@ -20,164 +20,164 @@ |
||
20 | 20 | */ |
21 | 21 | class ChoiceQuestion extends Question |
22 | 22 | { |
23 | - private $choices; |
|
24 | - private $multiselect = false; |
|
25 | - private $prompt = ' > '; |
|
26 | - private $errorMessage = 'Value "%s" is invalid'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param string $question The question to ask to the user |
|
30 | - * @param array $choices The list of available choices |
|
31 | - * @param mixed $default The default answer to return |
|
32 | - */ |
|
33 | - public function __construct(string $question, array $choices, $default = null) |
|
34 | - { |
|
35 | - if (!$choices) { |
|
36 | - throw new \LogicException('Choice question must have at least 1 choice available.'); |
|
37 | - } |
|
38 | - |
|
39 | - parent::__construct($question, $default); |
|
40 | - |
|
41 | - $this->choices = $choices; |
|
42 | - $this->setValidator($this->getDefaultValidator()); |
|
43 | - $this->setAutocompleterValues($choices); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Returns available choices. |
|
48 | - * |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - public function getChoices() |
|
52 | - { |
|
53 | - return $this->choices; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Sets multiselect option. |
|
58 | - * |
|
59 | - * When multiselect is set to true, multiple choices can be answered. |
|
60 | - * |
|
61 | - * @return $this |
|
62 | - */ |
|
63 | - public function setMultiselect(bool $multiselect) |
|
64 | - { |
|
65 | - $this->multiselect = $multiselect; |
|
66 | - $this->setValidator($this->getDefaultValidator()); |
|
67 | - |
|
68 | - return $this; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns whether the choices are multiselect. |
|
73 | - * |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public function isMultiselect() |
|
77 | - { |
|
78 | - return $this->multiselect; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Gets the prompt for choices. |
|
83 | - * |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function getPrompt() |
|
87 | - { |
|
88 | - return $this->prompt; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Sets the prompt for choices. |
|
93 | - * |
|
94 | - * @return $this |
|
95 | - */ |
|
96 | - public function setPrompt(string $prompt) |
|
97 | - { |
|
98 | - $this->prompt = $prompt; |
|
99 | - |
|
100 | - return $this; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Sets the error message for invalid values. |
|
105 | - * |
|
106 | - * The error message has a string placeholder (%s) for the invalid value. |
|
107 | - * |
|
108 | - * @return $this |
|
109 | - */ |
|
110 | - public function setErrorMessage(string $errorMessage) |
|
111 | - { |
|
112 | - $this->errorMessage = $errorMessage; |
|
113 | - $this->setValidator($this->getDefaultValidator()); |
|
114 | - |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - private function getDefaultValidator(): callable |
|
119 | - { |
|
120 | - $choices = $this->choices; |
|
121 | - $errorMessage = $this->errorMessage; |
|
122 | - $multiselect = $this->multiselect; |
|
123 | - $isAssoc = $this->isAssoc($choices); |
|
124 | - |
|
125 | - return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) { |
|
126 | - if ($multiselect) { |
|
127 | - // Check for a separated comma values |
|
128 | - if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) { |
|
129 | - throw new InvalidArgumentException(sprintf($errorMessage, $selected)); |
|
130 | - } |
|
131 | - |
|
132 | - $selectedChoices = explode(',', $selected); |
|
133 | - } else { |
|
134 | - $selectedChoices = [$selected]; |
|
135 | - } |
|
136 | - |
|
137 | - if ($this->isTrimmable()) { |
|
138 | - foreach ($selectedChoices as $k => $v) { |
|
139 | - $selectedChoices[$k] = trim($v); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - $multiselectChoices = []; |
|
144 | - foreach ($selectedChoices as $value) { |
|
145 | - $results = []; |
|
146 | - foreach ($choices as $key => $choice) { |
|
147 | - if ($choice === $value) { |
|
148 | - $results[] = $key; |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - if (\count($results) > 1) { |
|
153 | - throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of "%s".', implode('" or "', $results))); |
|
154 | - } |
|
155 | - |
|
156 | - $result = array_search($value, $choices); |
|
157 | - |
|
158 | - if (!$isAssoc) { |
|
159 | - if (false !== $result) { |
|
160 | - $result = $choices[$result]; |
|
161 | - } elseif (isset($choices[$value])) { |
|
162 | - $result = $choices[$value]; |
|
163 | - } |
|
164 | - } elseif (false === $result && isset($choices[$value])) { |
|
165 | - $result = $value; |
|
166 | - } |
|
167 | - |
|
168 | - if (false === $result) { |
|
169 | - throw new InvalidArgumentException(sprintf($errorMessage, $value)); |
|
170 | - } |
|
171 | - |
|
172 | - // For associative choices, consistently return the key as string: |
|
173 | - $multiselectChoices[] = $isAssoc ? (string) $result : $result; |
|
174 | - } |
|
175 | - |
|
176 | - if ($multiselect) { |
|
177 | - return $multiselectChoices; |
|
178 | - } |
|
179 | - |
|
180 | - return current($multiselectChoices); |
|
181 | - }; |
|
182 | - } |
|
23 | + private $choices; |
|
24 | + private $multiselect = false; |
|
25 | + private $prompt = ' > '; |
|
26 | + private $errorMessage = 'Value "%s" is invalid'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param string $question The question to ask to the user |
|
30 | + * @param array $choices The list of available choices |
|
31 | + * @param mixed $default The default answer to return |
|
32 | + */ |
|
33 | + public function __construct(string $question, array $choices, $default = null) |
|
34 | + { |
|
35 | + if (!$choices) { |
|
36 | + throw new \LogicException('Choice question must have at least 1 choice available.'); |
|
37 | + } |
|
38 | + |
|
39 | + parent::__construct($question, $default); |
|
40 | + |
|
41 | + $this->choices = $choices; |
|
42 | + $this->setValidator($this->getDefaultValidator()); |
|
43 | + $this->setAutocompleterValues($choices); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Returns available choices. |
|
48 | + * |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + public function getChoices() |
|
52 | + { |
|
53 | + return $this->choices; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Sets multiselect option. |
|
58 | + * |
|
59 | + * When multiselect is set to true, multiple choices can be answered. |
|
60 | + * |
|
61 | + * @return $this |
|
62 | + */ |
|
63 | + public function setMultiselect(bool $multiselect) |
|
64 | + { |
|
65 | + $this->multiselect = $multiselect; |
|
66 | + $this->setValidator($this->getDefaultValidator()); |
|
67 | + |
|
68 | + return $this; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns whether the choices are multiselect. |
|
73 | + * |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public function isMultiselect() |
|
77 | + { |
|
78 | + return $this->multiselect; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Gets the prompt for choices. |
|
83 | + * |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function getPrompt() |
|
87 | + { |
|
88 | + return $this->prompt; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Sets the prompt for choices. |
|
93 | + * |
|
94 | + * @return $this |
|
95 | + */ |
|
96 | + public function setPrompt(string $prompt) |
|
97 | + { |
|
98 | + $this->prompt = $prompt; |
|
99 | + |
|
100 | + return $this; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Sets the error message for invalid values. |
|
105 | + * |
|
106 | + * The error message has a string placeholder (%s) for the invalid value. |
|
107 | + * |
|
108 | + * @return $this |
|
109 | + */ |
|
110 | + public function setErrorMessage(string $errorMessage) |
|
111 | + { |
|
112 | + $this->errorMessage = $errorMessage; |
|
113 | + $this->setValidator($this->getDefaultValidator()); |
|
114 | + |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + private function getDefaultValidator(): callable |
|
119 | + { |
|
120 | + $choices = $this->choices; |
|
121 | + $errorMessage = $this->errorMessage; |
|
122 | + $multiselect = $this->multiselect; |
|
123 | + $isAssoc = $this->isAssoc($choices); |
|
124 | + |
|
125 | + return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) { |
|
126 | + if ($multiselect) { |
|
127 | + // Check for a separated comma values |
|
128 | + if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) { |
|
129 | + throw new InvalidArgumentException(sprintf($errorMessage, $selected)); |
|
130 | + } |
|
131 | + |
|
132 | + $selectedChoices = explode(',', $selected); |
|
133 | + } else { |
|
134 | + $selectedChoices = [$selected]; |
|
135 | + } |
|
136 | + |
|
137 | + if ($this->isTrimmable()) { |
|
138 | + foreach ($selectedChoices as $k => $v) { |
|
139 | + $selectedChoices[$k] = trim($v); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + $multiselectChoices = []; |
|
144 | + foreach ($selectedChoices as $value) { |
|
145 | + $results = []; |
|
146 | + foreach ($choices as $key => $choice) { |
|
147 | + if ($choice === $value) { |
|
148 | + $results[] = $key; |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + if (\count($results) > 1) { |
|
153 | + throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of "%s".', implode('" or "', $results))); |
|
154 | + } |
|
155 | + |
|
156 | + $result = array_search($value, $choices); |
|
157 | + |
|
158 | + if (!$isAssoc) { |
|
159 | + if (false !== $result) { |
|
160 | + $result = $choices[$result]; |
|
161 | + } elseif (isset($choices[$value])) { |
|
162 | + $result = $choices[$value]; |
|
163 | + } |
|
164 | + } elseif (false === $result && isset($choices[$value])) { |
|
165 | + $result = $value; |
|
166 | + } |
|
167 | + |
|
168 | + if (false === $result) { |
|
169 | + throw new InvalidArgumentException(sprintf($errorMessage, $value)); |
|
170 | + } |
|
171 | + |
|
172 | + // For associative choices, consistently return the key as string: |
|
173 | + $multiselectChoices[] = $isAssoc ? (string) $result : $result; |
|
174 | + } |
|
175 | + |
|
176 | + if ($multiselect) { |
|
177 | + return $multiselectChoices; |
|
178 | + } |
|
179 | + |
|
180 | + return current($multiselectChoices); |
|
181 | + }; |
|
182 | + } |
|
183 | 183 | } |
@@ -21,282 +21,282 @@ |
||
21 | 21 | */ |
22 | 22 | class Question |
23 | 23 | { |
24 | - private $question; |
|
25 | - private $attempts; |
|
26 | - private $hidden = false; |
|
27 | - private $hiddenFallback = true; |
|
28 | - private $autocompleterCallback; |
|
29 | - private $validator; |
|
30 | - private $default; |
|
31 | - private $normalizer; |
|
32 | - private $trimmable = true; |
|
33 | - private $multiline = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param string $question The question to ask to the user |
|
37 | - * @param string|bool|int|float|null $default The default answer to return if the user enters nothing |
|
38 | - */ |
|
39 | - public function __construct(string $question, $default = null) |
|
40 | - { |
|
41 | - $this->question = $question; |
|
42 | - $this->default = $default; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Returns the question. |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getQuestion() |
|
51 | - { |
|
52 | - return $this->question; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Returns the default answer. |
|
57 | - * |
|
58 | - * @return string|bool|int|float|null |
|
59 | - */ |
|
60 | - public function getDefault() |
|
61 | - { |
|
62 | - return $this->default; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Returns whether the user response accepts newline characters. |
|
67 | - */ |
|
68 | - public function isMultiline(): bool |
|
69 | - { |
|
70 | - return $this->multiline; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Sets whether the user response should accept newline characters. |
|
75 | - * |
|
76 | - * @return $this |
|
77 | - */ |
|
78 | - public function setMultiline(bool $multiline): self |
|
79 | - { |
|
80 | - $this->multiline = $multiline; |
|
81 | - |
|
82 | - return $this; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Returns whether the user response must be hidden. |
|
87 | - * |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public function isHidden() |
|
91 | - { |
|
92 | - return $this->hidden; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Sets whether the user response must be hidden or not. |
|
97 | - * |
|
98 | - * @return $this |
|
99 | - * |
|
100 | - * @throws LogicException In case the autocompleter is also used |
|
101 | - */ |
|
102 | - public function setHidden(bool $hidden) |
|
103 | - { |
|
104 | - if ($this->autocompleterCallback) { |
|
105 | - throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
106 | - } |
|
107 | - |
|
108 | - $this->hidden = (bool) $hidden; |
|
109 | - |
|
110 | - return $this; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * In case the response can not be hidden, whether to fallback on non-hidden question or not. |
|
115 | - * |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - public function isHiddenFallback() |
|
119 | - { |
|
120 | - return $this->hiddenFallback; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Sets whether to fallback on non-hidden question if the response can not be hidden. |
|
125 | - * |
|
126 | - * @return $this |
|
127 | - */ |
|
128 | - public function setHiddenFallback(bool $fallback) |
|
129 | - { |
|
130 | - $this->hiddenFallback = (bool) $fallback; |
|
131 | - |
|
132 | - return $this; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Gets values for the autocompleter. |
|
137 | - * |
|
138 | - * @return iterable|null |
|
139 | - */ |
|
140 | - public function getAutocompleterValues() |
|
141 | - { |
|
142 | - $callback = $this->getAutocompleterCallback(); |
|
143 | - |
|
144 | - return $callback ? $callback('') : null; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Sets values for the autocompleter. |
|
149 | - * |
|
150 | - * @return $this |
|
151 | - * |
|
152 | - * @throws LogicException |
|
153 | - */ |
|
154 | - public function setAutocompleterValues(?iterable $values) |
|
155 | - { |
|
156 | - if (\is_array($values)) { |
|
157 | - $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); |
|
158 | - |
|
159 | - $callback = static function () use ($values) { |
|
160 | - return $values; |
|
161 | - }; |
|
162 | - } elseif ($values instanceof \Traversable) { |
|
163 | - $valueCache = null; |
|
164 | - $callback = static function () use ($values, &$valueCache) { |
|
165 | - return $valueCache ?? $valueCache = iterator_to_array($values, false); |
|
166 | - }; |
|
167 | - } else { |
|
168 | - $callback = null; |
|
169 | - } |
|
170 | - |
|
171 | - return $this->setAutocompleterCallback($callback); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Gets the callback function used for the autocompleter. |
|
176 | - */ |
|
177 | - public function getAutocompleterCallback(): ?callable |
|
178 | - { |
|
179 | - return $this->autocompleterCallback; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Sets the callback function used for the autocompleter. |
|
184 | - * |
|
185 | - * The callback is passed the user input as argument and should return an iterable of corresponding suggestions. |
|
186 | - * |
|
187 | - * @return $this |
|
188 | - */ |
|
189 | - public function setAutocompleterCallback(callable $callback = null): self |
|
190 | - { |
|
191 | - if ($this->hidden && null !== $callback) { |
|
192 | - throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
193 | - } |
|
194 | - |
|
195 | - $this->autocompleterCallback = $callback; |
|
196 | - |
|
197 | - return $this; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Sets a validator for the question. |
|
202 | - * |
|
203 | - * @return $this |
|
204 | - */ |
|
205 | - public function setValidator(callable $validator = null) |
|
206 | - { |
|
207 | - $this->validator = $validator; |
|
208 | - |
|
209 | - return $this; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Gets the validator for the question. |
|
214 | - * |
|
215 | - * @return callable|null |
|
216 | - */ |
|
217 | - public function getValidator() |
|
218 | - { |
|
219 | - return $this->validator; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Sets the maximum number of attempts. |
|
224 | - * |
|
225 | - * Null means an unlimited number of attempts. |
|
226 | - * |
|
227 | - * @return $this |
|
228 | - * |
|
229 | - * @throws InvalidArgumentException in case the number of attempts is invalid |
|
230 | - */ |
|
231 | - public function setMaxAttempts(?int $attempts) |
|
232 | - { |
|
233 | - if (null !== $attempts) { |
|
234 | - $attempts = (int) $attempts; |
|
235 | - if ($attempts < 1) { |
|
236 | - throw new InvalidArgumentException('Maximum number of attempts must be a positive value.'); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - $this->attempts = $attempts; |
|
241 | - |
|
242 | - return $this; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Gets the maximum number of attempts. |
|
247 | - * |
|
248 | - * Null means an unlimited number of attempts. |
|
249 | - * |
|
250 | - * @return int|null |
|
251 | - */ |
|
252 | - public function getMaxAttempts() |
|
253 | - { |
|
254 | - return $this->attempts; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Sets a normalizer for the response. |
|
259 | - * |
|
260 | - * The normalizer can be a callable (a string), a closure or a class implementing __invoke. |
|
261 | - * |
|
262 | - * @return $this |
|
263 | - */ |
|
264 | - public function setNormalizer(callable $normalizer) |
|
265 | - { |
|
266 | - $this->normalizer = $normalizer; |
|
267 | - |
|
268 | - return $this; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Gets the normalizer for the response. |
|
273 | - * |
|
274 | - * The normalizer can ba a callable (a string), a closure or a class implementing __invoke. |
|
275 | - * |
|
276 | - * @return callable|null |
|
277 | - */ |
|
278 | - public function getNormalizer() |
|
279 | - { |
|
280 | - return $this->normalizer; |
|
281 | - } |
|
282 | - |
|
283 | - protected function isAssoc(array $array) |
|
284 | - { |
|
285 | - return (bool) \count(array_filter(array_keys($array), 'is_string')); |
|
286 | - } |
|
287 | - |
|
288 | - public function isTrimmable(): bool |
|
289 | - { |
|
290 | - return $this->trimmable; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @return $this |
|
295 | - */ |
|
296 | - public function setTrimmable(bool $trimmable): self |
|
297 | - { |
|
298 | - $this->trimmable = $trimmable; |
|
299 | - |
|
300 | - return $this; |
|
301 | - } |
|
24 | + private $question; |
|
25 | + private $attempts; |
|
26 | + private $hidden = false; |
|
27 | + private $hiddenFallback = true; |
|
28 | + private $autocompleterCallback; |
|
29 | + private $validator; |
|
30 | + private $default; |
|
31 | + private $normalizer; |
|
32 | + private $trimmable = true; |
|
33 | + private $multiline = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param string $question The question to ask to the user |
|
37 | + * @param string|bool|int|float|null $default The default answer to return if the user enters nothing |
|
38 | + */ |
|
39 | + public function __construct(string $question, $default = null) |
|
40 | + { |
|
41 | + $this->question = $question; |
|
42 | + $this->default = $default; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Returns the question. |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getQuestion() |
|
51 | + { |
|
52 | + return $this->question; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Returns the default answer. |
|
57 | + * |
|
58 | + * @return string|bool|int|float|null |
|
59 | + */ |
|
60 | + public function getDefault() |
|
61 | + { |
|
62 | + return $this->default; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Returns whether the user response accepts newline characters. |
|
67 | + */ |
|
68 | + public function isMultiline(): bool |
|
69 | + { |
|
70 | + return $this->multiline; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Sets whether the user response should accept newline characters. |
|
75 | + * |
|
76 | + * @return $this |
|
77 | + */ |
|
78 | + public function setMultiline(bool $multiline): self |
|
79 | + { |
|
80 | + $this->multiline = $multiline; |
|
81 | + |
|
82 | + return $this; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Returns whether the user response must be hidden. |
|
87 | + * |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public function isHidden() |
|
91 | + { |
|
92 | + return $this->hidden; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Sets whether the user response must be hidden or not. |
|
97 | + * |
|
98 | + * @return $this |
|
99 | + * |
|
100 | + * @throws LogicException In case the autocompleter is also used |
|
101 | + */ |
|
102 | + public function setHidden(bool $hidden) |
|
103 | + { |
|
104 | + if ($this->autocompleterCallback) { |
|
105 | + throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
106 | + } |
|
107 | + |
|
108 | + $this->hidden = (bool) $hidden; |
|
109 | + |
|
110 | + return $this; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * In case the response can not be hidden, whether to fallback on non-hidden question or not. |
|
115 | + * |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + public function isHiddenFallback() |
|
119 | + { |
|
120 | + return $this->hiddenFallback; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Sets whether to fallback on non-hidden question if the response can not be hidden. |
|
125 | + * |
|
126 | + * @return $this |
|
127 | + */ |
|
128 | + public function setHiddenFallback(bool $fallback) |
|
129 | + { |
|
130 | + $this->hiddenFallback = (bool) $fallback; |
|
131 | + |
|
132 | + return $this; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Gets values for the autocompleter. |
|
137 | + * |
|
138 | + * @return iterable|null |
|
139 | + */ |
|
140 | + public function getAutocompleterValues() |
|
141 | + { |
|
142 | + $callback = $this->getAutocompleterCallback(); |
|
143 | + |
|
144 | + return $callback ? $callback('') : null; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Sets values for the autocompleter. |
|
149 | + * |
|
150 | + * @return $this |
|
151 | + * |
|
152 | + * @throws LogicException |
|
153 | + */ |
|
154 | + public function setAutocompleterValues(?iterable $values) |
|
155 | + { |
|
156 | + if (\is_array($values)) { |
|
157 | + $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); |
|
158 | + |
|
159 | + $callback = static function () use ($values) { |
|
160 | + return $values; |
|
161 | + }; |
|
162 | + } elseif ($values instanceof \Traversable) { |
|
163 | + $valueCache = null; |
|
164 | + $callback = static function () use ($values, &$valueCache) { |
|
165 | + return $valueCache ?? $valueCache = iterator_to_array($values, false); |
|
166 | + }; |
|
167 | + } else { |
|
168 | + $callback = null; |
|
169 | + } |
|
170 | + |
|
171 | + return $this->setAutocompleterCallback($callback); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Gets the callback function used for the autocompleter. |
|
176 | + */ |
|
177 | + public function getAutocompleterCallback(): ?callable |
|
178 | + { |
|
179 | + return $this->autocompleterCallback; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Sets the callback function used for the autocompleter. |
|
184 | + * |
|
185 | + * The callback is passed the user input as argument and should return an iterable of corresponding suggestions. |
|
186 | + * |
|
187 | + * @return $this |
|
188 | + */ |
|
189 | + public function setAutocompleterCallback(callable $callback = null): self |
|
190 | + { |
|
191 | + if ($this->hidden && null !== $callback) { |
|
192 | + throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
193 | + } |
|
194 | + |
|
195 | + $this->autocompleterCallback = $callback; |
|
196 | + |
|
197 | + return $this; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Sets a validator for the question. |
|
202 | + * |
|
203 | + * @return $this |
|
204 | + */ |
|
205 | + public function setValidator(callable $validator = null) |
|
206 | + { |
|
207 | + $this->validator = $validator; |
|
208 | + |
|
209 | + return $this; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Gets the validator for the question. |
|
214 | + * |
|
215 | + * @return callable|null |
|
216 | + */ |
|
217 | + public function getValidator() |
|
218 | + { |
|
219 | + return $this->validator; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Sets the maximum number of attempts. |
|
224 | + * |
|
225 | + * Null means an unlimited number of attempts. |
|
226 | + * |
|
227 | + * @return $this |
|
228 | + * |
|
229 | + * @throws InvalidArgumentException in case the number of attempts is invalid |
|
230 | + */ |
|
231 | + public function setMaxAttempts(?int $attempts) |
|
232 | + { |
|
233 | + if (null !== $attempts) { |
|
234 | + $attempts = (int) $attempts; |
|
235 | + if ($attempts < 1) { |
|
236 | + throw new InvalidArgumentException('Maximum number of attempts must be a positive value.'); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + $this->attempts = $attempts; |
|
241 | + |
|
242 | + return $this; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Gets the maximum number of attempts. |
|
247 | + * |
|
248 | + * Null means an unlimited number of attempts. |
|
249 | + * |
|
250 | + * @return int|null |
|
251 | + */ |
|
252 | + public function getMaxAttempts() |
|
253 | + { |
|
254 | + return $this->attempts; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Sets a normalizer for the response. |
|
259 | + * |
|
260 | + * The normalizer can be a callable (a string), a closure or a class implementing __invoke. |
|
261 | + * |
|
262 | + * @return $this |
|
263 | + */ |
|
264 | + public function setNormalizer(callable $normalizer) |
|
265 | + { |
|
266 | + $this->normalizer = $normalizer; |
|
267 | + |
|
268 | + return $this; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Gets the normalizer for the response. |
|
273 | + * |
|
274 | + * The normalizer can ba a callable (a string), a closure or a class implementing __invoke. |
|
275 | + * |
|
276 | + * @return callable|null |
|
277 | + */ |
|
278 | + public function getNormalizer() |
|
279 | + { |
|
280 | + return $this->normalizer; |
|
281 | + } |
|
282 | + |
|
283 | + protected function isAssoc(array $array) |
|
284 | + { |
|
285 | + return (bool) \count(array_filter(array_keys($array), 'is_string')); |
|
286 | + } |
|
287 | + |
|
288 | + public function isTrimmable(): bool |
|
289 | + { |
|
290 | + return $this->trimmable; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * @return $this |
|
295 | + */ |
|
296 | + public function setTrimmable(bool $trimmable): self |
|
297 | + { |
|
298 | + $this->trimmable = $trimmable; |
|
299 | + |
|
300 | + return $this; |
|
301 | + } |
|
302 | 302 | } |
@@ -18,40 +18,40 @@ |
||
18 | 18 | */ |
19 | 19 | class ConfirmationQuestion extends Question |
20 | 20 | { |
21 | - private $trueAnswerRegex; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param string $question The question to ask to the user |
|
25 | - * @param bool $default The default answer to return, true or false |
|
26 | - * @param string $trueAnswerRegex A regex to match the "yes" answer |
|
27 | - */ |
|
28 | - public function __construct(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') |
|
29 | - { |
|
30 | - parent::__construct($question, $default); |
|
31 | - |
|
32 | - $this->trueAnswerRegex = $trueAnswerRegex; |
|
33 | - $this->setNormalizer($this->getDefaultNormalizer()); |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Returns the default answer normalizer. |
|
38 | - */ |
|
39 | - private function getDefaultNormalizer(): callable |
|
40 | - { |
|
41 | - $default = $this->getDefault(); |
|
42 | - $regex = $this->trueAnswerRegex; |
|
43 | - |
|
44 | - return function ($answer) use ($default, $regex) { |
|
45 | - if (\is_bool($answer)) { |
|
46 | - return $answer; |
|
47 | - } |
|
48 | - |
|
49 | - $answerIsTrue = (bool) preg_match($regex, $answer); |
|
50 | - if (false === $default) { |
|
51 | - return $answer && $answerIsTrue; |
|
52 | - } |
|
53 | - |
|
54 | - return '' === $answer || $answerIsTrue; |
|
55 | - }; |
|
56 | - } |
|
21 | + private $trueAnswerRegex; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param string $question The question to ask to the user |
|
25 | + * @param bool $default The default answer to return, true or false |
|
26 | + * @param string $trueAnswerRegex A regex to match the "yes" answer |
|
27 | + */ |
|
28 | + public function __construct(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') |
|
29 | + { |
|
30 | + parent::__construct($question, $default); |
|
31 | + |
|
32 | + $this->trueAnswerRegex = $trueAnswerRegex; |
|
33 | + $this->setNormalizer($this->getDefaultNormalizer()); |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Returns the default answer normalizer. |
|
38 | + */ |
|
39 | + private function getDefaultNormalizer(): callable |
|
40 | + { |
|
41 | + $default = $this->getDefault(); |
|
42 | + $regex = $this->trueAnswerRegex; |
|
43 | + |
|
44 | + return function ($answer) use ($default, $regex) { |
|
45 | + if (\is_bool($answer)) { |
|
46 | + return $answer; |
|
47 | + } |
|
48 | + |
|
49 | + $answerIsTrue = (bool) preg_match($regex, $answer); |
|
50 | + if (false === $default) { |
|
51 | + return $answer && $answerIsTrue; |
|
52 | + } |
|
53 | + |
|
54 | + return '' === $answer || $answerIsTrue; |
|
55 | + }; |
|
56 | + } |
|
57 | 57 | } |
@@ -35,479 +35,479 @@ |
||
35 | 35 | */ |
36 | 36 | class SymfonyStyle extends OutputStyle |
37 | 37 | { |
38 | - public const MAX_LINE_LENGTH = 120; |
|
39 | - |
|
40 | - private $input; |
|
41 | - private $questionHelper; |
|
42 | - private $progressBar; |
|
43 | - private $lineLength; |
|
44 | - private $bufferedOutput; |
|
45 | - |
|
46 | - public function __construct(InputInterface $input, OutputInterface $output) |
|
47 | - { |
|
48 | - $this->input = $input; |
|
49 | - $this->bufferedOutput = new TrimmedBufferOutput(\DIRECTORY_SEPARATOR === '\\' ? 4 : 2, $output->getVerbosity(), false, clone $output->getFormatter()); |
|
50 | - // Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not. |
|
51 | - $width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH; |
|
52 | - $this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH); |
|
53 | - |
|
54 | - parent::__construct($output); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Formats a message as a block of text. |
|
59 | - * |
|
60 | - * @param string|array $messages The message to write in the block |
|
61 | - */ |
|
62 | - public function block($messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true) |
|
63 | - { |
|
64 | - $messages = \is_array($messages) ? array_values($messages) : [$messages]; |
|
65 | - |
|
66 | - $this->autoPrependBlock(); |
|
67 | - $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape)); |
|
68 | - $this->newLine(); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * {@inheritdoc} |
|
73 | - */ |
|
74 | - public function title(string $message) |
|
75 | - { |
|
76 | - $this->autoPrependBlock(); |
|
77 | - $this->writeln([ |
|
78 | - sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), |
|
79 | - sprintf('<comment>%s</>', str_repeat('=', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))), |
|
80 | - ]); |
|
81 | - $this->newLine(); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * {@inheritdoc} |
|
86 | - */ |
|
87 | - public function section(string $message) |
|
88 | - { |
|
89 | - $this->autoPrependBlock(); |
|
90 | - $this->writeln([ |
|
91 | - sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), |
|
92 | - sprintf('<comment>%s</>', str_repeat('-', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))), |
|
93 | - ]); |
|
94 | - $this->newLine(); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * {@inheritdoc} |
|
99 | - */ |
|
100 | - public function listing(array $elements) |
|
101 | - { |
|
102 | - $this->autoPrependText(); |
|
103 | - $elements = array_map(function ($element) { |
|
104 | - return sprintf(' * %s', $element); |
|
105 | - }, $elements); |
|
106 | - |
|
107 | - $this->writeln($elements); |
|
108 | - $this->newLine(); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * {@inheritdoc} |
|
113 | - */ |
|
114 | - public function text($message) |
|
115 | - { |
|
116 | - $this->autoPrependText(); |
|
117 | - |
|
118 | - $messages = \is_array($message) ? array_values($message) : [$message]; |
|
119 | - foreach ($messages as $message) { |
|
120 | - $this->writeln(sprintf(' %s', $message)); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Formats a command comment. |
|
126 | - * |
|
127 | - * @param string|array $message |
|
128 | - */ |
|
129 | - public function comment($message) |
|
130 | - { |
|
131 | - $this->block($message, null, null, '<fg=default;bg=default> // </>', false, false); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * {@inheritdoc} |
|
136 | - */ |
|
137 | - public function success($message) |
|
138 | - { |
|
139 | - $this->block($message, 'OK', 'fg=black;bg=green', ' ', true); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * {@inheritdoc} |
|
144 | - */ |
|
145 | - public function error($message) |
|
146 | - { |
|
147 | - $this->block($message, 'ERROR', 'fg=white;bg=red', ' ', true); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * {@inheritdoc} |
|
152 | - */ |
|
153 | - public function warning($message) |
|
154 | - { |
|
155 | - $this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ', true); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * {@inheritdoc} |
|
160 | - */ |
|
161 | - public function note($message) |
|
162 | - { |
|
163 | - $this->block($message, 'NOTE', 'fg=yellow', ' ! '); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Formats an info message. |
|
168 | - * |
|
169 | - * @param string|array $message |
|
170 | - */ |
|
171 | - public function info($message) |
|
172 | - { |
|
173 | - $this->block($message, 'INFO', 'fg=green', ' ', true); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * {@inheritdoc} |
|
178 | - */ |
|
179 | - public function caution($message) |
|
180 | - { |
|
181 | - $this->block($message, 'CAUTION', 'fg=white;bg=red', ' ! ', true); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * {@inheritdoc} |
|
186 | - */ |
|
187 | - public function table(array $headers, array $rows) |
|
188 | - { |
|
189 | - $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
190 | - $style->setCellHeaderFormat('<info>%s</info>'); |
|
191 | - |
|
192 | - $table = new Table($this); |
|
193 | - $table->setHeaders($headers); |
|
194 | - $table->setRows($rows); |
|
195 | - $table->setStyle($style); |
|
196 | - |
|
197 | - $table->render(); |
|
198 | - $this->newLine(); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Formats a horizontal table. |
|
203 | - */ |
|
204 | - public function horizontalTable(array $headers, array $rows) |
|
205 | - { |
|
206 | - $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
207 | - $style->setCellHeaderFormat('<info>%s</info>'); |
|
208 | - |
|
209 | - $table = new Table($this); |
|
210 | - $table->setHeaders($headers); |
|
211 | - $table->setRows($rows); |
|
212 | - $table->setStyle($style); |
|
213 | - $table->setHorizontal(true); |
|
214 | - |
|
215 | - $table->render(); |
|
216 | - $this->newLine(); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Formats a list of key/value horizontally. |
|
221 | - * |
|
222 | - * Each row can be one of: |
|
223 | - * * 'A title' |
|
224 | - * * ['key' => 'value'] |
|
225 | - * * new TableSeparator() |
|
226 | - * |
|
227 | - * @param string|array|TableSeparator ...$list |
|
228 | - */ |
|
229 | - public function definitionList(...$list) |
|
230 | - { |
|
231 | - $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
232 | - $style->setCellHeaderFormat('<info>%s</info>'); |
|
233 | - |
|
234 | - $table = new Table($this); |
|
235 | - $headers = []; |
|
236 | - $row = []; |
|
237 | - foreach ($list as $value) { |
|
238 | - if ($value instanceof TableSeparator) { |
|
239 | - $headers[] = $value; |
|
240 | - $row[] = $value; |
|
241 | - continue; |
|
242 | - } |
|
243 | - if (\is_string($value)) { |
|
244 | - $headers[] = new TableCell($value, ['colspan' => 2]); |
|
245 | - $row[] = null; |
|
246 | - continue; |
|
247 | - } |
|
248 | - if (!\is_array($value)) { |
|
249 | - throw new InvalidArgumentException('Value should be an array, string, or an instance of TableSeparator.'); |
|
250 | - } |
|
251 | - $headers[] = key($value); |
|
252 | - $row[] = current($value); |
|
253 | - } |
|
254 | - |
|
255 | - $table->setHeaders($headers); |
|
256 | - $table->setRows([$row]); |
|
257 | - $table->setHorizontal(); |
|
258 | - $table->setStyle($style); |
|
259 | - |
|
260 | - $table->render(); |
|
261 | - $this->newLine(); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * {@inheritdoc} |
|
266 | - */ |
|
267 | - public function ask(string $question, string $default = null, callable $validator = null) |
|
268 | - { |
|
269 | - $question = new Question($question, $default); |
|
270 | - $question->setValidator($validator); |
|
271 | - |
|
272 | - return $this->askQuestion($question); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * {@inheritdoc} |
|
277 | - */ |
|
278 | - public function askHidden(string $question, callable $validator = null) |
|
279 | - { |
|
280 | - $question = new Question($question); |
|
281 | - |
|
282 | - $question->setHidden(true); |
|
283 | - $question->setValidator($validator); |
|
284 | - |
|
285 | - return $this->askQuestion($question); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * {@inheritdoc} |
|
290 | - */ |
|
291 | - public function confirm(string $question, bool $default = true) |
|
292 | - { |
|
293 | - return $this->askQuestion(new ConfirmationQuestion($question, $default)); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * {@inheritdoc} |
|
298 | - */ |
|
299 | - public function choice(string $question, array $choices, $default = null) |
|
300 | - { |
|
301 | - if (null !== $default) { |
|
302 | - $values = array_flip($choices); |
|
303 | - $default = $values[$default] ?? $default; |
|
304 | - } |
|
305 | - |
|
306 | - return $this->askQuestion(new ChoiceQuestion($question, $choices, $default)); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * {@inheritdoc} |
|
311 | - */ |
|
312 | - public function progressStart(int $max = 0) |
|
313 | - { |
|
314 | - $this->progressBar = $this->createProgressBar($max); |
|
315 | - $this->progressBar->start(); |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * {@inheritdoc} |
|
320 | - */ |
|
321 | - public function progressAdvance(int $step = 1) |
|
322 | - { |
|
323 | - $this->getProgressBar()->advance($step); |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * {@inheritdoc} |
|
328 | - */ |
|
329 | - public function progressFinish() |
|
330 | - { |
|
331 | - $this->getProgressBar()->finish(); |
|
332 | - $this->newLine(2); |
|
333 | - $this->progressBar = null; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * {@inheritdoc} |
|
338 | - */ |
|
339 | - public function createProgressBar(int $max = 0) |
|
340 | - { |
|
341 | - $progressBar = parent::createProgressBar($max); |
|
342 | - |
|
343 | - if ('\\' !== \DIRECTORY_SEPARATOR || 'Hyper' === getenv('TERM_PROGRAM')) { |
|
344 | - $progressBar->setEmptyBarCharacter('░'); // light shade character \u2591 |
|
345 | - $progressBar->setProgressCharacter(''); |
|
346 | - $progressBar->setBarCharacter('▓'); // dark shade character \u2593 |
|
347 | - } |
|
348 | - |
|
349 | - return $progressBar; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * @return mixed |
|
354 | - */ |
|
355 | - public function askQuestion(Question $question) |
|
356 | - { |
|
357 | - if ($this->input->isInteractive()) { |
|
358 | - $this->autoPrependBlock(); |
|
359 | - } |
|
360 | - |
|
361 | - if (!$this->questionHelper) { |
|
362 | - $this->questionHelper = new SymfonyQuestionHelper(); |
|
363 | - } |
|
364 | - |
|
365 | - $answer = $this->questionHelper->ask($this->input, $this, $question); |
|
366 | - |
|
367 | - if ($this->input->isInteractive()) { |
|
368 | - $this->newLine(); |
|
369 | - $this->bufferedOutput->write("\n"); |
|
370 | - } |
|
371 | - |
|
372 | - return $answer; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * {@inheritdoc} |
|
377 | - */ |
|
378 | - public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
379 | - { |
|
380 | - if (!is_iterable($messages)) { |
|
381 | - $messages = [$messages]; |
|
382 | - } |
|
383 | - |
|
384 | - foreach ($messages as $message) { |
|
385 | - parent::writeln($message, $type); |
|
386 | - $this->writeBuffer($message, true, $type); |
|
387 | - } |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * {@inheritdoc} |
|
392 | - */ |
|
393 | - public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
394 | - { |
|
395 | - if (!is_iterable($messages)) { |
|
396 | - $messages = [$messages]; |
|
397 | - } |
|
398 | - |
|
399 | - foreach ($messages as $message) { |
|
400 | - parent::write($message, $newline, $type); |
|
401 | - $this->writeBuffer($message, $newline, $type); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * {@inheritdoc} |
|
407 | - */ |
|
408 | - public function newLine(int $count = 1) |
|
409 | - { |
|
410 | - parent::newLine($count); |
|
411 | - $this->bufferedOutput->write(str_repeat("\n", $count)); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Returns a new instance which makes use of stderr if available. |
|
416 | - * |
|
417 | - * @return self |
|
418 | - */ |
|
419 | - public function getErrorStyle() |
|
420 | - { |
|
421 | - return new self($this->input, $this->getErrorOutput()); |
|
422 | - } |
|
423 | - |
|
424 | - private function getProgressBar(): ProgressBar |
|
425 | - { |
|
426 | - if (!$this->progressBar) { |
|
427 | - throw new RuntimeException('The ProgressBar is not started.'); |
|
428 | - } |
|
429 | - |
|
430 | - return $this->progressBar; |
|
431 | - } |
|
432 | - |
|
433 | - private function autoPrependBlock(): void |
|
434 | - { |
|
435 | - $chars = substr(str_replace(\PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2); |
|
436 | - |
|
437 | - if (!isset($chars[0])) { |
|
438 | - $this->newLine(); //empty history, so we should start with a new line. |
|
439 | - |
|
440 | - return; |
|
441 | - } |
|
442 | - //Prepend new line for each non LF chars (This means no blank line was output before) |
|
443 | - $this->newLine(2 - substr_count($chars, "\n")); |
|
444 | - } |
|
445 | - |
|
446 | - private function autoPrependText(): void |
|
447 | - { |
|
448 | - $fetched = $this->bufferedOutput->fetch(); |
|
449 | - //Prepend new line if last char isn't EOL: |
|
450 | - if (!str_ends_with($fetched, "\n")) { |
|
451 | - $this->newLine(); |
|
452 | - } |
|
453 | - } |
|
454 | - |
|
455 | - private function writeBuffer(string $message, bool $newLine, int $type): void |
|
456 | - { |
|
457 | - // We need to know if the last chars are PHP_EOL |
|
458 | - $this->bufferedOutput->write($message, $newLine, $type); |
|
459 | - } |
|
460 | - |
|
461 | - private function createBlock(iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false): array |
|
462 | - { |
|
463 | - $indentLength = 0; |
|
464 | - $prefixLength = Helper::width(Helper::removeDecoration($this->getFormatter(), $prefix)); |
|
465 | - $lines = []; |
|
466 | - |
|
467 | - if (null !== $type) { |
|
468 | - $type = sprintf('[%s] ', $type); |
|
469 | - $indentLength = \strlen($type); |
|
470 | - $lineIndentation = str_repeat(' ', $indentLength); |
|
471 | - } |
|
472 | - |
|
473 | - // wrap and add newlines for each element |
|
474 | - foreach ($messages as $key => $message) { |
|
475 | - if ($escape) { |
|
476 | - $message = OutputFormatter::escape($message); |
|
477 | - } |
|
478 | - |
|
479 | - $decorationLength = Helper::width($message) - Helper::width(Helper::removeDecoration($this->getFormatter(), $message)); |
|
480 | - $messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength); |
|
481 | - $messageLines = explode(\PHP_EOL, wordwrap($message, $messageLineLength, \PHP_EOL, true)); |
|
482 | - foreach ($messageLines as $messageLine) { |
|
483 | - $lines[] = $messageLine; |
|
484 | - } |
|
485 | - |
|
486 | - if (\count($messages) > 1 && $key < \count($messages) - 1) { |
|
487 | - $lines[] = ''; |
|
488 | - } |
|
489 | - } |
|
490 | - |
|
491 | - $firstLineIndex = 0; |
|
492 | - if ($padding && $this->isDecorated()) { |
|
493 | - $firstLineIndex = 1; |
|
494 | - array_unshift($lines, ''); |
|
495 | - $lines[] = ''; |
|
496 | - } |
|
497 | - |
|
498 | - foreach ($lines as $i => &$line) { |
|
499 | - if (null !== $type) { |
|
500 | - $line = $firstLineIndex === $i ? $type.$line : $lineIndentation.$line; |
|
501 | - } |
|
502 | - |
|
503 | - $line = $prefix.$line; |
|
504 | - $line .= str_repeat(' ', max($this->lineLength - Helper::width(Helper::removeDecoration($this->getFormatter(), $line)), 0)); |
|
505 | - |
|
506 | - if ($style) { |
|
507 | - $line = sprintf('<%s>%s</>', $style, $line); |
|
508 | - } |
|
509 | - } |
|
510 | - |
|
511 | - return $lines; |
|
512 | - } |
|
38 | + public const MAX_LINE_LENGTH = 120; |
|
39 | + |
|
40 | + private $input; |
|
41 | + private $questionHelper; |
|
42 | + private $progressBar; |
|
43 | + private $lineLength; |
|
44 | + private $bufferedOutput; |
|
45 | + |
|
46 | + public function __construct(InputInterface $input, OutputInterface $output) |
|
47 | + { |
|
48 | + $this->input = $input; |
|
49 | + $this->bufferedOutput = new TrimmedBufferOutput(\DIRECTORY_SEPARATOR === '\\' ? 4 : 2, $output->getVerbosity(), false, clone $output->getFormatter()); |
|
50 | + // Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not. |
|
51 | + $width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH; |
|
52 | + $this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH); |
|
53 | + |
|
54 | + parent::__construct($output); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Formats a message as a block of text. |
|
59 | + * |
|
60 | + * @param string|array $messages The message to write in the block |
|
61 | + */ |
|
62 | + public function block($messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true) |
|
63 | + { |
|
64 | + $messages = \is_array($messages) ? array_values($messages) : [$messages]; |
|
65 | + |
|
66 | + $this->autoPrependBlock(); |
|
67 | + $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape)); |
|
68 | + $this->newLine(); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * {@inheritdoc} |
|
73 | + */ |
|
74 | + public function title(string $message) |
|
75 | + { |
|
76 | + $this->autoPrependBlock(); |
|
77 | + $this->writeln([ |
|
78 | + sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), |
|
79 | + sprintf('<comment>%s</>', str_repeat('=', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))), |
|
80 | + ]); |
|
81 | + $this->newLine(); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * {@inheritdoc} |
|
86 | + */ |
|
87 | + public function section(string $message) |
|
88 | + { |
|
89 | + $this->autoPrependBlock(); |
|
90 | + $this->writeln([ |
|
91 | + sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), |
|
92 | + sprintf('<comment>%s</>', str_repeat('-', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))), |
|
93 | + ]); |
|
94 | + $this->newLine(); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * {@inheritdoc} |
|
99 | + */ |
|
100 | + public function listing(array $elements) |
|
101 | + { |
|
102 | + $this->autoPrependText(); |
|
103 | + $elements = array_map(function ($element) { |
|
104 | + return sprintf(' * %s', $element); |
|
105 | + }, $elements); |
|
106 | + |
|
107 | + $this->writeln($elements); |
|
108 | + $this->newLine(); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * {@inheritdoc} |
|
113 | + */ |
|
114 | + public function text($message) |
|
115 | + { |
|
116 | + $this->autoPrependText(); |
|
117 | + |
|
118 | + $messages = \is_array($message) ? array_values($message) : [$message]; |
|
119 | + foreach ($messages as $message) { |
|
120 | + $this->writeln(sprintf(' %s', $message)); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Formats a command comment. |
|
126 | + * |
|
127 | + * @param string|array $message |
|
128 | + */ |
|
129 | + public function comment($message) |
|
130 | + { |
|
131 | + $this->block($message, null, null, '<fg=default;bg=default> // </>', false, false); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * {@inheritdoc} |
|
136 | + */ |
|
137 | + public function success($message) |
|
138 | + { |
|
139 | + $this->block($message, 'OK', 'fg=black;bg=green', ' ', true); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * {@inheritdoc} |
|
144 | + */ |
|
145 | + public function error($message) |
|
146 | + { |
|
147 | + $this->block($message, 'ERROR', 'fg=white;bg=red', ' ', true); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * {@inheritdoc} |
|
152 | + */ |
|
153 | + public function warning($message) |
|
154 | + { |
|
155 | + $this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ', true); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * {@inheritdoc} |
|
160 | + */ |
|
161 | + public function note($message) |
|
162 | + { |
|
163 | + $this->block($message, 'NOTE', 'fg=yellow', ' ! '); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Formats an info message. |
|
168 | + * |
|
169 | + * @param string|array $message |
|
170 | + */ |
|
171 | + public function info($message) |
|
172 | + { |
|
173 | + $this->block($message, 'INFO', 'fg=green', ' ', true); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * {@inheritdoc} |
|
178 | + */ |
|
179 | + public function caution($message) |
|
180 | + { |
|
181 | + $this->block($message, 'CAUTION', 'fg=white;bg=red', ' ! ', true); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * {@inheritdoc} |
|
186 | + */ |
|
187 | + public function table(array $headers, array $rows) |
|
188 | + { |
|
189 | + $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
190 | + $style->setCellHeaderFormat('<info>%s</info>'); |
|
191 | + |
|
192 | + $table = new Table($this); |
|
193 | + $table->setHeaders($headers); |
|
194 | + $table->setRows($rows); |
|
195 | + $table->setStyle($style); |
|
196 | + |
|
197 | + $table->render(); |
|
198 | + $this->newLine(); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Formats a horizontal table. |
|
203 | + */ |
|
204 | + public function horizontalTable(array $headers, array $rows) |
|
205 | + { |
|
206 | + $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
207 | + $style->setCellHeaderFormat('<info>%s</info>'); |
|
208 | + |
|
209 | + $table = new Table($this); |
|
210 | + $table->setHeaders($headers); |
|
211 | + $table->setRows($rows); |
|
212 | + $table->setStyle($style); |
|
213 | + $table->setHorizontal(true); |
|
214 | + |
|
215 | + $table->render(); |
|
216 | + $this->newLine(); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Formats a list of key/value horizontally. |
|
221 | + * |
|
222 | + * Each row can be one of: |
|
223 | + * * 'A title' |
|
224 | + * * ['key' => 'value'] |
|
225 | + * * new TableSeparator() |
|
226 | + * |
|
227 | + * @param string|array|TableSeparator ...$list |
|
228 | + */ |
|
229 | + public function definitionList(...$list) |
|
230 | + { |
|
231 | + $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
232 | + $style->setCellHeaderFormat('<info>%s</info>'); |
|
233 | + |
|
234 | + $table = new Table($this); |
|
235 | + $headers = []; |
|
236 | + $row = []; |
|
237 | + foreach ($list as $value) { |
|
238 | + if ($value instanceof TableSeparator) { |
|
239 | + $headers[] = $value; |
|
240 | + $row[] = $value; |
|
241 | + continue; |
|
242 | + } |
|
243 | + if (\is_string($value)) { |
|
244 | + $headers[] = new TableCell($value, ['colspan' => 2]); |
|
245 | + $row[] = null; |
|
246 | + continue; |
|
247 | + } |
|
248 | + if (!\is_array($value)) { |
|
249 | + throw new InvalidArgumentException('Value should be an array, string, or an instance of TableSeparator.'); |
|
250 | + } |
|
251 | + $headers[] = key($value); |
|
252 | + $row[] = current($value); |
|
253 | + } |
|
254 | + |
|
255 | + $table->setHeaders($headers); |
|
256 | + $table->setRows([$row]); |
|
257 | + $table->setHorizontal(); |
|
258 | + $table->setStyle($style); |
|
259 | + |
|
260 | + $table->render(); |
|
261 | + $this->newLine(); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * {@inheritdoc} |
|
266 | + */ |
|
267 | + public function ask(string $question, string $default = null, callable $validator = null) |
|
268 | + { |
|
269 | + $question = new Question($question, $default); |
|
270 | + $question->setValidator($validator); |
|
271 | + |
|
272 | + return $this->askQuestion($question); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * {@inheritdoc} |
|
277 | + */ |
|
278 | + public function askHidden(string $question, callable $validator = null) |
|
279 | + { |
|
280 | + $question = new Question($question); |
|
281 | + |
|
282 | + $question->setHidden(true); |
|
283 | + $question->setValidator($validator); |
|
284 | + |
|
285 | + return $this->askQuestion($question); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * {@inheritdoc} |
|
290 | + */ |
|
291 | + public function confirm(string $question, bool $default = true) |
|
292 | + { |
|
293 | + return $this->askQuestion(new ConfirmationQuestion($question, $default)); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * {@inheritdoc} |
|
298 | + */ |
|
299 | + public function choice(string $question, array $choices, $default = null) |
|
300 | + { |
|
301 | + if (null !== $default) { |
|
302 | + $values = array_flip($choices); |
|
303 | + $default = $values[$default] ?? $default; |
|
304 | + } |
|
305 | + |
|
306 | + return $this->askQuestion(new ChoiceQuestion($question, $choices, $default)); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * {@inheritdoc} |
|
311 | + */ |
|
312 | + public function progressStart(int $max = 0) |
|
313 | + { |
|
314 | + $this->progressBar = $this->createProgressBar($max); |
|
315 | + $this->progressBar->start(); |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * {@inheritdoc} |
|
320 | + */ |
|
321 | + public function progressAdvance(int $step = 1) |
|
322 | + { |
|
323 | + $this->getProgressBar()->advance($step); |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * {@inheritdoc} |
|
328 | + */ |
|
329 | + public function progressFinish() |
|
330 | + { |
|
331 | + $this->getProgressBar()->finish(); |
|
332 | + $this->newLine(2); |
|
333 | + $this->progressBar = null; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * {@inheritdoc} |
|
338 | + */ |
|
339 | + public function createProgressBar(int $max = 0) |
|
340 | + { |
|
341 | + $progressBar = parent::createProgressBar($max); |
|
342 | + |
|
343 | + if ('\\' !== \DIRECTORY_SEPARATOR || 'Hyper' === getenv('TERM_PROGRAM')) { |
|
344 | + $progressBar->setEmptyBarCharacter('░'); // light shade character \u2591 |
|
345 | + $progressBar->setProgressCharacter(''); |
|
346 | + $progressBar->setBarCharacter('▓'); // dark shade character \u2593 |
|
347 | + } |
|
348 | + |
|
349 | + return $progressBar; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * @return mixed |
|
354 | + */ |
|
355 | + public function askQuestion(Question $question) |
|
356 | + { |
|
357 | + if ($this->input->isInteractive()) { |
|
358 | + $this->autoPrependBlock(); |
|
359 | + } |
|
360 | + |
|
361 | + if (!$this->questionHelper) { |
|
362 | + $this->questionHelper = new SymfonyQuestionHelper(); |
|
363 | + } |
|
364 | + |
|
365 | + $answer = $this->questionHelper->ask($this->input, $this, $question); |
|
366 | + |
|
367 | + if ($this->input->isInteractive()) { |
|
368 | + $this->newLine(); |
|
369 | + $this->bufferedOutput->write("\n"); |
|
370 | + } |
|
371 | + |
|
372 | + return $answer; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * {@inheritdoc} |
|
377 | + */ |
|
378 | + public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
379 | + { |
|
380 | + if (!is_iterable($messages)) { |
|
381 | + $messages = [$messages]; |
|
382 | + } |
|
383 | + |
|
384 | + foreach ($messages as $message) { |
|
385 | + parent::writeln($message, $type); |
|
386 | + $this->writeBuffer($message, true, $type); |
|
387 | + } |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * {@inheritdoc} |
|
392 | + */ |
|
393 | + public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
394 | + { |
|
395 | + if (!is_iterable($messages)) { |
|
396 | + $messages = [$messages]; |
|
397 | + } |
|
398 | + |
|
399 | + foreach ($messages as $message) { |
|
400 | + parent::write($message, $newline, $type); |
|
401 | + $this->writeBuffer($message, $newline, $type); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * {@inheritdoc} |
|
407 | + */ |
|
408 | + public function newLine(int $count = 1) |
|
409 | + { |
|
410 | + parent::newLine($count); |
|
411 | + $this->bufferedOutput->write(str_repeat("\n", $count)); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Returns a new instance which makes use of stderr if available. |
|
416 | + * |
|
417 | + * @return self |
|
418 | + */ |
|
419 | + public function getErrorStyle() |
|
420 | + { |
|
421 | + return new self($this->input, $this->getErrorOutput()); |
|
422 | + } |
|
423 | + |
|
424 | + private function getProgressBar(): ProgressBar |
|
425 | + { |
|
426 | + if (!$this->progressBar) { |
|
427 | + throw new RuntimeException('The ProgressBar is not started.'); |
|
428 | + } |
|
429 | + |
|
430 | + return $this->progressBar; |
|
431 | + } |
|
432 | + |
|
433 | + private function autoPrependBlock(): void |
|
434 | + { |
|
435 | + $chars = substr(str_replace(\PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2); |
|
436 | + |
|
437 | + if (!isset($chars[0])) { |
|
438 | + $this->newLine(); //empty history, so we should start with a new line. |
|
439 | + |
|
440 | + return; |
|
441 | + } |
|
442 | + //Prepend new line for each non LF chars (This means no blank line was output before) |
|
443 | + $this->newLine(2 - substr_count($chars, "\n")); |
|
444 | + } |
|
445 | + |
|
446 | + private function autoPrependText(): void |
|
447 | + { |
|
448 | + $fetched = $this->bufferedOutput->fetch(); |
|
449 | + //Prepend new line if last char isn't EOL: |
|
450 | + if (!str_ends_with($fetched, "\n")) { |
|
451 | + $this->newLine(); |
|
452 | + } |
|
453 | + } |
|
454 | + |
|
455 | + private function writeBuffer(string $message, bool $newLine, int $type): void |
|
456 | + { |
|
457 | + // We need to know if the last chars are PHP_EOL |
|
458 | + $this->bufferedOutput->write($message, $newLine, $type); |
|
459 | + } |
|
460 | + |
|
461 | + private function createBlock(iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false): array |
|
462 | + { |
|
463 | + $indentLength = 0; |
|
464 | + $prefixLength = Helper::width(Helper::removeDecoration($this->getFormatter(), $prefix)); |
|
465 | + $lines = []; |
|
466 | + |
|
467 | + if (null !== $type) { |
|
468 | + $type = sprintf('[%s] ', $type); |
|
469 | + $indentLength = \strlen($type); |
|
470 | + $lineIndentation = str_repeat(' ', $indentLength); |
|
471 | + } |
|
472 | + |
|
473 | + // wrap and add newlines for each element |
|
474 | + foreach ($messages as $key => $message) { |
|
475 | + if ($escape) { |
|
476 | + $message = OutputFormatter::escape($message); |
|
477 | + } |
|
478 | + |
|
479 | + $decorationLength = Helper::width($message) - Helper::width(Helper::removeDecoration($this->getFormatter(), $message)); |
|
480 | + $messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength); |
|
481 | + $messageLines = explode(\PHP_EOL, wordwrap($message, $messageLineLength, \PHP_EOL, true)); |
|
482 | + foreach ($messageLines as $messageLine) { |
|
483 | + $lines[] = $messageLine; |
|
484 | + } |
|
485 | + |
|
486 | + if (\count($messages) > 1 && $key < \count($messages) - 1) { |
|
487 | + $lines[] = ''; |
|
488 | + } |
|
489 | + } |
|
490 | + |
|
491 | + $firstLineIndex = 0; |
|
492 | + if ($padding && $this->isDecorated()) { |
|
493 | + $firstLineIndex = 1; |
|
494 | + array_unshift($lines, ''); |
|
495 | + $lines[] = ''; |
|
496 | + } |
|
497 | + |
|
498 | + foreach ($lines as $i => &$line) { |
|
499 | + if (null !== $type) { |
|
500 | + $line = $firstLineIndex === $i ? $type.$line : $lineIndentation.$line; |
|
501 | + } |
|
502 | + |
|
503 | + $line = $prefix.$line; |
|
504 | + $line .= str_repeat(' ', max($this->lineLength - Helper::width(Helper::removeDecoration($this->getFormatter(), $line)), 0)); |
|
505 | + |
|
506 | + if ($style) { |
|
507 | + $line = sprintf('<%s>%s</>', $style, $line); |
|
508 | + } |
|
509 | + } |
|
510 | + |
|
511 | + return $lines; |
|
512 | + } |
|
513 | 513 | } |
@@ -18,115 +18,115 @@ |
||
18 | 18 | */ |
19 | 19 | interface StyleInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Formats a command title. |
|
23 | - */ |
|
24 | - public function title(string $message); |
|
25 | - |
|
26 | - /** |
|
27 | - * Formats a section title. |
|
28 | - */ |
|
29 | - public function section(string $message); |
|
30 | - |
|
31 | - /** |
|
32 | - * Formats a list. |
|
33 | - */ |
|
34 | - public function listing(array $elements); |
|
35 | - |
|
36 | - /** |
|
37 | - * Formats informational text. |
|
38 | - * |
|
39 | - * @param string|array $message |
|
40 | - */ |
|
41 | - public function text($message); |
|
42 | - |
|
43 | - /** |
|
44 | - * Formats a success result bar. |
|
45 | - * |
|
46 | - * @param string|array $message |
|
47 | - */ |
|
48 | - public function success($message); |
|
49 | - |
|
50 | - /** |
|
51 | - * Formats an error result bar. |
|
52 | - * |
|
53 | - * @param string|array $message |
|
54 | - */ |
|
55 | - public function error($message); |
|
56 | - |
|
57 | - /** |
|
58 | - * Formats an warning result bar. |
|
59 | - * |
|
60 | - * @param string|array $message |
|
61 | - */ |
|
62 | - public function warning($message); |
|
63 | - |
|
64 | - /** |
|
65 | - * Formats a note admonition. |
|
66 | - * |
|
67 | - * @param string|array $message |
|
68 | - */ |
|
69 | - public function note($message); |
|
70 | - |
|
71 | - /** |
|
72 | - * Formats a caution admonition. |
|
73 | - * |
|
74 | - * @param string|array $message |
|
75 | - */ |
|
76 | - public function caution($message); |
|
77 | - |
|
78 | - /** |
|
79 | - * Formats a table. |
|
80 | - */ |
|
81 | - public function table(array $headers, array $rows); |
|
82 | - |
|
83 | - /** |
|
84 | - * Asks a question. |
|
85 | - * |
|
86 | - * @return mixed |
|
87 | - */ |
|
88 | - public function ask(string $question, string $default = null, callable $validator = null); |
|
89 | - |
|
90 | - /** |
|
91 | - * Asks a question with the user input hidden. |
|
92 | - * |
|
93 | - * @return mixed |
|
94 | - */ |
|
95 | - public function askHidden(string $question, callable $validator = null); |
|
96 | - |
|
97 | - /** |
|
98 | - * Asks for confirmation. |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - public function confirm(string $question, bool $default = true); |
|
103 | - |
|
104 | - /** |
|
105 | - * Asks a choice question. |
|
106 | - * |
|
107 | - * @param string|int|null $default |
|
108 | - * |
|
109 | - * @return mixed |
|
110 | - */ |
|
111 | - public function choice(string $question, array $choices, $default = null); |
|
112 | - |
|
113 | - /** |
|
114 | - * Add newline(s). |
|
115 | - */ |
|
116 | - public function newLine(int $count = 1); |
|
117 | - |
|
118 | - /** |
|
119 | - * Starts the progress output. |
|
120 | - */ |
|
121 | - public function progressStart(int $max = 0); |
|
122 | - |
|
123 | - /** |
|
124 | - * Advances the progress output X steps. |
|
125 | - */ |
|
126 | - public function progressAdvance(int $step = 1); |
|
127 | - |
|
128 | - /** |
|
129 | - * Finishes the progress output. |
|
130 | - */ |
|
131 | - public function progressFinish(); |
|
21 | + /** |
|
22 | + * Formats a command title. |
|
23 | + */ |
|
24 | + public function title(string $message); |
|
25 | + |
|
26 | + /** |
|
27 | + * Formats a section title. |
|
28 | + */ |
|
29 | + public function section(string $message); |
|
30 | + |
|
31 | + /** |
|
32 | + * Formats a list. |
|
33 | + */ |
|
34 | + public function listing(array $elements); |
|
35 | + |
|
36 | + /** |
|
37 | + * Formats informational text. |
|
38 | + * |
|
39 | + * @param string|array $message |
|
40 | + */ |
|
41 | + public function text($message); |
|
42 | + |
|
43 | + /** |
|
44 | + * Formats a success result bar. |
|
45 | + * |
|
46 | + * @param string|array $message |
|
47 | + */ |
|
48 | + public function success($message); |
|
49 | + |
|
50 | + /** |
|
51 | + * Formats an error result bar. |
|
52 | + * |
|
53 | + * @param string|array $message |
|
54 | + */ |
|
55 | + public function error($message); |
|
56 | + |
|
57 | + /** |
|
58 | + * Formats an warning result bar. |
|
59 | + * |
|
60 | + * @param string|array $message |
|
61 | + */ |
|
62 | + public function warning($message); |
|
63 | + |
|
64 | + /** |
|
65 | + * Formats a note admonition. |
|
66 | + * |
|
67 | + * @param string|array $message |
|
68 | + */ |
|
69 | + public function note($message); |
|
70 | + |
|
71 | + /** |
|
72 | + * Formats a caution admonition. |
|
73 | + * |
|
74 | + * @param string|array $message |
|
75 | + */ |
|
76 | + public function caution($message); |
|
77 | + |
|
78 | + /** |
|
79 | + * Formats a table. |
|
80 | + */ |
|
81 | + public function table(array $headers, array $rows); |
|
82 | + |
|
83 | + /** |
|
84 | + * Asks a question. |
|
85 | + * |
|
86 | + * @return mixed |
|
87 | + */ |
|
88 | + public function ask(string $question, string $default = null, callable $validator = null); |
|
89 | + |
|
90 | + /** |
|
91 | + * Asks a question with the user input hidden. |
|
92 | + * |
|
93 | + * @return mixed |
|
94 | + */ |
|
95 | + public function askHidden(string $question, callable $validator = null); |
|
96 | + |
|
97 | + /** |
|
98 | + * Asks for confirmation. |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + public function confirm(string $question, bool $default = true); |
|
103 | + |
|
104 | + /** |
|
105 | + * Asks a choice question. |
|
106 | + * |
|
107 | + * @param string|int|null $default |
|
108 | + * |
|
109 | + * @return mixed |
|
110 | + */ |
|
111 | + public function choice(string $question, array $choices, $default = null); |
|
112 | + |
|
113 | + /** |
|
114 | + * Add newline(s). |
|
115 | + */ |
|
116 | + public function newLine(int $count = 1); |
|
117 | + |
|
118 | + /** |
|
119 | + * Starts the progress output. |
|
120 | + */ |
|
121 | + public function progressStart(int $max = 0); |
|
122 | + |
|
123 | + /** |
|
124 | + * Advances the progress output X steps. |
|
125 | + */ |
|
126 | + public function progressAdvance(int $step = 1); |
|
127 | + |
|
128 | + /** |
|
129 | + * Finishes the progress output. |
|
130 | + */ |
|
131 | + public function progressFinish(); |
|
132 | 132 | } |
@@ -23,131 +23,131 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class OutputStyle implements OutputInterface, StyleInterface |
25 | 25 | { |
26 | - private $output; |
|
27 | - |
|
28 | - public function __construct(OutputInterface $output) |
|
29 | - { |
|
30 | - $this->output = $output; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * {@inheritdoc} |
|
35 | - */ |
|
36 | - public function newLine(int $count = 1) |
|
37 | - { |
|
38 | - $this->output->write(str_repeat(\PHP_EOL, $count)); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @return ProgressBar |
|
43 | - */ |
|
44 | - public function createProgressBar(int $max = 0) |
|
45 | - { |
|
46 | - return new ProgressBar($this->output, $max); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
53 | - { |
|
54 | - $this->output->write($messages, $newline, $type); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * {@inheritdoc} |
|
59 | - */ |
|
60 | - public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
61 | - { |
|
62 | - $this->output->writeln($messages, $type); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - public function setVerbosity(int $level) |
|
69 | - { |
|
70 | - $this->output->setVerbosity($level); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * {@inheritdoc} |
|
75 | - */ |
|
76 | - public function getVerbosity() |
|
77 | - { |
|
78 | - return $this->output->getVerbosity(); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * {@inheritdoc} |
|
83 | - */ |
|
84 | - public function setDecorated(bool $decorated) |
|
85 | - { |
|
86 | - $this->output->setDecorated($decorated); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * {@inheritdoc} |
|
91 | - */ |
|
92 | - public function isDecorated() |
|
93 | - { |
|
94 | - return $this->output->isDecorated(); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * {@inheritdoc} |
|
99 | - */ |
|
100 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
101 | - { |
|
102 | - $this->output->setFormatter($formatter); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * {@inheritdoc} |
|
107 | - */ |
|
108 | - public function getFormatter() |
|
109 | - { |
|
110 | - return $this->output->getFormatter(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * {@inheritdoc} |
|
115 | - */ |
|
116 | - public function isQuiet() |
|
117 | - { |
|
118 | - return $this->output->isQuiet(); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * {@inheritdoc} |
|
123 | - */ |
|
124 | - public function isVerbose() |
|
125 | - { |
|
126 | - return $this->output->isVerbose(); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * {@inheritdoc} |
|
131 | - */ |
|
132 | - public function isVeryVerbose() |
|
133 | - { |
|
134 | - return $this->output->isVeryVerbose(); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * {@inheritdoc} |
|
139 | - */ |
|
140 | - public function isDebug() |
|
141 | - { |
|
142 | - return $this->output->isDebug(); |
|
143 | - } |
|
144 | - |
|
145 | - protected function getErrorOutput() |
|
146 | - { |
|
147 | - if (!$this->output instanceof ConsoleOutputInterface) { |
|
148 | - return $this->output; |
|
149 | - } |
|
150 | - |
|
151 | - return $this->output->getErrorOutput(); |
|
152 | - } |
|
26 | + private $output; |
|
27 | + |
|
28 | + public function __construct(OutputInterface $output) |
|
29 | + { |
|
30 | + $this->output = $output; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * {@inheritdoc} |
|
35 | + */ |
|
36 | + public function newLine(int $count = 1) |
|
37 | + { |
|
38 | + $this->output->write(str_repeat(\PHP_EOL, $count)); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @return ProgressBar |
|
43 | + */ |
|
44 | + public function createProgressBar(int $max = 0) |
|
45 | + { |
|
46 | + return new ProgressBar($this->output, $max); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
53 | + { |
|
54 | + $this->output->write($messages, $newline, $type); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * {@inheritdoc} |
|
59 | + */ |
|
60 | + public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
61 | + { |
|
62 | + $this->output->writeln($messages, $type); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + public function setVerbosity(int $level) |
|
69 | + { |
|
70 | + $this->output->setVerbosity($level); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * {@inheritdoc} |
|
75 | + */ |
|
76 | + public function getVerbosity() |
|
77 | + { |
|
78 | + return $this->output->getVerbosity(); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * {@inheritdoc} |
|
83 | + */ |
|
84 | + public function setDecorated(bool $decorated) |
|
85 | + { |
|
86 | + $this->output->setDecorated($decorated); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * {@inheritdoc} |
|
91 | + */ |
|
92 | + public function isDecorated() |
|
93 | + { |
|
94 | + return $this->output->isDecorated(); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * {@inheritdoc} |
|
99 | + */ |
|
100 | + public function setFormatter(OutputFormatterInterface $formatter) |
|
101 | + { |
|
102 | + $this->output->setFormatter($formatter); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * {@inheritdoc} |
|
107 | + */ |
|
108 | + public function getFormatter() |
|
109 | + { |
|
110 | + return $this->output->getFormatter(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * {@inheritdoc} |
|
115 | + */ |
|
116 | + public function isQuiet() |
|
117 | + { |
|
118 | + return $this->output->isQuiet(); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * {@inheritdoc} |
|
123 | + */ |
|
124 | + public function isVerbose() |
|
125 | + { |
|
126 | + return $this->output->isVerbose(); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * {@inheritdoc} |
|
131 | + */ |
|
132 | + public function isVeryVerbose() |
|
133 | + { |
|
134 | + return $this->output->isVeryVerbose(); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * {@inheritdoc} |
|
139 | + */ |
|
140 | + public function isDebug() |
|
141 | + { |
|
142 | + return $this->output->isDebug(); |
|
143 | + } |
|
144 | + |
|
145 | + protected function getErrorOutput() |
|
146 | + { |
|
147 | + if (!$this->output instanceof ConsoleOutputInterface) { |
|
148 | + return $this->output; |
|
149 | + } |
|
150 | + |
|
151 | + return $this->output->getErrorOutput(); |
|
152 | + } |
|
153 | 153 | } |
@@ -18,41 +18,41 @@ |
||
18 | 18 | */ |
19 | 19 | interface OutputFormatterInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Sets the decorated flag. |
|
23 | - */ |
|
24 | - public function setDecorated(bool $decorated); |
|
25 | - |
|
26 | - /** |
|
27 | - * Gets the decorated flag. |
|
28 | - * |
|
29 | - * @return bool true if the output will decorate messages, false otherwise |
|
30 | - */ |
|
31 | - public function isDecorated(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Sets a new style. |
|
35 | - */ |
|
36 | - public function setStyle(string $name, OutputFormatterStyleInterface $style); |
|
37 | - |
|
38 | - /** |
|
39 | - * Checks if output formatter has style with specified name. |
|
40 | - * |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function hasStyle(string $name); |
|
44 | - |
|
45 | - /** |
|
46 | - * Gets style options from style with specified name. |
|
47 | - * |
|
48 | - * @return OutputFormatterStyleInterface |
|
49 | - * |
|
50 | - * @throws \InvalidArgumentException When style isn't defined |
|
51 | - */ |
|
52 | - public function getStyle(string $name); |
|
53 | - |
|
54 | - /** |
|
55 | - * Formats a message according to the given styles. |
|
56 | - */ |
|
57 | - public function format(?string $message); |
|
21 | + /** |
|
22 | + * Sets the decorated flag. |
|
23 | + */ |
|
24 | + public function setDecorated(bool $decorated); |
|
25 | + |
|
26 | + /** |
|
27 | + * Gets the decorated flag. |
|
28 | + * |
|
29 | + * @return bool true if the output will decorate messages, false otherwise |
|
30 | + */ |
|
31 | + public function isDecorated(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Sets a new style. |
|
35 | + */ |
|
36 | + public function setStyle(string $name, OutputFormatterStyleInterface $style); |
|
37 | + |
|
38 | + /** |
|
39 | + * Checks if output formatter has style with specified name. |
|
40 | + * |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function hasStyle(string $name); |
|
44 | + |
|
45 | + /** |
|
46 | + * Gets style options from style with specified name. |
|
47 | + * |
|
48 | + * @return OutputFormatterStyleInterface |
|
49 | + * |
|
50 | + * @throws \InvalidArgumentException When style isn't defined |
|
51 | + */ |
|
52 | + public function getStyle(string $name); |
|
53 | + |
|
54 | + /** |
|
55 | + * Formats a message according to the given styles. |
|
56 | + */ |
|
57 | + public function format(?string $message); |
|
58 | 58 | } |
@@ -19,92 +19,92 @@ |
||
19 | 19 | */ |
20 | 20 | class OutputFormatterStyleStack implements ResetInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * @var OutputFormatterStyleInterface[] |
|
24 | - */ |
|
25 | - private $styles; |
|
26 | - |
|
27 | - private $emptyStyle; |
|
28 | - |
|
29 | - public function __construct(OutputFormatterStyleInterface $emptyStyle = null) |
|
30 | - { |
|
31 | - $this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle(); |
|
32 | - $this->reset(); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Resets stack (ie. empty internal arrays). |
|
37 | - */ |
|
38 | - public function reset() |
|
39 | - { |
|
40 | - $this->styles = []; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Pushes a style in the stack. |
|
45 | - */ |
|
46 | - public function push(OutputFormatterStyleInterface $style) |
|
47 | - { |
|
48 | - $this->styles[] = $style; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Pops a style from the stack. |
|
53 | - * |
|
54 | - * @return OutputFormatterStyleInterface |
|
55 | - * |
|
56 | - * @throws InvalidArgumentException When style tags incorrectly nested |
|
57 | - */ |
|
58 | - public function pop(OutputFormatterStyleInterface $style = null) |
|
59 | - { |
|
60 | - if (empty($this->styles)) { |
|
61 | - return $this->emptyStyle; |
|
62 | - } |
|
63 | - |
|
64 | - if (null === $style) { |
|
65 | - return array_pop($this->styles); |
|
66 | - } |
|
67 | - |
|
68 | - foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { |
|
69 | - if ($style->apply('') === $stackedStyle->apply('')) { |
|
70 | - $this->styles = \array_slice($this->styles, 0, $index); |
|
71 | - |
|
72 | - return $stackedStyle; |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - throw new InvalidArgumentException('Incorrectly nested style tag found.'); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Computes current style with stacks top codes. |
|
81 | - * |
|
82 | - * @return OutputFormatterStyle |
|
83 | - */ |
|
84 | - public function getCurrent() |
|
85 | - { |
|
86 | - if (empty($this->styles)) { |
|
87 | - return $this->emptyStyle; |
|
88 | - } |
|
89 | - |
|
90 | - return $this->styles[\count($this->styles) - 1]; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @return $this |
|
95 | - */ |
|
96 | - public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) |
|
97 | - { |
|
98 | - $this->emptyStyle = $emptyStyle; |
|
99 | - |
|
100 | - return $this; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @return OutputFormatterStyleInterface |
|
105 | - */ |
|
106 | - public function getEmptyStyle() |
|
107 | - { |
|
108 | - return $this->emptyStyle; |
|
109 | - } |
|
22 | + /** |
|
23 | + * @var OutputFormatterStyleInterface[] |
|
24 | + */ |
|
25 | + private $styles; |
|
26 | + |
|
27 | + private $emptyStyle; |
|
28 | + |
|
29 | + public function __construct(OutputFormatterStyleInterface $emptyStyle = null) |
|
30 | + { |
|
31 | + $this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle(); |
|
32 | + $this->reset(); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Resets stack (ie. empty internal arrays). |
|
37 | + */ |
|
38 | + public function reset() |
|
39 | + { |
|
40 | + $this->styles = []; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Pushes a style in the stack. |
|
45 | + */ |
|
46 | + public function push(OutputFormatterStyleInterface $style) |
|
47 | + { |
|
48 | + $this->styles[] = $style; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Pops a style from the stack. |
|
53 | + * |
|
54 | + * @return OutputFormatterStyleInterface |
|
55 | + * |
|
56 | + * @throws InvalidArgumentException When style tags incorrectly nested |
|
57 | + */ |
|
58 | + public function pop(OutputFormatterStyleInterface $style = null) |
|
59 | + { |
|
60 | + if (empty($this->styles)) { |
|
61 | + return $this->emptyStyle; |
|
62 | + } |
|
63 | + |
|
64 | + if (null === $style) { |
|
65 | + return array_pop($this->styles); |
|
66 | + } |
|
67 | + |
|
68 | + foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { |
|
69 | + if ($style->apply('') === $stackedStyle->apply('')) { |
|
70 | + $this->styles = \array_slice($this->styles, 0, $index); |
|
71 | + |
|
72 | + return $stackedStyle; |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + throw new InvalidArgumentException('Incorrectly nested style tag found.'); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Computes current style with stacks top codes. |
|
81 | + * |
|
82 | + * @return OutputFormatterStyle |
|
83 | + */ |
|
84 | + public function getCurrent() |
|
85 | + { |
|
86 | + if (empty($this->styles)) { |
|
87 | + return $this->emptyStyle; |
|
88 | + } |
|
89 | + |
|
90 | + return $this->styles[\count($this->styles) - 1]; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @return $this |
|
95 | + */ |
|
96 | + public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) |
|
97 | + { |
|
98 | + $this->emptyStyle = $emptyStyle; |
|
99 | + |
|
100 | + return $this; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @return OutputFormatterStyleInterface |
|
105 | + */ |
|
106 | + public function getEmptyStyle() |
|
107 | + { |
|
108 | + return $this->emptyStyle; |
|
109 | + } |
|
110 | 110 | } |
@@ -15,51 +15,51 @@ |
||
15 | 15 | */ |
16 | 16 | final class NullOutputFormatterStyle implements OutputFormatterStyleInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * {@inheritdoc} |
|
20 | - */ |
|
21 | - public function apply(string $text): string |
|
22 | - { |
|
23 | - return $text; |
|
24 | - } |
|
18 | + /** |
|
19 | + * {@inheritdoc} |
|
20 | + */ |
|
21 | + public function apply(string $text): string |
|
22 | + { |
|
23 | + return $text; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritdoc} |
|
28 | - */ |
|
29 | - public function setBackground(string $color = null): void |
|
30 | - { |
|
31 | - // do nothing |
|
32 | - } |
|
26 | + /** |
|
27 | + * {@inheritdoc} |
|
28 | + */ |
|
29 | + public function setBackground(string $color = null): void |
|
30 | + { |
|
31 | + // do nothing |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * {@inheritdoc} |
|
36 | - */ |
|
37 | - public function setForeground(string $color = null): void |
|
38 | - { |
|
39 | - // do nothing |
|
40 | - } |
|
34 | + /** |
|
35 | + * {@inheritdoc} |
|
36 | + */ |
|
37 | + public function setForeground(string $color = null): void |
|
38 | + { |
|
39 | + // do nothing |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritdoc} |
|
44 | - */ |
|
45 | - public function setOption(string $option): void |
|
46 | - { |
|
47 | - // do nothing |
|
48 | - } |
|
42 | + /** |
|
43 | + * {@inheritdoc} |
|
44 | + */ |
|
45 | + public function setOption(string $option): void |
|
46 | + { |
|
47 | + // do nothing |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritdoc} |
|
52 | - */ |
|
53 | - public function setOptions(array $options): void |
|
54 | - { |
|
55 | - // do nothing |
|
56 | - } |
|
50 | + /** |
|
51 | + * {@inheritdoc} |
|
52 | + */ |
|
53 | + public function setOptions(array $options): void |
|
54 | + { |
|
55 | + // do nothing |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritdoc} |
|
60 | - */ |
|
61 | - public function unsetOption(string $option): void |
|
62 | - { |
|
63 | - // do nothing |
|
64 | - } |
|
58 | + /** |
|
59 | + * {@inheritdoc} |
|
60 | + */ |
|
61 | + public function unsetOption(string $option): void |
|
62 | + { |
|
63 | + // do nothing |
|
64 | + } |
|
65 | 65 | } |