@@ -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 | } |
@@ -16,57 +16,57 @@ |
||
16 | 16 | */ |
17 | 17 | final class NullOutputFormatter implements OutputFormatterInterface |
18 | 18 | { |
19 | - private $style; |
|
19 | + private $style; |
|
20 | 20 | |
21 | - /** |
|
22 | - * {@inheritdoc} |
|
23 | - */ |
|
24 | - public function format(?string $message): void |
|
25 | - { |
|
26 | - // do nothing |
|
27 | - } |
|
21 | + /** |
|
22 | + * {@inheritdoc} |
|
23 | + */ |
|
24 | + public function format(?string $message): void |
|
25 | + { |
|
26 | + // do nothing |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - public function getStyle(string $name): OutputFormatterStyleInterface |
|
33 | - { |
|
34 | - if ($this->style) { |
|
35 | - return $this->style; |
|
36 | - } |
|
37 | - // to comply with the interface we must return a OutputFormatterStyleInterface |
|
38 | - return $this->style = new NullOutputFormatterStyle(); |
|
39 | - } |
|
29 | + /** |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + public function getStyle(string $name): OutputFormatterStyleInterface |
|
33 | + { |
|
34 | + if ($this->style) { |
|
35 | + return $this->style; |
|
36 | + } |
|
37 | + // to comply with the interface we must return a OutputFormatterStyleInterface |
|
38 | + return $this->style = new NullOutputFormatterStyle(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - public function hasStyle(string $name): bool |
|
45 | - { |
|
46 | - return false; |
|
47 | - } |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + public function hasStyle(string $name): bool |
|
45 | + { |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function isDecorated(): bool |
|
53 | - { |
|
54 | - return false; |
|
55 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function isDecorated(): bool |
|
53 | + { |
|
54 | + return false; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritdoc} |
|
59 | - */ |
|
60 | - public function setDecorated(bool $decorated): void |
|
61 | - { |
|
62 | - // do nothing |
|
63 | - } |
|
57 | + /** |
|
58 | + * {@inheritdoc} |
|
59 | + */ |
|
60 | + public function setDecorated(bool $decorated): void |
|
61 | + { |
|
62 | + // do nothing |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - public function setStyle(string $name, OutputFormatterStyleInterface $style): void |
|
69 | - { |
|
70 | - // do nothing |
|
71 | - } |
|
65 | + /** |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + public function setStyle(string $name, OutputFormatterStyleInterface $style): void |
|
69 | + { |
|
70 | + // do nothing |
|
71 | + } |
|
72 | 72 | } |
@@ -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 | } |
@@ -18,8 +18,8 @@ |
||
18 | 18 | */ |
19 | 19 | interface WrappableOutputFormatterInterface extends OutputFormatterInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping). |
|
23 | - */ |
|
24 | - public function formatAndWrap(?string $message, int $width); |
|
21 | + /** |
|
22 | + * Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping). |
|
23 | + */ |
|
24 | + public function formatAndWrap(?string $message, int $width); |
|
25 | 25 | } |
@@ -18,151 +18,151 @@ |
||
18 | 18 | */ |
19 | 19 | final class Cursor |
20 | 20 | { |
21 | - private $output; |
|
22 | - private $input; |
|
21 | + private $output; |
|
22 | + private $input; |
|
23 | 23 | |
24 | - public function __construct(OutputInterface $output, $input = null) |
|
25 | - { |
|
26 | - $this->output = $output; |
|
27 | - $this->input = $input ?? (\defined('STDIN') ? \STDIN : fopen('php://input', 'r+')); |
|
28 | - } |
|
24 | + public function __construct(OutputInterface $output, $input = null) |
|
25 | + { |
|
26 | + $this->output = $output; |
|
27 | + $this->input = $input ?? (\defined('STDIN') ? \STDIN : fopen('php://input', 'r+')); |
|
28 | + } |
|
29 | 29 | |
30 | - public function moveUp(int $lines = 1): self |
|
31 | - { |
|
32 | - $this->output->write(sprintf("\x1b[%dA", $lines)); |
|
30 | + public function moveUp(int $lines = 1): self |
|
31 | + { |
|
32 | + $this->output->write(sprintf("\x1b[%dA", $lines)); |
|
33 | 33 | |
34 | - return $this; |
|
35 | - } |
|
34 | + return $this; |
|
35 | + } |
|
36 | 36 | |
37 | - public function moveDown(int $lines = 1): self |
|
38 | - { |
|
39 | - $this->output->write(sprintf("\x1b[%dB", $lines)); |
|
37 | + public function moveDown(int $lines = 1): self |
|
38 | + { |
|
39 | + $this->output->write(sprintf("\x1b[%dB", $lines)); |
|
40 | 40 | |
41 | - return $this; |
|
42 | - } |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | |
44 | - public function moveRight(int $columns = 1): self |
|
45 | - { |
|
46 | - $this->output->write(sprintf("\x1b[%dC", $columns)); |
|
44 | + public function moveRight(int $columns = 1): self |
|
45 | + { |
|
46 | + $this->output->write(sprintf("\x1b[%dC", $columns)); |
|
47 | 47 | |
48 | - return $this; |
|
49 | - } |
|
48 | + return $this; |
|
49 | + } |
|
50 | 50 | |
51 | - public function moveLeft(int $columns = 1): self |
|
52 | - { |
|
53 | - $this->output->write(sprintf("\x1b[%dD", $columns)); |
|
51 | + public function moveLeft(int $columns = 1): self |
|
52 | + { |
|
53 | + $this->output->write(sprintf("\x1b[%dD", $columns)); |
|
54 | 54 | |
55 | - return $this; |
|
56 | - } |
|
55 | + return $this; |
|
56 | + } |
|
57 | 57 | |
58 | - public function moveToColumn(int $column): self |
|
59 | - { |
|
60 | - $this->output->write(sprintf("\x1b[%dG", $column)); |
|
58 | + public function moveToColumn(int $column): self |
|
59 | + { |
|
60 | + $this->output->write(sprintf("\x1b[%dG", $column)); |
|
61 | 61 | |
62 | - return $this; |
|
63 | - } |
|
62 | + return $this; |
|
63 | + } |
|
64 | 64 | |
65 | - public function moveToPosition(int $column, int $row): self |
|
66 | - { |
|
67 | - $this->output->write(sprintf("\x1b[%d;%dH", $row + 1, $column)); |
|
65 | + public function moveToPosition(int $column, int $row): self |
|
66 | + { |
|
67 | + $this->output->write(sprintf("\x1b[%d;%dH", $row + 1, $column)); |
|
68 | 68 | |
69 | - return $this; |
|
70 | - } |
|
69 | + return $this; |
|
70 | + } |
|
71 | 71 | |
72 | - public function savePosition(): self |
|
73 | - { |
|
74 | - $this->output->write("\x1b7"); |
|
72 | + public function savePosition(): self |
|
73 | + { |
|
74 | + $this->output->write("\x1b7"); |
|
75 | 75 | |
76 | - return $this; |
|
77 | - } |
|
76 | + return $this; |
|
77 | + } |
|
78 | 78 | |
79 | - public function restorePosition(): self |
|
80 | - { |
|
81 | - $this->output->write("\x1b8"); |
|
79 | + public function restorePosition(): self |
|
80 | + { |
|
81 | + $this->output->write("\x1b8"); |
|
82 | 82 | |
83 | - return $this; |
|
84 | - } |
|
83 | + return $this; |
|
84 | + } |
|
85 | 85 | |
86 | - public function hide(): self |
|
87 | - { |
|
88 | - $this->output->write("\x1b[?25l"); |
|
86 | + public function hide(): self |
|
87 | + { |
|
88 | + $this->output->write("\x1b[?25l"); |
|
89 | 89 | |
90 | - return $this; |
|
91 | - } |
|
90 | + return $this; |
|
91 | + } |
|
92 | 92 | |
93 | - public function show(): self |
|
94 | - { |
|
95 | - $this->output->write("\x1b[?25h\x1b[?0c"); |
|
93 | + public function show(): self |
|
94 | + { |
|
95 | + $this->output->write("\x1b[?25h\x1b[?0c"); |
|
96 | 96 | |
97 | - return $this; |
|
98 | - } |
|
97 | + return $this; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Clears all the output from the current line. |
|
102 | - */ |
|
103 | - public function clearLine(): self |
|
104 | - { |
|
105 | - $this->output->write("\x1b[2K"); |
|
100 | + /** |
|
101 | + * Clears all the output from the current line. |
|
102 | + */ |
|
103 | + public function clearLine(): self |
|
104 | + { |
|
105 | + $this->output->write("\x1b[2K"); |
|
106 | 106 | |
107 | - return $this; |
|
108 | - } |
|
107 | + return $this; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Clears all the output from the current line after the current position. |
|
112 | - */ |
|
113 | - public function clearLineAfter(): self |
|
114 | - { |
|
115 | - $this->output->write("\x1b[K"); |
|
110 | + /** |
|
111 | + * Clears all the output from the current line after the current position. |
|
112 | + */ |
|
113 | + public function clearLineAfter(): self |
|
114 | + { |
|
115 | + $this->output->write("\x1b[K"); |
|
116 | 116 | |
117 | - return $this; |
|
118 | - } |
|
117 | + return $this; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Clears all the output from the cursors' current position to the end of the screen. |
|
122 | - */ |
|
123 | - public function clearOutput(): self |
|
124 | - { |
|
125 | - $this->output->write("\x1b[0J"); |
|
120 | + /** |
|
121 | + * Clears all the output from the cursors' current position to the end of the screen. |
|
122 | + */ |
|
123 | + public function clearOutput(): self |
|
124 | + { |
|
125 | + $this->output->write("\x1b[0J"); |
|
126 | 126 | |
127 | - return $this; |
|
128 | - } |
|
127 | + return $this; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Clears the entire screen. |
|
132 | - */ |
|
133 | - public function clearScreen(): self |
|
134 | - { |
|
135 | - $this->output->write("\x1b[2J"); |
|
130 | + /** |
|
131 | + * Clears the entire screen. |
|
132 | + */ |
|
133 | + public function clearScreen(): self |
|
134 | + { |
|
135 | + $this->output->write("\x1b[2J"); |
|
136 | 136 | |
137 | - return $this; |
|
138 | - } |
|
137 | + return $this; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Returns the current cursor position as x,y coordinates. |
|
142 | - */ |
|
143 | - public function getCurrentPosition(): array |
|
144 | - { |
|
145 | - static $isTtySupported; |
|
140 | + /** |
|
141 | + * Returns the current cursor position as x,y coordinates. |
|
142 | + */ |
|
143 | + public function getCurrentPosition(): array |
|
144 | + { |
|
145 | + static $isTtySupported; |
|
146 | 146 | |
147 | - if (null === $isTtySupported && \function_exists('proc_open')) { |
|
148 | - $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes); |
|
149 | - } |
|
147 | + if (null === $isTtySupported && \function_exists('proc_open')) { |
|
148 | + $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes); |
|
149 | + } |
|
150 | 150 | |
151 | - if (!$isTtySupported) { |
|
152 | - return [1, 1]; |
|
153 | - } |
|
151 | + if (!$isTtySupported) { |
|
152 | + return [1, 1]; |
|
153 | + } |
|
154 | 154 | |
155 | - $sttyMode = shell_exec('stty -g'); |
|
156 | - shell_exec('stty -icanon -echo'); |
|
155 | + $sttyMode = shell_exec('stty -g'); |
|
156 | + shell_exec('stty -icanon -echo'); |
|
157 | 157 | |
158 | - @fwrite($this->input, "\033[6n"); |
|
158 | + @fwrite($this->input, "\033[6n"); |
|
159 | 159 | |
160 | - $code = trim(fread($this->input, 1024)); |
|
160 | + $code = trim(fread($this->input, 1024)); |
|
161 | 161 | |
162 | - shell_exec(sprintf('stty %s', $sttyMode)); |
|
162 | + shell_exec(sprintf('stty %s', $sttyMode)); |
|
163 | 163 | |
164 | - sscanf($code, "\033[%d;%dR", $row, $col); |
|
164 | + sscanf($code, "\033[%d;%dR", $row, $col); |
|
165 | 165 | |
166 | - return [$col, $row]; |
|
167 | - } |
|
166 | + return [$col, $row]; |
|
167 | + } |
|
168 | 168 | } |
@@ -23,50 +23,50 @@ |
||
23 | 23 | */ |
24 | 24 | final class ConsoleEvents |
25 | 25 | { |
26 | - /** |
|
27 | - * The COMMAND event allows you to attach listeners before any command is |
|
28 | - * executed by the console. It also allows you to modify the command, input and output |
|
29 | - * before they are handed to the command. |
|
30 | - * |
|
31 | - * @Event("Symfony\Component\Console\Event\ConsoleCommandEvent") |
|
32 | - */ |
|
33 | - public const COMMAND = 'console.command'; |
|
26 | + /** |
|
27 | + * The COMMAND event allows you to attach listeners before any command is |
|
28 | + * executed by the console. It also allows you to modify the command, input and output |
|
29 | + * before they are handed to the command. |
|
30 | + * |
|
31 | + * @Event("Symfony\Component\Console\Event\ConsoleCommandEvent") |
|
32 | + */ |
|
33 | + public const COMMAND = 'console.command'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * The SIGNAL event allows you to perform some actions |
|
37 | - * after the command execution was interrupted. |
|
38 | - * |
|
39 | - * @Event("Symfony\Component\Console\Event\ConsoleSignalEvent") |
|
40 | - */ |
|
41 | - public const SIGNAL = 'console.signal'; |
|
35 | + /** |
|
36 | + * The SIGNAL event allows you to perform some actions |
|
37 | + * after the command execution was interrupted. |
|
38 | + * |
|
39 | + * @Event("Symfony\Component\Console\Event\ConsoleSignalEvent") |
|
40 | + */ |
|
41 | + public const SIGNAL = 'console.signal'; |
|
42 | 42 | |
43 | - /** |
|
44 | - * The TERMINATE event allows you to attach listeners after a command is |
|
45 | - * executed by the console. |
|
46 | - * |
|
47 | - * @Event("Symfony\Component\Console\Event\ConsoleTerminateEvent") |
|
48 | - */ |
|
49 | - public const TERMINATE = 'console.terminate'; |
|
43 | + /** |
|
44 | + * The TERMINATE event allows you to attach listeners after a command is |
|
45 | + * executed by the console. |
|
46 | + * |
|
47 | + * @Event("Symfony\Component\Console\Event\ConsoleTerminateEvent") |
|
48 | + */ |
|
49 | + public const TERMINATE = 'console.terminate'; |
|
50 | 50 | |
51 | - /** |
|
52 | - * The ERROR event occurs when an uncaught exception or error appears. |
|
53 | - * |
|
54 | - * This event allows you to deal with the exception/error or |
|
55 | - * to modify the thrown exception. |
|
56 | - * |
|
57 | - * @Event("Symfony\Component\Console\Event\ConsoleErrorEvent") |
|
58 | - */ |
|
59 | - public const ERROR = 'console.error'; |
|
51 | + /** |
|
52 | + * The ERROR event occurs when an uncaught exception or error appears. |
|
53 | + * |
|
54 | + * This event allows you to deal with the exception/error or |
|
55 | + * to modify the thrown exception. |
|
56 | + * |
|
57 | + * @Event("Symfony\Component\Console\Event\ConsoleErrorEvent") |
|
58 | + */ |
|
59 | + public const ERROR = 'console.error'; |
|
60 | 60 | |
61 | - /** |
|
62 | - * Event aliases. |
|
63 | - * |
|
64 | - * These aliases can be consumed by RegisterListenersPass. |
|
65 | - */ |
|
66 | - public const ALIASES = [ |
|
67 | - ConsoleCommandEvent::class => self::COMMAND, |
|
68 | - ConsoleErrorEvent::class => self::ERROR, |
|
69 | - ConsoleSignalEvent::class => self::SIGNAL, |
|
70 | - ConsoleTerminateEvent::class => self::TERMINATE, |
|
71 | - ]; |
|
61 | + /** |
|
62 | + * Event aliases. |
|
63 | + * |
|
64 | + * These aliases can be consumed by RegisterListenersPass. |
|
65 | + */ |
|
66 | + public const ALIASES = [ |
|
67 | + ConsoleCommandEvent::class => self::COMMAND, |
|
68 | + ConsoleErrorEvent::class => self::ERROR, |
|
69 | + ConsoleSignalEvent::class => self::SIGNAL, |
|
70 | + ConsoleTerminateEvent::class => self::TERMINATE, |
|
71 | + ]; |
|
72 | 72 | } |
@@ -29,120 +29,120 @@ |
||
29 | 29 | */ |
30 | 30 | class AddConsoleCommandPass implements CompilerPassInterface |
31 | 31 | { |
32 | - private $commandLoaderServiceId; |
|
33 | - private $commandTag; |
|
34 | - private $noPreloadTag; |
|
35 | - private $privateTagName; |
|
36 | - |
|
37 | - public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private') |
|
38 | - { |
|
39 | - if (0 < \func_num_args()) { |
|
40 | - trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); |
|
41 | - } |
|
42 | - |
|
43 | - $this->commandLoaderServiceId = $commandLoaderServiceId; |
|
44 | - $this->commandTag = $commandTag; |
|
45 | - $this->noPreloadTag = $noPreloadTag; |
|
46 | - $this->privateTagName = $privateTagName; |
|
47 | - } |
|
48 | - |
|
49 | - public function process(ContainerBuilder $container) |
|
50 | - { |
|
51 | - $commandServices = $container->findTaggedServiceIds($this->commandTag, true); |
|
52 | - $lazyCommandMap = []; |
|
53 | - $lazyCommandRefs = []; |
|
54 | - $serviceIds = []; |
|
55 | - |
|
56 | - foreach ($commandServices as $id => $tags) { |
|
57 | - $definition = $container->getDefinition($id); |
|
58 | - $definition->addTag($this->noPreloadTag); |
|
59 | - $class = $container->getParameterBag()->resolveValue($definition->getClass()); |
|
60 | - |
|
61 | - if (isset($tags[0]['command'])) { |
|
62 | - $aliases = $tags[0]['command']; |
|
63 | - } else { |
|
64 | - if (!$r = $container->getReflectionClass($class)) { |
|
65 | - throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); |
|
66 | - } |
|
67 | - if (!$r->isSubclassOf(Command::class)) { |
|
68 | - throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); |
|
69 | - } |
|
70 | - $aliases = $class::getDefaultName(); |
|
71 | - } |
|
72 | - |
|
73 | - $aliases = explode('|', $aliases ?? ''); |
|
74 | - $commandName = array_shift($aliases); |
|
75 | - |
|
76 | - if ($isHidden = '' === $commandName) { |
|
77 | - $commandName = array_shift($aliases); |
|
78 | - } |
|
79 | - |
|
80 | - if (null === $commandName) { |
|
81 | - if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) { |
|
82 | - $commandId = 'console.command.public_alias.'.$id; |
|
83 | - $container->setAlias($commandId, $id)->setPublic(true); |
|
84 | - $id = $commandId; |
|
85 | - } |
|
86 | - $serviceIds[] = $id; |
|
87 | - |
|
88 | - continue; |
|
89 | - } |
|
90 | - |
|
91 | - $description = $tags[0]['description'] ?? null; |
|
92 | - |
|
93 | - unset($tags[0]); |
|
94 | - $lazyCommandMap[$commandName] = $id; |
|
95 | - $lazyCommandRefs[$id] = new TypedReference($id, $class); |
|
96 | - |
|
97 | - foreach ($aliases as $alias) { |
|
98 | - $lazyCommandMap[$alias] = $id; |
|
99 | - } |
|
100 | - |
|
101 | - foreach ($tags as $tag) { |
|
102 | - if (isset($tag['command'])) { |
|
103 | - $aliases[] = $tag['command']; |
|
104 | - $lazyCommandMap[$tag['command']] = $id; |
|
105 | - } |
|
106 | - |
|
107 | - $description = $description ?? $tag['description'] ?? null; |
|
108 | - } |
|
109 | - |
|
110 | - $definition->addMethodCall('setName', [$commandName]); |
|
111 | - |
|
112 | - if ($aliases) { |
|
113 | - $definition->addMethodCall('setAliases', [$aliases]); |
|
114 | - } |
|
115 | - |
|
116 | - if ($isHidden) { |
|
117 | - $definition->addMethodCall('setHidden', [true]); |
|
118 | - } |
|
119 | - |
|
120 | - if (!$description) { |
|
121 | - if (!$r = $container->getReflectionClass($class)) { |
|
122 | - throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); |
|
123 | - } |
|
124 | - if (!$r->isSubclassOf(Command::class)) { |
|
125 | - throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); |
|
126 | - } |
|
127 | - $description = $class::getDefaultDescription(); |
|
128 | - } |
|
129 | - |
|
130 | - if ($description) { |
|
131 | - $definition->addMethodCall('setDescription', [$description]); |
|
132 | - |
|
133 | - $container->register('.'.$id.'.lazy', LazyCommand::class) |
|
134 | - ->setArguments([$commandName, $aliases, $description, $isHidden, new ServiceClosureArgument($lazyCommandRefs[$id])]); |
|
135 | - |
|
136 | - $lazyCommandRefs[$id] = new Reference('.'.$id.'.lazy'); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - $container |
|
141 | - ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) |
|
142 | - ->setPublic(true) |
|
143 | - ->addTag($this->noPreloadTag) |
|
144 | - ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); |
|
145 | - |
|
146 | - $container->setParameter('console.command.ids', $serviceIds); |
|
147 | - } |
|
32 | + private $commandLoaderServiceId; |
|
33 | + private $commandTag; |
|
34 | + private $noPreloadTag; |
|
35 | + private $privateTagName; |
|
36 | + |
|
37 | + public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private') |
|
38 | + { |
|
39 | + if (0 < \func_num_args()) { |
|
40 | + trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); |
|
41 | + } |
|
42 | + |
|
43 | + $this->commandLoaderServiceId = $commandLoaderServiceId; |
|
44 | + $this->commandTag = $commandTag; |
|
45 | + $this->noPreloadTag = $noPreloadTag; |
|
46 | + $this->privateTagName = $privateTagName; |
|
47 | + } |
|
48 | + |
|
49 | + public function process(ContainerBuilder $container) |
|
50 | + { |
|
51 | + $commandServices = $container->findTaggedServiceIds($this->commandTag, true); |
|
52 | + $lazyCommandMap = []; |
|
53 | + $lazyCommandRefs = []; |
|
54 | + $serviceIds = []; |
|
55 | + |
|
56 | + foreach ($commandServices as $id => $tags) { |
|
57 | + $definition = $container->getDefinition($id); |
|
58 | + $definition->addTag($this->noPreloadTag); |
|
59 | + $class = $container->getParameterBag()->resolveValue($definition->getClass()); |
|
60 | + |
|
61 | + if (isset($tags[0]['command'])) { |
|
62 | + $aliases = $tags[0]['command']; |
|
63 | + } else { |
|
64 | + if (!$r = $container->getReflectionClass($class)) { |
|
65 | + throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); |
|
66 | + } |
|
67 | + if (!$r->isSubclassOf(Command::class)) { |
|
68 | + throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); |
|
69 | + } |
|
70 | + $aliases = $class::getDefaultName(); |
|
71 | + } |
|
72 | + |
|
73 | + $aliases = explode('|', $aliases ?? ''); |
|
74 | + $commandName = array_shift($aliases); |
|
75 | + |
|
76 | + if ($isHidden = '' === $commandName) { |
|
77 | + $commandName = array_shift($aliases); |
|
78 | + } |
|
79 | + |
|
80 | + if (null === $commandName) { |
|
81 | + if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) { |
|
82 | + $commandId = 'console.command.public_alias.'.$id; |
|
83 | + $container->setAlias($commandId, $id)->setPublic(true); |
|
84 | + $id = $commandId; |
|
85 | + } |
|
86 | + $serviceIds[] = $id; |
|
87 | + |
|
88 | + continue; |
|
89 | + } |
|
90 | + |
|
91 | + $description = $tags[0]['description'] ?? null; |
|
92 | + |
|
93 | + unset($tags[0]); |
|
94 | + $lazyCommandMap[$commandName] = $id; |
|
95 | + $lazyCommandRefs[$id] = new TypedReference($id, $class); |
|
96 | + |
|
97 | + foreach ($aliases as $alias) { |
|
98 | + $lazyCommandMap[$alias] = $id; |
|
99 | + } |
|
100 | + |
|
101 | + foreach ($tags as $tag) { |
|
102 | + if (isset($tag['command'])) { |
|
103 | + $aliases[] = $tag['command']; |
|
104 | + $lazyCommandMap[$tag['command']] = $id; |
|
105 | + } |
|
106 | + |
|
107 | + $description = $description ?? $tag['description'] ?? null; |
|
108 | + } |
|
109 | + |
|
110 | + $definition->addMethodCall('setName', [$commandName]); |
|
111 | + |
|
112 | + if ($aliases) { |
|
113 | + $definition->addMethodCall('setAliases', [$aliases]); |
|
114 | + } |
|
115 | + |
|
116 | + if ($isHidden) { |
|
117 | + $definition->addMethodCall('setHidden', [true]); |
|
118 | + } |
|
119 | + |
|
120 | + if (!$description) { |
|
121 | + if (!$r = $container->getReflectionClass($class)) { |
|
122 | + throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); |
|
123 | + } |
|
124 | + if (!$r->isSubclassOf(Command::class)) { |
|
125 | + throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); |
|
126 | + } |
|
127 | + $description = $class::getDefaultDescription(); |
|
128 | + } |
|
129 | + |
|
130 | + if ($description) { |
|
131 | + $definition->addMethodCall('setDescription', [$description]); |
|
132 | + |
|
133 | + $container->register('.'.$id.'.lazy', LazyCommand::class) |
|
134 | + ->setArguments([$commandName, $aliases, $description, $isHidden, new ServiceClosureArgument($lazyCommandRefs[$id])]); |
|
135 | + |
|
136 | + $lazyCommandRefs[$id] = new Reference('.'.$id.'.lazy'); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + $container |
|
141 | + ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) |
|
142 | + ->setPublic(true) |
|
143 | + ->addTag($this->noPreloadTag) |
|
144 | + ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); |
|
145 | + |
|
146 | + $container->setParameter('console.command.ids', $serviceIds); |
|
147 | + } |
|
148 | 148 | } |
@@ -26,42 +26,42 @@ |
||
26 | 26 | */ |
27 | 27 | class ApplicationTester |
28 | 28 | { |
29 | - use TesterTrait; |
|
29 | + use TesterTrait; |
|
30 | 30 | |
31 | - private $application; |
|
32 | - private $input; |
|
33 | - private $statusCode; |
|
31 | + private $application; |
|
32 | + private $input; |
|
33 | + private $statusCode; |
|
34 | 34 | |
35 | - public function __construct(Application $application) |
|
36 | - { |
|
37 | - $this->application = $application; |
|
38 | - } |
|
35 | + public function __construct(Application $application) |
|
36 | + { |
|
37 | + $this->application = $application; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Executes the application. |
|
42 | - * |
|
43 | - * Available options: |
|
44 | - * |
|
45 | - * * interactive: Sets the input interactive flag |
|
46 | - * * decorated: Sets the output decorated flag |
|
47 | - * * verbosity: Sets the output verbosity flag |
|
48 | - * * capture_stderr_separately: Make output of stdOut and stdErr separately available |
|
49 | - * |
|
50 | - * @return int The command exit code |
|
51 | - */ |
|
52 | - public function run(array $input, array $options = []) |
|
53 | - { |
|
54 | - $this->input = new ArrayInput($input); |
|
55 | - if (isset($options['interactive'])) { |
|
56 | - $this->input->setInteractive($options['interactive']); |
|
57 | - } |
|
40 | + /** |
|
41 | + * Executes the application. |
|
42 | + * |
|
43 | + * Available options: |
|
44 | + * |
|
45 | + * * interactive: Sets the input interactive flag |
|
46 | + * * decorated: Sets the output decorated flag |
|
47 | + * * verbosity: Sets the output verbosity flag |
|
48 | + * * capture_stderr_separately: Make output of stdOut and stdErr separately available |
|
49 | + * |
|
50 | + * @return int The command exit code |
|
51 | + */ |
|
52 | + public function run(array $input, array $options = []) |
|
53 | + { |
|
54 | + $this->input = new ArrayInput($input); |
|
55 | + if (isset($options['interactive'])) { |
|
56 | + $this->input->setInteractive($options['interactive']); |
|
57 | + } |
|
58 | 58 | |
59 | - if ($this->inputs) { |
|
60 | - $this->input->setStream(self::createStream($this->inputs)); |
|
61 | - } |
|
59 | + if ($this->inputs) { |
|
60 | + $this->input->setStream(self::createStream($this->inputs)); |
|
61 | + } |
|
62 | 62 | |
63 | - $this->initOutput($options); |
|
63 | + $this->initOutput($options); |
|
64 | 64 | |
65 | - return $this->statusCode = $this->application->run($this->input, $this->output); |
|
66 | - } |
|
65 | + return $this->statusCode = $this->application->run($this->input, $this->output); |
|
66 | + } |
|
67 | 67 | } |
@@ -22,57 +22,57 @@ |
||
22 | 22 | */ |
23 | 23 | class CommandTester |
24 | 24 | { |
25 | - use TesterTrait; |
|
25 | + use TesterTrait; |
|
26 | 26 | |
27 | - private $command; |
|
28 | - private $input; |
|
29 | - private $statusCode; |
|
27 | + private $command; |
|
28 | + private $input; |
|
29 | + private $statusCode; |
|
30 | 30 | |
31 | - public function __construct(Command $command) |
|
32 | - { |
|
33 | - $this->command = $command; |
|
34 | - } |
|
31 | + public function __construct(Command $command) |
|
32 | + { |
|
33 | + $this->command = $command; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Executes the command. |
|
38 | - * |
|
39 | - * Available execution options: |
|
40 | - * |
|
41 | - * * interactive: Sets the input interactive flag |
|
42 | - * * decorated: Sets the output decorated flag |
|
43 | - * * verbosity: Sets the output verbosity flag |
|
44 | - * * capture_stderr_separately: Make output of stdOut and stdErr separately available |
|
45 | - * |
|
46 | - * @param array $input An array of command arguments and options |
|
47 | - * @param array $options An array of execution options |
|
48 | - * |
|
49 | - * @return int The command exit code |
|
50 | - */ |
|
51 | - public function execute(array $input, array $options = []) |
|
52 | - { |
|
53 | - // set the command name automatically if the application requires |
|
54 | - // this argument and no command name was passed |
|
55 | - if (!isset($input['command']) |
|
56 | - && (null !== $application = $this->command->getApplication()) |
|
57 | - && $application->getDefinition()->hasArgument('command') |
|
58 | - ) { |
|
59 | - $input = array_merge(['command' => $this->command->getName()], $input); |
|
60 | - } |
|
36 | + /** |
|
37 | + * Executes the command. |
|
38 | + * |
|
39 | + * Available execution options: |
|
40 | + * |
|
41 | + * * interactive: Sets the input interactive flag |
|
42 | + * * decorated: Sets the output decorated flag |
|
43 | + * * verbosity: Sets the output verbosity flag |
|
44 | + * * capture_stderr_separately: Make output of stdOut and stdErr separately available |
|
45 | + * |
|
46 | + * @param array $input An array of command arguments and options |
|
47 | + * @param array $options An array of execution options |
|
48 | + * |
|
49 | + * @return int The command exit code |
|
50 | + */ |
|
51 | + public function execute(array $input, array $options = []) |
|
52 | + { |
|
53 | + // set the command name automatically if the application requires |
|
54 | + // this argument and no command name was passed |
|
55 | + if (!isset($input['command']) |
|
56 | + && (null !== $application = $this->command->getApplication()) |
|
57 | + && $application->getDefinition()->hasArgument('command') |
|
58 | + ) { |
|
59 | + $input = array_merge(['command' => $this->command->getName()], $input); |
|
60 | + } |
|
61 | 61 | |
62 | - $this->input = new ArrayInput($input); |
|
63 | - // Use an in-memory input stream even if no inputs are set so that QuestionHelper::ask() does not rely on the blocking STDIN. |
|
64 | - $this->input->setStream(self::createStream($this->inputs)); |
|
62 | + $this->input = new ArrayInput($input); |
|
63 | + // Use an in-memory input stream even if no inputs are set so that QuestionHelper::ask() does not rely on the blocking STDIN. |
|
64 | + $this->input->setStream(self::createStream($this->inputs)); |
|
65 | 65 | |
66 | - if (isset($options['interactive'])) { |
|
67 | - $this->input->setInteractive($options['interactive']); |
|
68 | - } |
|
66 | + if (isset($options['interactive'])) { |
|
67 | + $this->input->setInteractive($options['interactive']); |
|
68 | + } |
|
69 | 69 | |
70 | - if (!isset($options['decorated'])) { |
|
71 | - $options['decorated'] = false; |
|
72 | - } |
|
70 | + if (!isset($options['decorated'])) { |
|
71 | + $options['decorated'] = false; |
|
72 | + } |
|
73 | 73 | |
74 | - $this->initOutput($options); |
|
74 | + $this->initOutput($options); |
|
75 | 75 | |
76 | - return $this->statusCode = $this->command->run($this->input, $this->output); |
|
77 | - } |
|
76 | + return $this->statusCode = $this->command->run($this->input, $this->output); |
|
77 | + } |
|
78 | 78 | } |