@@ -24,72 +24,72 @@ |
||
24 | 24 | */ |
25 | 25 | class ErrorListener implements EventSubscriberInterface |
26 | 26 | { |
27 | - private $logger; |
|
27 | + private $logger; |
|
28 | 28 | |
29 | - public function __construct(LoggerInterface $logger = null) |
|
30 | - { |
|
31 | - $this->logger = $logger; |
|
32 | - } |
|
29 | + public function __construct(LoggerInterface $logger = null) |
|
30 | + { |
|
31 | + $this->logger = $logger; |
|
32 | + } |
|
33 | 33 | |
34 | - public function onConsoleError(ConsoleErrorEvent $event) |
|
35 | - { |
|
36 | - if (null === $this->logger) { |
|
37 | - return; |
|
38 | - } |
|
34 | + public function onConsoleError(ConsoleErrorEvent $event) |
|
35 | + { |
|
36 | + if (null === $this->logger) { |
|
37 | + return; |
|
38 | + } |
|
39 | 39 | |
40 | - $error = $event->getError(); |
|
40 | + $error = $event->getError(); |
|
41 | 41 | |
42 | - if (!$inputString = $this->getInputString($event)) { |
|
43 | - $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); |
|
42 | + if (!$inputString = $this->getInputString($event)) { |
|
43 | + $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); |
|
44 | 44 | |
45 | - return; |
|
46 | - } |
|
45 | + return; |
|
46 | + } |
|
47 | 47 | |
48 | - $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); |
|
49 | - } |
|
48 | + $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); |
|
49 | + } |
|
50 | 50 | |
51 | - public function onConsoleTerminate(ConsoleTerminateEvent $event) |
|
52 | - { |
|
53 | - if (null === $this->logger) { |
|
54 | - return; |
|
55 | - } |
|
51 | + public function onConsoleTerminate(ConsoleTerminateEvent $event) |
|
52 | + { |
|
53 | + if (null === $this->logger) { |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - $exitCode = $event->getExitCode(); |
|
57 | + $exitCode = $event->getExitCode(); |
|
58 | 58 | |
59 | - if (0 === $exitCode) { |
|
60 | - return; |
|
61 | - } |
|
59 | + if (0 === $exitCode) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - if (!$inputString = $this->getInputString($event)) { |
|
64 | - $this->logger->debug('The console exited with code "{code}"', ['code' => $exitCode]); |
|
63 | + if (!$inputString = $this->getInputString($event)) { |
|
64 | + $this->logger->debug('The console exited with code "{code}"', ['code' => $exitCode]); |
|
65 | 65 | |
66 | - return; |
|
67 | - } |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - $this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]); |
|
70 | - } |
|
69 | + $this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]); |
|
70 | + } |
|
71 | 71 | |
72 | - public static function getSubscribedEvents() |
|
73 | - { |
|
74 | - return [ |
|
75 | - ConsoleEvents::ERROR => ['onConsoleError', -128], |
|
76 | - ConsoleEvents::TERMINATE => ['onConsoleTerminate', -128], |
|
77 | - ]; |
|
78 | - } |
|
72 | + public static function getSubscribedEvents() |
|
73 | + { |
|
74 | + return [ |
|
75 | + ConsoleEvents::ERROR => ['onConsoleError', -128], |
|
76 | + ConsoleEvents::TERMINATE => ['onConsoleTerminate', -128], |
|
77 | + ]; |
|
78 | + } |
|
79 | 79 | |
80 | - private static function getInputString(ConsoleEvent $event): ?string |
|
81 | - { |
|
82 | - $commandName = $event->getCommand() ? $event->getCommand()->getName() : null; |
|
83 | - $input = $event->getInput(); |
|
80 | + private static function getInputString(ConsoleEvent $event): ?string |
|
81 | + { |
|
82 | + $commandName = $event->getCommand() ? $event->getCommand()->getName() : null; |
|
83 | + $input = $event->getInput(); |
|
84 | 84 | |
85 | - if (method_exists($input, '__toString')) { |
|
86 | - if ($commandName) { |
|
87 | - return str_replace(["'$commandName'", "\"$commandName\""], $commandName, (string) $input); |
|
88 | - } |
|
85 | + if (method_exists($input, '__toString')) { |
|
86 | + if ($commandName) { |
|
87 | + return str_replace(["'$commandName'", "\"$commandName\""], $commandName, (string) $input); |
|
88 | + } |
|
89 | 89 | |
90 | - return (string) $input; |
|
91 | - } |
|
90 | + return (string) $input; |
|
91 | + } |
|
92 | 92 | |
93 | - return $commandName; |
|
94 | - } |
|
93 | + return $commandName; |
|
94 | + } |
|
95 | 95 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -20,89 +20,89 @@ |
||
20 | 20 | */ |
21 | 21 | class OutputFormatterStyle implements OutputFormatterStyleInterface |
22 | 22 | { |
23 | - private $color; |
|
24 | - private $foreground; |
|
25 | - private $background; |
|
26 | - private $options; |
|
27 | - private $href; |
|
28 | - private $handlesHrefGracefully; |
|
23 | + private $color; |
|
24 | + private $foreground; |
|
25 | + private $background; |
|
26 | + private $options; |
|
27 | + private $href; |
|
28 | + private $handlesHrefGracefully; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Initializes output formatter style. |
|
32 | - * |
|
33 | - * @param string|null $foreground The style foreground color name |
|
34 | - * @param string|null $background The style background color name |
|
35 | - */ |
|
36 | - public function __construct(string $foreground = null, string $background = null, array $options = []) |
|
37 | - { |
|
38 | - $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); |
|
39 | - } |
|
30 | + /** |
|
31 | + * Initializes output formatter style. |
|
32 | + * |
|
33 | + * @param string|null $foreground The style foreground color name |
|
34 | + * @param string|null $background The style background color name |
|
35 | + */ |
|
36 | + public function __construct(string $foreground = null, string $background = null, array $options = []) |
|
37 | + { |
|
38 | + $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - public function setForeground(string $color = null) |
|
45 | - { |
|
46 | - $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); |
|
47 | - } |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + public function setForeground(string $color = null) |
|
45 | + { |
|
46 | + $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function setBackground(string $color = null) |
|
53 | - { |
|
54 | - $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); |
|
55 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function setBackground(string $color = null) |
|
53 | + { |
|
54 | + $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); |
|
55 | + } |
|
56 | 56 | |
57 | - public function setHref(string $url): void |
|
58 | - { |
|
59 | - $this->href = $url; |
|
60 | - } |
|
57 | + public function setHref(string $url): void |
|
58 | + { |
|
59 | + $this->href = $url; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritdoc} |
|
64 | - */ |
|
65 | - public function setOption(string $option) |
|
66 | - { |
|
67 | - $this->options[] = $option; |
|
68 | - $this->color = new Color($this->foreground, $this->background, $this->options); |
|
69 | - } |
|
62 | + /** |
|
63 | + * {@inheritdoc} |
|
64 | + */ |
|
65 | + public function setOption(string $option) |
|
66 | + { |
|
67 | + $this->options[] = $option; |
|
68 | + $this->color = new Color($this->foreground, $this->background, $this->options); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * {@inheritdoc} |
|
73 | - */ |
|
74 | - public function unsetOption(string $option) |
|
75 | - { |
|
76 | - $pos = array_search($option, $this->options); |
|
77 | - if (false !== $pos) { |
|
78 | - unset($this->options[$pos]); |
|
79 | - } |
|
71 | + /** |
|
72 | + * {@inheritdoc} |
|
73 | + */ |
|
74 | + public function unsetOption(string $option) |
|
75 | + { |
|
76 | + $pos = array_search($option, $this->options); |
|
77 | + if (false !== $pos) { |
|
78 | + unset($this->options[$pos]); |
|
79 | + } |
|
80 | 80 | |
81 | - $this->color = new Color($this->foreground, $this->background, $this->options); |
|
82 | - } |
|
81 | + $this->color = new Color($this->foreground, $this->background, $this->options); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * {@inheritdoc} |
|
86 | - */ |
|
87 | - public function setOptions(array $options) |
|
88 | - { |
|
89 | - $this->color = new Color($this->foreground, $this->background, $this->options = $options); |
|
90 | - } |
|
84 | + /** |
|
85 | + * {@inheritdoc} |
|
86 | + */ |
|
87 | + public function setOptions(array $options) |
|
88 | + { |
|
89 | + $this->color = new Color($this->foreground, $this->background, $this->options = $options); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * {@inheritdoc} |
|
94 | - */ |
|
95 | - public function apply(string $text) |
|
96 | - { |
|
97 | - if (null === $this->handlesHrefGracefully) { |
|
98 | - $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') |
|
99 | - && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); |
|
100 | - } |
|
92 | + /** |
|
93 | + * {@inheritdoc} |
|
94 | + */ |
|
95 | + public function apply(string $text) |
|
96 | + { |
|
97 | + if (null === $this->handlesHrefGracefully) { |
|
98 | + $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') |
|
99 | + && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); |
|
100 | + } |
|
101 | 101 | |
102 | - if (null !== $this->href && $this->handlesHrefGracefully) { |
|
103 | - $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; |
|
104 | - } |
|
102 | + if (null !== $this->href && $this->handlesHrefGracefully) { |
|
103 | + $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; |
|
104 | + } |
|
105 | 105 | |
106 | - return $this->color->apply($text); |
|
107 | - } |
|
106 | + return $this->color->apply($text); |
|
107 | + } |
|
108 | 108 | } |
@@ -18,35 +18,35 @@ |
||
18 | 18 | */ |
19 | 19 | interface OutputFormatterStyleInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Sets style foreground color. |
|
23 | - */ |
|
24 | - public function setForeground(string $color = null); |
|
25 | - |
|
26 | - /** |
|
27 | - * Sets style background color. |
|
28 | - */ |
|
29 | - public function setBackground(string $color = null); |
|
30 | - |
|
31 | - /** |
|
32 | - * Sets some specific style option. |
|
33 | - */ |
|
34 | - public function setOption(string $option); |
|
35 | - |
|
36 | - /** |
|
37 | - * Unsets some specific style option. |
|
38 | - */ |
|
39 | - public function unsetOption(string $option); |
|
40 | - |
|
41 | - /** |
|
42 | - * Sets multiple style options at once. |
|
43 | - */ |
|
44 | - public function setOptions(array $options); |
|
45 | - |
|
46 | - /** |
|
47 | - * Applies the style to a given text. |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function apply(string $text); |
|
21 | + /** |
|
22 | + * Sets style foreground color. |
|
23 | + */ |
|
24 | + public function setForeground(string $color = null); |
|
25 | + |
|
26 | + /** |
|
27 | + * Sets style background color. |
|
28 | + */ |
|
29 | + public function setBackground(string $color = null); |
|
30 | + |
|
31 | + /** |
|
32 | + * Sets some specific style option. |
|
33 | + */ |
|
34 | + public function setOption(string $option); |
|
35 | + |
|
36 | + /** |
|
37 | + * Unsets some specific style option. |
|
38 | + */ |
|
39 | + public function unsetOption(string $option); |
|
40 | + |
|
41 | + /** |
|
42 | + * Sets multiple style options at once. |
|
43 | + */ |
|
44 | + public function setOptions(array $options); |
|
45 | + |
|
46 | + /** |
|
47 | + * Applies the style to a given text. |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function apply(string $text); |
|
52 | 52 | } |