@@ -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 | } |
@@ -21,78 +21,78 @@ discard block |
||
21 | 21 | private $output; |
22 | 22 | private $input; |
23 | 23 | |
24 | - public function __construct(OutputInterface $output, $input = null) |
|
24 | + public function __construct( OutputInterface $output, $input = null ) |
|
25 | 25 | { |
26 | 26 | $this->output = $output; |
27 | - $this->input = $input ?? (\defined('STDIN') ? \STDIN : fopen('php://input', 'r+')); |
|
27 | + $this->input = $input ?? ( \defined( 'STDIN' ) ? \STDIN : fopen( 'php://input', 'r+' ) ); |
|
28 | 28 | } |
29 | 29 | |
30 | - public function moveUp(int $lines = 1): self |
|
30 | + public function moveUp( int $lines = 1 ): self |
|
31 | 31 | { |
32 | - $this->output->write(sprintf("\x1b[%dA", $lines)); |
|
32 | + $this->output->write( sprintf( "\x1b[%dA", $lines ) ); |
|
33 | 33 | |
34 | 34 | return $this; |
35 | 35 | } |
36 | 36 | |
37 | - public function moveDown(int $lines = 1): self |
|
37 | + public function moveDown( int $lines = 1 ): self |
|
38 | 38 | { |
39 | - $this->output->write(sprintf("\x1b[%dB", $lines)); |
|
39 | + $this->output->write( sprintf( "\x1b[%dB", $lines ) ); |
|
40 | 40 | |
41 | 41 | return $this; |
42 | 42 | } |
43 | 43 | |
44 | - public function moveRight(int $columns = 1): self |
|
44 | + public function moveRight( int $columns = 1 ): self |
|
45 | 45 | { |
46 | - $this->output->write(sprintf("\x1b[%dC", $columns)); |
|
46 | + $this->output->write( sprintf( "\x1b[%dC", $columns ) ); |
|
47 | 47 | |
48 | 48 | return $this; |
49 | 49 | } |
50 | 50 | |
51 | - public function moveLeft(int $columns = 1): self |
|
51 | + public function moveLeft( int $columns = 1 ): self |
|
52 | 52 | { |
53 | - $this->output->write(sprintf("\x1b[%dD", $columns)); |
|
53 | + $this->output->write( sprintf( "\x1b[%dD", $columns ) ); |
|
54 | 54 | |
55 | 55 | return $this; |
56 | 56 | } |
57 | 57 | |
58 | - public function moveToColumn(int $column): self |
|
58 | + public function moveToColumn( int $column ): self |
|
59 | 59 | { |
60 | - $this->output->write(sprintf("\x1b[%dG", $column)); |
|
60 | + $this->output->write( sprintf( "\x1b[%dG", $column ) ); |
|
61 | 61 | |
62 | 62 | return $this; |
63 | 63 | } |
64 | 64 | |
65 | - public function moveToPosition(int $column, int $row): self |
|
65 | + public function moveToPosition( int $column, int $row ): self |
|
66 | 66 | { |
67 | - $this->output->write(sprintf("\x1b[%d;%dH", $row + 1, $column)); |
|
67 | + $this->output->write( sprintf( "\x1b[%d;%dH", $row + 1, $column ) ); |
|
68 | 68 | |
69 | 69 | return $this; |
70 | 70 | } |
71 | 71 | |
72 | 72 | public function savePosition(): self |
73 | 73 | { |
74 | - $this->output->write("\x1b7"); |
|
74 | + $this->output->write( "\x1b7" ); |
|
75 | 75 | |
76 | 76 | return $this; |
77 | 77 | } |
78 | 78 | |
79 | 79 | public function restorePosition(): self |
80 | 80 | { |
81 | - $this->output->write("\x1b8"); |
|
81 | + $this->output->write( "\x1b8" ); |
|
82 | 82 | |
83 | 83 | return $this; |
84 | 84 | } |
85 | 85 | |
86 | 86 | public function hide(): self |
87 | 87 | { |
88 | - $this->output->write("\x1b[?25l"); |
|
88 | + $this->output->write( "\x1b[?25l" ); |
|
89 | 89 | |
90 | 90 | return $this; |
91 | 91 | } |
92 | 92 | |
93 | 93 | public function show(): self |
94 | 94 | { |
95 | - $this->output->write("\x1b[?25h\x1b[?0c"); |
|
95 | + $this->output->write( "\x1b[?25h\x1b[?0c" ); |
|
96 | 96 | |
97 | 97 | return $this; |
98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function clearLine(): self |
104 | 104 | { |
105 | - $this->output->write("\x1b[2K"); |
|
105 | + $this->output->write( "\x1b[2K" ); |
|
106 | 106 | |
107 | 107 | return $this; |
108 | 108 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function clearLineAfter(): self |
114 | 114 | { |
115 | - $this->output->write("\x1b[K"); |
|
115 | + $this->output->write( "\x1b[K" ); |
|
116 | 116 | |
117 | 117 | return $this; |
118 | 118 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function clearOutput(): self |
124 | 124 | { |
125 | - $this->output->write("\x1b[0J"); |
|
125 | + $this->output->write( "\x1b[0J" ); |
|
126 | 126 | |
127 | 127 | return $this; |
128 | 128 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function clearScreen(): self |
134 | 134 | { |
135 | - $this->output->write("\x1b[2J"); |
|
135 | + $this->output->write( "\x1b[2J" ); |
|
136 | 136 | |
137 | 137 | return $this; |
138 | 138 | } |
@@ -144,25 +144,25 @@ discard block |
||
144 | 144 | { |
145 | 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); |
|
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 | 149 | } |
150 | 150 | |
151 | - if (!$isTtySupported) { |
|
152 | - return [1, 1]; |
|
151 | + if ( ! $isTtySupported ) { |
|
152 | + return [ 1, 1 ]; |
|
153 | 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]; |
|
166 | + return [ $col, $row ]; |
|
167 | 167 | } |
168 | 168 | } |
@@ -16,13 +16,11 @@ |
||
16 | 16 | /** |
17 | 17 | * @author Pierre du Plessis <[email protected]> |
18 | 18 | */ |
19 | -final class Cursor |
|
20 | -{ |
|
19 | +final class Cursor { |
|
21 | 20 | private $output; |
22 | 21 | private $input; |
23 | 22 | |
24 | - public function __construct(OutputInterface $output, $input = null) |
|
25 | - { |
|
23 | + public function __construct(OutputInterface $output, $input = null) { |
|
26 | 24 | $this->output = $output; |
27 | 25 | $this->input = $input ?? (\defined('STDIN') ? \STDIN : fopen('php://input', 'r+')); |
28 | 26 | } |
@@ -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 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | * |
22 | 22 | * @author Francesco Levorato <[email protected]> |
23 | 23 | */ |
24 | -final class ConsoleEvents |
|
25 | -{ |
|
24 | +final class ConsoleEvents { |
|
26 | 25 | /** |
27 | 26 | * The COMMAND event allows you to attach listeners before any command is |
28 | 27 | * executed by the console. It also allows you to modify the command, input and output |
@@ -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 | } |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | private $noPreloadTag; |
35 | 35 | private $privateTagName; |
36 | 36 | |
37 | - public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private') |
|
37 | + public function __construct( string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private' ) |
|
38 | 38 | { |
39 | - if (0 < \func_num_args()) { |
|
40 | - trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); |
|
39 | + if ( 0 < \func_num_args() ) { |
|
40 | + trigger_deprecation( 'symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__ ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | $this->commandLoaderServiceId = $commandLoaderServiceId; |
@@ -46,103 +46,103 @@ discard block |
||
46 | 46 | $this->privateTagName = $privateTagName; |
47 | 47 | } |
48 | 48 | |
49 | - public function process(ContainerBuilder $container) |
|
49 | + public function process( ContainerBuilder $container ) |
|
50 | 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']; |
|
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 | 63 | } else { |
64 | - if (!$r = $container->getReflectionClass($class)) { |
|
65 | - throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); |
|
64 | + if ( ! $r = $container->getReflectionClass( $class ) ) { |
|
65 | + throw new InvalidArgumentException( sprintf( 'Class "%s" used for service "%s" cannot be found.', $class, $id ) ); |
|
66 | 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)); |
|
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 | 69 | } |
70 | 70 | $aliases = $class::getDefaultName(); |
71 | 71 | } |
72 | 72 | |
73 | - $aliases = explode('|', $aliases ?? ''); |
|
74 | - $commandName = array_shift($aliases); |
|
73 | + $aliases = explode( '|', $aliases ?? '' ); |
|
74 | + $commandName = array_shift( $aliases ); |
|
75 | 75 | |
76 | - if ($isHidden = '' === $commandName) { |
|
77 | - $commandName = array_shift($aliases); |
|
76 | + if ( $isHidden = '' === $commandName ) { |
|
77 | + $commandName = array_shift( $aliases ); |
|
78 | 78 | } |
79 | 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); |
|
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 | 84 | $id = $commandId; |
85 | 85 | } |
86 | - $serviceIds[] = $id; |
|
86 | + $serviceIds[ ] = $id; |
|
87 | 87 | |
88 | 88 | continue; |
89 | 89 | } |
90 | 90 | |
91 | - $description = $tags[0]['description'] ?? null; |
|
91 | + $description = $tags[ 0 ][ 'description' ] ?? null; |
|
92 | 92 | |
93 | - unset($tags[0]); |
|
94 | - $lazyCommandMap[$commandName] = $id; |
|
95 | - $lazyCommandRefs[$id] = new TypedReference($id, $class); |
|
93 | + unset( $tags[ 0 ] ); |
|
94 | + $lazyCommandMap[ $commandName ] = $id; |
|
95 | + $lazyCommandRefs[ $id ] = new TypedReference( $id, $class ); |
|
96 | 96 | |
97 | - foreach ($aliases as $alias) { |
|
98 | - $lazyCommandMap[$alias] = $id; |
|
97 | + foreach ( $aliases as $alias ) { |
|
98 | + $lazyCommandMap[ $alias ] = $id; |
|
99 | 99 | } |
100 | 100 | |
101 | - foreach ($tags as $tag) { |
|
102 | - if (isset($tag['command'])) { |
|
103 | - $aliases[] = $tag['command']; |
|
104 | - $lazyCommandMap[$tag['command']] = $id; |
|
101 | + foreach ( $tags as $tag ) { |
|
102 | + if ( isset( $tag[ 'command' ] ) ) { |
|
103 | + $aliases[ ] = $tag[ 'command' ]; |
|
104 | + $lazyCommandMap[ $tag[ 'command' ] ] = $id; |
|
105 | 105 | } |
106 | 106 | |
107 | - $description = $description ?? $tag['description'] ?? null; |
|
107 | + $description = $description ?? $tag[ 'description' ] ?? null; |
|
108 | 108 | } |
109 | 109 | |
110 | - $definition->addMethodCall('setName', [$commandName]); |
|
110 | + $definition->addMethodCall( 'setName', [ $commandName ] ); |
|
111 | 111 | |
112 | - if ($aliases) { |
|
113 | - $definition->addMethodCall('setAliases', [$aliases]); |
|
112 | + if ( $aliases ) { |
|
113 | + $definition->addMethodCall( 'setAliases', [ $aliases ] ); |
|
114 | 114 | } |
115 | 115 | |
116 | - if ($isHidden) { |
|
117 | - $definition->addMethodCall('setHidden', [true]); |
|
116 | + if ( $isHidden ) { |
|
117 | + $definition->addMethodCall( 'setHidden', [ true ] ); |
|
118 | 118 | } |
119 | 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)); |
|
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 | 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)); |
|
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 | 126 | } |
127 | 127 | $description = $class::getDefaultDescription(); |
128 | 128 | } |
129 | 129 | |
130 | - if ($description) { |
|
131 | - $definition->addMethodCall('setDescription', [$description]); |
|
130 | + if ( $description ) { |
|
131 | + $definition->addMethodCall( 'setDescription', [ $description ] ); |
|
132 | 132 | |
133 | - $container->register('.'.$id.'.lazy', LazyCommand::class) |
|
134 | - ->setArguments([$commandName, $aliases, $description, $isHidden, new ServiceClosureArgument($lazyCommandRefs[$id])]); |
|
133 | + $container->register( '.' . $id . '.lazy', LazyCommand::class ) |
|
134 | + ->setArguments( [ $commandName, $aliases, $description, $isHidden, new ServiceClosureArgument( $lazyCommandRefs[ $id ] ) ] ); |
|
135 | 135 | |
136 | - $lazyCommandRefs[$id] = new Reference('.'.$id.'.lazy'); |
|
136 | + $lazyCommandRefs[ $id ] = new Reference( '.' . $id . '.lazy' ); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | 140 | $container |
141 | - ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) |
|
142 | - ->setPublic(true) |
|
143 | - ->addTag($this->noPreloadTag) |
|
144 | - ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); |
|
141 | + ->register( $this->commandLoaderServiceId, ContainerCommandLoader::class ) |
|
142 | + ->setPublic( true ) |
|
143 | + ->addTag( $this->noPreloadTag ) |
|
144 | + ->setArguments( [ ServiceLocatorTagPass::register( $container, $lazyCommandRefs ), $lazyCommandMap ] ); |
|
145 | 145 | |
146 | - $container->setParameter('console.command.ids', $serviceIds); |
|
146 | + $container->setParameter( 'console.command.ids', $serviceIds ); |
|
147 | 147 | } |
148 | 148 | } |
@@ -27,15 +27,13 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @author Grégoire Pineau <[email protected]> |
29 | 29 | */ |
30 | -class AddConsoleCommandPass implements CompilerPassInterface |
|
31 | -{ |
|
30 | +class AddConsoleCommandPass implements CompilerPassInterface { |
|
32 | 31 | private $commandLoaderServiceId; |
33 | 32 | private $commandTag; |
34 | 33 | private $noPreloadTag; |
35 | 34 | private $privateTagName; |
36 | 35 | |
37 | - public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private') |
|
38 | - { |
|
36 | + public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private') { |
|
39 | 37 | if (0 < \func_num_args()) { |
40 | 38 | trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); |
41 | 39 | } |
@@ -46,8 +44,7 @@ discard block |
||
46 | 44 | $this->privateTagName = $privateTagName; |
47 | 45 | } |
48 | 46 | |
49 | - public function process(ContainerBuilder $container) |
|
50 | - { |
|
47 | + public function process(ContainerBuilder $container) { |
|
51 | 48 | $commandServices = $container->findTaggedServiceIds($this->commandTag, true); |
52 | 49 | $lazyCommandMap = []; |
53 | 50 | $lazyCommandRefs = []; |
@@ -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 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | private $input; |
33 | 33 | private $statusCode; |
34 | 34 | |
35 | - public function __construct(Application $application) |
|
35 | + public function __construct( Application $application ) |
|
36 | 36 | { |
37 | 37 | $this->application = $application; |
38 | 38 | } |
@@ -49,19 +49,19 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @return int The command exit code |
51 | 51 | */ |
52 | - public function run(array $input, array $options = []) |
|
52 | + public function run( array $input, array $options = [ ] ) |
|
53 | 53 | { |
54 | - $this->input = new ArrayInput($input); |
|
55 | - if (isset($options['interactive'])) { |
|
56 | - $this->input->setInteractive($options['interactive']); |
|
54 | + $this->input = new ArrayInput( $input ); |
|
55 | + if ( isset( $options[ 'interactive' ] ) ) { |
|
56 | + $this->input->setInteractive( $options[ 'interactive' ] ); |
|
57 | 57 | } |
58 | 58 | |
59 | - if ($this->inputs) { |
|
60 | - $this->input->setStream(self::createStream($this->inputs)); |
|
59 | + if ( $this->inputs ) { |
|
60 | + $this->input->setStream( self::createStream( $this->inputs ) ); |
|
61 | 61 | } |
62 | 62 | |
63 | - $this->initOutput($options); |
|
63 | + $this->initOutput( $options ); |
|
64 | 64 | |
65 | - return $this->statusCode = $this->application->run($this->input, $this->output); |
|
65 | + return $this->statusCode = $this->application->run( $this->input, $this->output ); |
|
66 | 66 | } |
67 | 67 | } |
@@ -24,16 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @author Fabien Potencier <[email protected]> |
26 | 26 | */ |
27 | -class ApplicationTester |
|
28 | -{ |
|
27 | +class ApplicationTester { |
|
29 | 28 | use TesterTrait; |
30 | 29 | |
31 | 30 | private $application; |
32 | 31 | private $input; |
33 | 32 | private $statusCode; |
34 | 33 | |
35 | - public function __construct(Application $application) |
|
36 | - { |
|
34 | + public function __construct(Application $application) { |
|
37 | 35 | $this->application = $application; |
38 | 36 | } |
39 | 37 | |
@@ -49,8 +47,7 @@ discard block |
||
49 | 47 | * |
50 | 48 | * @return int The command exit code |
51 | 49 | */ |
52 | - public function run(array $input, array $options = []) |
|
53 | - { |
|
50 | + public function run(array $input, array $options = []) { |
|
54 | 51 | $this->input = new ArrayInput($input); |
55 | 52 | if (isset($options['interactive'])) { |
56 | 53 | $this->input->setInteractive($options['interactive']); |
@@ -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 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | private $input; |
29 | 29 | private $statusCode; |
30 | 30 | |
31 | - public function __construct(Command $command) |
|
31 | + public function __construct( Command $command ) |
|
32 | 32 | { |
33 | 33 | $this->command = $command; |
34 | 34 | } |
@@ -48,31 +48,31 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return int The command exit code |
50 | 50 | */ |
51 | - public function execute(array $input, array $options = []) |
|
51 | + public function execute( array $input, array $options = [ ] ) |
|
52 | 52 | { |
53 | 53 | // set the command name automatically if the application requires |
54 | 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') |
|
55 | + if ( ! isset( $input[ 'command' ] ) |
|
56 | + && ( null !== $application = $this->command->getApplication() ) |
|
57 | + && $application->getDefinition()->hasArgument( 'command' ) |
|
58 | 58 | ) { |
59 | - $input = array_merge(['command' => $this->command->getName()], $input); |
|
59 | + $input = array_merge( [ 'command' => $this->command->getName() ], $input ); |
|
60 | 60 | } |
61 | 61 | |
62 | - $this->input = new ArrayInput($input); |
|
62 | + $this->input = new ArrayInput( $input ); |
|
63 | 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)); |
|
64 | + $this->input->setStream( self::createStream( $this->inputs ) ); |
|
65 | 65 | |
66 | - if (isset($options['interactive'])) { |
|
67 | - $this->input->setInteractive($options['interactive']); |
|
66 | + if ( isset( $options[ 'interactive' ] ) ) { |
|
67 | + $this->input->setInteractive( $options[ 'interactive' ] ); |
|
68 | 68 | } |
69 | 69 | |
70 | - if (!isset($options['decorated'])) { |
|
71 | - $options['decorated'] = false; |
|
70 | + if ( ! isset( $options[ 'decorated' ] ) ) { |
|
71 | + $options[ 'decorated' ] = false; |
|
72 | 72 | } |
73 | 73 | |
74 | - $this->initOutput($options); |
|
74 | + $this->initOutput( $options ); |
|
75 | 75 | |
76 | - return $this->statusCode = $this->command->run($this->input, $this->output); |
|
76 | + return $this->statusCode = $this->command->run( $this->input, $this->output ); |
|
77 | 77 | } |
78 | 78 | } |
@@ -20,16 +20,14 @@ discard block |
||
20 | 20 | * @author Fabien Potencier <[email protected]> |
21 | 21 | * @author Robin Chalas <[email protected]> |
22 | 22 | */ |
23 | -class CommandTester |
|
24 | -{ |
|
23 | +class CommandTester { |
|
25 | 24 | use TesterTrait; |
26 | 25 | |
27 | 26 | private $command; |
28 | 27 | private $input; |
29 | 28 | private $statusCode; |
30 | 29 | |
31 | - public function __construct(Command $command) |
|
32 | - { |
|
30 | + public function __construct(Command $command) { |
|
33 | 31 | $this->command = $command; |
34 | 32 | } |
35 | 33 | |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @return int The command exit code |
50 | 48 | */ |
51 | - public function execute(array $input, array $options = []) |
|
52 | - { |
|
49 | + public function execute(array $input, array $options = []) { |
|
53 | 50 | // set the command name automatically if the application requires |
54 | 51 | // this argument and no command name was passed |
55 | 52 | if (!isset($input['command']) |
@@ -21,166 +21,166 @@ |
||
21 | 21 | */ |
22 | 22 | trait TesterTrait |
23 | 23 | { |
24 | - /** @var StreamOutput */ |
|
25 | - private $output; |
|
26 | - private $inputs = []; |
|
27 | - private $captureStreamsIndependently = false; |
|
28 | - |
|
29 | - /** |
|
30 | - * Gets the display returned by the last execution of the command or application. |
|
31 | - * |
|
32 | - * @throws \RuntimeException If it's called before the execute method |
|
33 | - * |
|
34 | - * @return string The display |
|
35 | - */ |
|
36 | - public function getDisplay(bool $normalize = false) |
|
37 | - { |
|
38 | - if (null === $this->output) { |
|
39 | - throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?'); |
|
40 | - } |
|
41 | - |
|
42 | - rewind($this->output->getStream()); |
|
43 | - |
|
44 | - $display = stream_get_contents($this->output->getStream()); |
|
45 | - |
|
46 | - if ($normalize) { |
|
47 | - $display = str_replace(\PHP_EOL, "\n", $display); |
|
48 | - } |
|
49 | - |
|
50 | - return $display; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Gets the output written to STDERR by the application. |
|
55 | - * |
|
56 | - * @param bool $normalize Whether to normalize end of lines to \n or not |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getErrorOutput(bool $normalize = false) |
|
61 | - { |
|
62 | - if (!$this->captureStreamsIndependently) { |
|
63 | - throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.'); |
|
64 | - } |
|
65 | - |
|
66 | - rewind($this->output->getErrorOutput()->getStream()); |
|
67 | - |
|
68 | - $display = stream_get_contents($this->output->getErrorOutput()->getStream()); |
|
69 | - |
|
70 | - if ($normalize) { |
|
71 | - $display = str_replace(\PHP_EOL, "\n", $display); |
|
72 | - } |
|
73 | - |
|
74 | - return $display; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Gets the input instance used by the last execution of the command or application. |
|
79 | - * |
|
80 | - * @return InputInterface The current input instance |
|
81 | - */ |
|
82 | - public function getInput() |
|
83 | - { |
|
84 | - return $this->input; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Gets the output instance used by the last execution of the command or application. |
|
89 | - * |
|
90 | - * @return OutputInterface The current output instance |
|
91 | - */ |
|
92 | - public function getOutput() |
|
93 | - { |
|
94 | - return $this->output; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Gets the status code returned by the last execution of the command or application. |
|
99 | - * |
|
100 | - * @throws \RuntimeException If it's called before the execute method |
|
101 | - * |
|
102 | - * @return int The status code |
|
103 | - */ |
|
104 | - public function getStatusCode() |
|
105 | - { |
|
106 | - if (null === $this->statusCode) { |
|
107 | - throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?'); |
|
108 | - } |
|
109 | - |
|
110 | - return $this->statusCode; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Sets the user inputs. |
|
115 | - * |
|
116 | - * @param array $inputs An array of strings representing each input |
|
117 | - * passed to the command input stream |
|
118 | - * |
|
119 | - * @return $this |
|
120 | - */ |
|
121 | - public function setInputs(array $inputs) |
|
122 | - { |
|
123 | - $this->inputs = $inputs; |
|
124 | - |
|
125 | - return $this; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Initializes the output property. |
|
130 | - * |
|
131 | - * Available options: |
|
132 | - * |
|
133 | - * * decorated: Sets the output decorated flag |
|
134 | - * * verbosity: Sets the output verbosity flag |
|
135 | - * * capture_stderr_separately: Make output of stdOut and stdErr separately available |
|
136 | - */ |
|
137 | - private function initOutput(array $options) |
|
138 | - { |
|
139 | - $this->captureStreamsIndependently = \array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately']; |
|
140 | - if (!$this->captureStreamsIndependently) { |
|
141 | - $this->output = new StreamOutput(fopen('php://memory', 'w', false)); |
|
142 | - if (isset($options['decorated'])) { |
|
143 | - $this->output->setDecorated($options['decorated']); |
|
144 | - } |
|
145 | - if (isset($options['verbosity'])) { |
|
146 | - $this->output->setVerbosity($options['verbosity']); |
|
147 | - } |
|
148 | - } else { |
|
149 | - $this->output = new ConsoleOutput( |
|
150 | - $options['verbosity'] ?? ConsoleOutput::VERBOSITY_NORMAL, |
|
151 | - $options['decorated'] ?? null |
|
152 | - ); |
|
153 | - |
|
154 | - $errorOutput = new StreamOutput(fopen('php://memory', 'w', false)); |
|
155 | - $errorOutput->setFormatter($this->output->getFormatter()); |
|
156 | - $errorOutput->setVerbosity($this->output->getVerbosity()); |
|
157 | - $errorOutput->setDecorated($this->output->isDecorated()); |
|
158 | - |
|
159 | - $reflectedOutput = new \ReflectionObject($this->output); |
|
160 | - $strErrProperty = $reflectedOutput->getProperty('stderr'); |
|
161 | - $strErrProperty->setAccessible(true); |
|
162 | - $strErrProperty->setValue($this->output, $errorOutput); |
|
163 | - |
|
164 | - $reflectedParent = $reflectedOutput->getParentClass(); |
|
165 | - $streamProperty = $reflectedParent->getProperty('stream'); |
|
166 | - $streamProperty->setAccessible(true); |
|
167 | - $streamProperty->setValue($this->output, fopen('php://memory', 'w', false)); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @return resource |
|
173 | - */ |
|
174 | - private static function createStream(array $inputs) |
|
175 | - { |
|
176 | - $stream = fopen('php://memory', 'r+', false); |
|
177 | - |
|
178 | - foreach ($inputs as $input) { |
|
179 | - fwrite($stream, $input.\PHP_EOL); |
|
180 | - } |
|
181 | - |
|
182 | - rewind($stream); |
|
183 | - |
|
184 | - return $stream; |
|
185 | - } |
|
24 | + /** @var StreamOutput */ |
|
25 | + private $output; |
|
26 | + private $inputs = []; |
|
27 | + private $captureStreamsIndependently = false; |
|
28 | + |
|
29 | + /** |
|
30 | + * Gets the display returned by the last execution of the command or application. |
|
31 | + * |
|
32 | + * @throws \RuntimeException If it's called before the execute method |
|
33 | + * |
|
34 | + * @return string The display |
|
35 | + */ |
|
36 | + public function getDisplay(bool $normalize = false) |
|
37 | + { |
|
38 | + if (null === $this->output) { |
|
39 | + throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?'); |
|
40 | + } |
|
41 | + |
|
42 | + rewind($this->output->getStream()); |
|
43 | + |
|
44 | + $display = stream_get_contents($this->output->getStream()); |
|
45 | + |
|
46 | + if ($normalize) { |
|
47 | + $display = str_replace(\PHP_EOL, "\n", $display); |
|
48 | + } |
|
49 | + |
|
50 | + return $display; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Gets the output written to STDERR by the application. |
|
55 | + * |
|
56 | + * @param bool $normalize Whether to normalize end of lines to \n or not |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getErrorOutput(bool $normalize = false) |
|
61 | + { |
|
62 | + if (!$this->captureStreamsIndependently) { |
|
63 | + throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.'); |
|
64 | + } |
|
65 | + |
|
66 | + rewind($this->output->getErrorOutput()->getStream()); |
|
67 | + |
|
68 | + $display = stream_get_contents($this->output->getErrorOutput()->getStream()); |
|
69 | + |
|
70 | + if ($normalize) { |
|
71 | + $display = str_replace(\PHP_EOL, "\n", $display); |
|
72 | + } |
|
73 | + |
|
74 | + return $display; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Gets the input instance used by the last execution of the command or application. |
|
79 | + * |
|
80 | + * @return InputInterface The current input instance |
|
81 | + */ |
|
82 | + public function getInput() |
|
83 | + { |
|
84 | + return $this->input; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Gets the output instance used by the last execution of the command or application. |
|
89 | + * |
|
90 | + * @return OutputInterface The current output instance |
|
91 | + */ |
|
92 | + public function getOutput() |
|
93 | + { |
|
94 | + return $this->output; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Gets the status code returned by the last execution of the command or application. |
|
99 | + * |
|
100 | + * @throws \RuntimeException If it's called before the execute method |
|
101 | + * |
|
102 | + * @return int The status code |
|
103 | + */ |
|
104 | + public function getStatusCode() |
|
105 | + { |
|
106 | + if (null === $this->statusCode) { |
|
107 | + throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?'); |
|
108 | + } |
|
109 | + |
|
110 | + return $this->statusCode; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Sets the user inputs. |
|
115 | + * |
|
116 | + * @param array $inputs An array of strings representing each input |
|
117 | + * passed to the command input stream |
|
118 | + * |
|
119 | + * @return $this |
|
120 | + */ |
|
121 | + public function setInputs(array $inputs) |
|
122 | + { |
|
123 | + $this->inputs = $inputs; |
|
124 | + |
|
125 | + return $this; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Initializes the output property. |
|
130 | + * |
|
131 | + * Available options: |
|
132 | + * |
|
133 | + * * decorated: Sets the output decorated flag |
|
134 | + * * verbosity: Sets the output verbosity flag |
|
135 | + * * capture_stderr_separately: Make output of stdOut and stdErr separately available |
|
136 | + */ |
|
137 | + private function initOutput(array $options) |
|
138 | + { |
|
139 | + $this->captureStreamsIndependently = \array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately']; |
|
140 | + if (!$this->captureStreamsIndependently) { |
|
141 | + $this->output = new StreamOutput(fopen('php://memory', 'w', false)); |
|
142 | + if (isset($options['decorated'])) { |
|
143 | + $this->output->setDecorated($options['decorated']); |
|
144 | + } |
|
145 | + if (isset($options['verbosity'])) { |
|
146 | + $this->output->setVerbosity($options['verbosity']); |
|
147 | + } |
|
148 | + } else { |
|
149 | + $this->output = new ConsoleOutput( |
|
150 | + $options['verbosity'] ?? ConsoleOutput::VERBOSITY_NORMAL, |
|
151 | + $options['decorated'] ?? null |
|
152 | + ); |
|
153 | + |
|
154 | + $errorOutput = new StreamOutput(fopen('php://memory', 'w', false)); |
|
155 | + $errorOutput->setFormatter($this->output->getFormatter()); |
|
156 | + $errorOutput->setVerbosity($this->output->getVerbosity()); |
|
157 | + $errorOutput->setDecorated($this->output->isDecorated()); |
|
158 | + |
|
159 | + $reflectedOutput = new \ReflectionObject($this->output); |
|
160 | + $strErrProperty = $reflectedOutput->getProperty('stderr'); |
|
161 | + $strErrProperty->setAccessible(true); |
|
162 | + $strErrProperty->setValue($this->output, $errorOutput); |
|
163 | + |
|
164 | + $reflectedParent = $reflectedOutput->getParentClass(); |
|
165 | + $streamProperty = $reflectedParent->getProperty('stream'); |
|
166 | + $streamProperty->setAccessible(true); |
|
167 | + $streamProperty->setValue($this->output, fopen('php://memory', 'w', false)); |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @return resource |
|
173 | + */ |
|
174 | + private static function createStream(array $inputs) |
|
175 | + { |
|
176 | + $stream = fopen('php://memory', 'r+', false); |
|
177 | + |
|
178 | + foreach ($inputs as $input) { |
|
179 | + fwrite($stream, $input.\PHP_EOL); |
|
180 | + } |
|
181 | + |
|
182 | + rewind($stream); |
|
183 | + |
|
184 | + return $stream; |
|
185 | + } |
|
186 | 186 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | { |
24 | 24 | /** @var StreamOutput */ |
25 | 25 | private $output; |
26 | - private $inputs = []; |
|
26 | + private $inputs = [ ]; |
|
27 | 27 | private $captureStreamsIndependently = false; |
28 | 28 | |
29 | 29 | /** |
@@ -33,18 +33,18 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return string The display |
35 | 35 | */ |
36 | - public function getDisplay(bool $normalize = false) |
|
36 | + public function getDisplay( bool $normalize = false ) |
|
37 | 37 | { |
38 | - if (null === $this->output) { |
|
39 | - throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?'); |
|
38 | + if ( null === $this->output ) { |
|
39 | + throw new \RuntimeException( 'Output not initialized, did you execute the command before requesting the display?' ); |
|
40 | 40 | } |
41 | 41 | |
42 | - rewind($this->output->getStream()); |
|
42 | + rewind( $this->output->getStream() ); |
|
43 | 43 | |
44 | - $display = stream_get_contents($this->output->getStream()); |
|
44 | + $display = stream_get_contents( $this->output->getStream() ); |
|
45 | 45 | |
46 | - if ($normalize) { |
|
47 | - $display = str_replace(\PHP_EOL, "\n", $display); |
|
46 | + if ( $normalize ) { |
|
47 | + $display = str_replace( \PHP_EOL, "\n", $display ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | return $display; |
@@ -57,18 +57,18 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return string |
59 | 59 | */ |
60 | - public function getErrorOutput(bool $normalize = false) |
|
60 | + public function getErrorOutput( bool $normalize = false ) |
|
61 | 61 | { |
62 | - if (!$this->captureStreamsIndependently) { |
|
63 | - throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.'); |
|
62 | + if ( ! $this->captureStreamsIndependently ) { |
|
63 | + throw new \LogicException( 'The error output is not available when the tester is run without "capture_stderr_separately" option set.' ); |
|
64 | 64 | } |
65 | 65 | |
66 | - rewind($this->output->getErrorOutput()->getStream()); |
|
66 | + rewind( $this->output->getErrorOutput()->getStream() ); |
|
67 | 67 | |
68 | - $display = stream_get_contents($this->output->getErrorOutput()->getStream()); |
|
68 | + $display = stream_get_contents( $this->output->getErrorOutput()->getStream() ); |
|
69 | 69 | |
70 | - if ($normalize) { |
|
71 | - $display = str_replace(\PHP_EOL, "\n", $display); |
|
70 | + if ( $normalize ) { |
|
71 | + $display = str_replace( \PHP_EOL, "\n", $display ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | return $display; |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getStatusCode() |
105 | 105 | { |
106 | - if (null === $this->statusCode) { |
|
107 | - throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?'); |
|
106 | + if ( null === $this->statusCode ) { |
|
107 | + throw new \RuntimeException( 'Status code not initialized, did you execute the command before requesting the status code?' ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | return $this->statusCode; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return $this |
120 | 120 | */ |
121 | - public function setInputs(array $inputs) |
|
121 | + public function setInputs( array $inputs ) |
|
122 | 122 | { |
123 | 123 | $this->inputs = $inputs; |
124 | 124 | |
@@ -134,52 +134,52 @@ discard block |
||
134 | 134 | * * verbosity: Sets the output verbosity flag |
135 | 135 | * * capture_stderr_separately: Make output of stdOut and stdErr separately available |
136 | 136 | */ |
137 | - private function initOutput(array $options) |
|
137 | + private function initOutput( array $options ) |
|
138 | 138 | { |
139 | - $this->captureStreamsIndependently = \array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately']; |
|
140 | - if (!$this->captureStreamsIndependently) { |
|
141 | - $this->output = new StreamOutput(fopen('php://memory', 'w', false)); |
|
142 | - if (isset($options['decorated'])) { |
|
143 | - $this->output->setDecorated($options['decorated']); |
|
139 | + $this->captureStreamsIndependently = \array_key_exists( 'capture_stderr_separately', $options ) && $options[ 'capture_stderr_separately' ]; |
|
140 | + if ( ! $this->captureStreamsIndependently ) { |
|
141 | + $this->output = new StreamOutput( fopen( 'php://memory', 'w', false ) ); |
|
142 | + if ( isset( $options[ 'decorated' ] ) ) { |
|
143 | + $this->output->setDecorated( $options[ 'decorated' ] ); |
|
144 | 144 | } |
145 | - if (isset($options['verbosity'])) { |
|
146 | - $this->output->setVerbosity($options['verbosity']); |
|
145 | + if ( isset( $options[ 'verbosity' ] ) ) { |
|
146 | + $this->output->setVerbosity( $options[ 'verbosity' ] ); |
|
147 | 147 | } |
148 | 148 | } else { |
149 | 149 | $this->output = new ConsoleOutput( |
150 | - $options['verbosity'] ?? ConsoleOutput::VERBOSITY_NORMAL, |
|
151 | - $options['decorated'] ?? null |
|
150 | + $options[ 'verbosity' ] ?? ConsoleOutput::VERBOSITY_NORMAL, |
|
151 | + $options[ 'decorated' ] ?? null |
|
152 | 152 | ); |
153 | 153 | |
154 | - $errorOutput = new StreamOutput(fopen('php://memory', 'w', false)); |
|
155 | - $errorOutput->setFormatter($this->output->getFormatter()); |
|
156 | - $errorOutput->setVerbosity($this->output->getVerbosity()); |
|
157 | - $errorOutput->setDecorated($this->output->isDecorated()); |
|
154 | + $errorOutput = new StreamOutput( fopen( 'php://memory', 'w', false ) ); |
|
155 | + $errorOutput->setFormatter( $this->output->getFormatter() ); |
|
156 | + $errorOutput->setVerbosity( $this->output->getVerbosity() ); |
|
157 | + $errorOutput->setDecorated( $this->output->isDecorated() ); |
|
158 | 158 | |
159 | - $reflectedOutput = new \ReflectionObject($this->output); |
|
160 | - $strErrProperty = $reflectedOutput->getProperty('stderr'); |
|
161 | - $strErrProperty->setAccessible(true); |
|
162 | - $strErrProperty->setValue($this->output, $errorOutput); |
|
159 | + $reflectedOutput = new \ReflectionObject( $this->output ); |
|
160 | + $strErrProperty = $reflectedOutput->getProperty( 'stderr' ); |
|
161 | + $strErrProperty->setAccessible( true ); |
|
162 | + $strErrProperty->setValue( $this->output, $errorOutput ); |
|
163 | 163 | |
164 | 164 | $reflectedParent = $reflectedOutput->getParentClass(); |
165 | - $streamProperty = $reflectedParent->getProperty('stream'); |
|
166 | - $streamProperty->setAccessible(true); |
|
167 | - $streamProperty->setValue($this->output, fopen('php://memory', 'w', false)); |
|
165 | + $streamProperty = $reflectedParent->getProperty( 'stream' ); |
|
166 | + $streamProperty->setAccessible( true ); |
|
167 | + $streamProperty->setValue( $this->output, fopen( 'php://memory', 'w', false ) ); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | 172 | * @return resource |
173 | 173 | */ |
174 | - private static function createStream(array $inputs) |
|
174 | + private static function createStream( array $inputs ) |
|
175 | 175 | { |
176 | - $stream = fopen('php://memory', 'r+', false); |
|
176 | + $stream = fopen( 'php://memory', 'r+', false ); |
|
177 | 177 | |
178 | - foreach ($inputs as $input) { |
|
179 | - fwrite($stream, $input.\PHP_EOL); |
|
178 | + foreach ( $inputs as $input ) { |
|
179 | + fwrite( $stream, $input . \PHP_EOL ); |
|
180 | 180 | } |
181 | 181 | |
182 | - rewind($stream); |
|
182 | + rewind( $stream ); |
|
183 | 183 | |
184 | 184 | return $stream; |
185 | 185 | } |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @author Amrouche Hamza <[email protected]> |
21 | 21 | */ |
22 | -trait TesterTrait |
|
23 | -{ |
|
22 | +trait TesterTrait { |
|
24 | 23 | /** @var StreamOutput */ |
25 | 24 | private $output; |
26 | 25 | private $inputs = []; |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | * |
34 | 33 | * @return string The display |
35 | 34 | */ |
36 | - public function getDisplay(bool $normalize = false) |
|
37 | - { |
|
35 | + public function getDisplay(bool $normalize = false) { |
|
38 | 36 | if (null === $this->output) { |
39 | 37 | throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?'); |
40 | 38 | } |
@@ -57,8 +55,7 @@ discard block |
||
57 | 55 | * |
58 | 56 | * @return string |
59 | 57 | */ |
60 | - public function getErrorOutput(bool $normalize = false) |
|
61 | - { |
|
58 | + public function getErrorOutput(bool $normalize = false) { |
|
62 | 59 | if (!$this->captureStreamsIndependently) { |
63 | 60 | throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.'); |
64 | 61 | } |
@@ -79,8 +76,7 @@ discard block |
||
79 | 76 | * |
80 | 77 | * @return InputInterface The current input instance |
81 | 78 | */ |
82 | - public function getInput() |
|
83 | - { |
|
79 | + public function getInput() { |
|
84 | 80 | return $this->input; |
85 | 81 | } |
86 | 82 | |
@@ -89,8 +85,7 @@ discard block |
||
89 | 85 | * |
90 | 86 | * @return OutputInterface The current output instance |
91 | 87 | */ |
92 | - public function getOutput() |
|
93 | - { |
|
88 | + public function getOutput() { |
|
94 | 89 | return $this->output; |
95 | 90 | } |
96 | 91 | |
@@ -101,8 +96,7 @@ discard block |
||
101 | 96 | * |
102 | 97 | * @return int The status code |
103 | 98 | */ |
104 | - public function getStatusCode() |
|
105 | - { |
|
99 | + public function getStatusCode() { |
|
106 | 100 | if (null === $this->statusCode) { |
107 | 101 | throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?'); |
108 | 102 | } |
@@ -118,8 +112,7 @@ discard block |
||
118 | 112 | * |
119 | 113 | * @return $this |
120 | 114 | */ |
121 | - public function setInputs(array $inputs) |
|
122 | - { |
|
115 | + public function setInputs(array $inputs) { |
|
123 | 116 | $this->inputs = $inputs; |
124 | 117 | |
125 | 118 | return $this; |
@@ -134,8 +127,7 @@ discard block |
||
134 | 127 | * * verbosity: Sets the output verbosity flag |
135 | 128 | * * capture_stderr_separately: Make output of stdOut and stdErr separately available |
136 | 129 | */ |
137 | - private function initOutput(array $options) |
|
138 | - { |
|
130 | + private function initOutput(array $options) { |
|
139 | 131 | $this->captureStreamsIndependently = \array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately']; |
140 | 132 | if (!$this->captureStreamsIndependently) { |
141 | 133 | $this->output = new StreamOutput(fopen('php://memory', 'w', false)); |
@@ -171,8 +163,7 @@ discard block |
||
171 | 163 | /** |
172 | 164 | * @return resource |
173 | 165 | */ |
174 | - private static function createStream(array $inputs) |
|
175 | - { |
|
166 | + private static function createStream(array $inputs) { |
|
176 | 167 | $stream = fopen('php://memory', 'r+', false); |
177 | 168 | |
178 | 169 | foreach ($inputs as $input) { |
@@ -20,48 +20,48 @@ |
||
20 | 20 | */ |
21 | 21 | class SingleCommandApplication extends Command |
22 | 22 | { |
23 | - private $version = 'UNKNOWN'; |
|
24 | - private $autoExit = true; |
|
25 | - private $running = false; |
|
23 | + private $version = 'UNKNOWN'; |
|
24 | + private $autoExit = true; |
|
25 | + private $running = false; |
|
26 | 26 | |
27 | - public function setVersion(string $version): self |
|
28 | - { |
|
29 | - $this->version = $version; |
|
27 | + public function setVersion(string $version): self |
|
28 | + { |
|
29 | + $this->version = $version; |
|
30 | 30 | |
31 | - return $this; |
|
32 | - } |
|
31 | + return $this; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @final |
|
36 | - */ |
|
37 | - public function setAutoExit(bool $autoExit): self |
|
38 | - { |
|
39 | - $this->autoExit = $autoExit; |
|
34 | + /** |
|
35 | + * @final |
|
36 | + */ |
|
37 | + public function setAutoExit(bool $autoExit): self |
|
38 | + { |
|
39 | + $this->autoExit = $autoExit; |
|
40 | 40 | |
41 | - return $this; |
|
42 | - } |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | |
44 | - public function run(InputInterface $input = null, OutputInterface $output = null): int |
|
45 | - { |
|
46 | - if ($this->running) { |
|
47 | - return parent::run($input, $output); |
|
48 | - } |
|
44 | + public function run(InputInterface $input = null, OutputInterface $output = null): int |
|
45 | + { |
|
46 | + if ($this->running) { |
|
47 | + return parent::run($input, $output); |
|
48 | + } |
|
49 | 49 | |
50 | - // We use the command name as the application name |
|
51 | - $application = new Application($this->getName() ?: 'UNKNOWN', $this->version); |
|
52 | - $application->setAutoExit($this->autoExit); |
|
53 | - // Fix the usage of the command displayed with "--help" |
|
54 | - $this->setName($_SERVER['argv'][0]); |
|
55 | - $application->add($this); |
|
56 | - $application->setDefaultCommand($this->getName(), true); |
|
50 | + // We use the command name as the application name |
|
51 | + $application = new Application($this->getName() ?: 'UNKNOWN', $this->version); |
|
52 | + $application->setAutoExit($this->autoExit); |
|
53 | + // Fix the usage of the command displayed with "--help" |
|
54 | + $this->setName($_SERVER['argv'][0]); |
|
55 | + $application->add($this); |
|
56 | + $application->setDefaultCommand($this->getName(), true); |
|
57 | 57 | |
58 | - $this->running = true; |
|
59 | - try { |
|
60 | - $ret = $application->run($input, $output); |
|
61 | - } finally { |
|
62 | - $this->running = false; |
|
63 | - } |
|
58 | + $this->running = true; |
|
59 | + try { |
|
60 | + $ret = $application->run($input, $output); |
|
61 | + } finally { |
|
62 | + $this->running = false; |
|
63 | + } |
|
64 | 64 | |
65 | - return $ret ?? 1; |
|
66 | - } |
|
65 | + return $ret ?? 1; |
|
66 | + } |
|
67 | 67 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | private $autoExit = true; |
25 | 25 | private $running = false; |
26 | 26 | |
27 | - public function setVersion(string $version): self |
|
27 | + public function setVersion( string $version ): self |
|
28 | 28 | { |
29 | 29 | $this->version = $version; |
30 | 30 | |
@@ -34,30 +34,30 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @final |
36 | 36 | */ |
37 | - public function setAutoExit(bool $autoExit): self |
|
37 | + public function setAutoExit( bool $autoExit ): self |
|
38 | 38 | { |
39 | 39 | $this->autoExit = $autoExit; |
40 | 40 | |
41 | 41 | return $this; |
42 | 42 | } |
43 | 43 | |
44 | - public function run(InputInterface $input = null, OutputInterface $output = null): int |
|
44 | + public function run( InputInterface $input = null, OutputInterface $output = null ): int |
|
45 | 45 | { |
46 | - if ($this->running) { |
|
47 | - return parent::run($input, $output); |
|
46 | + if ( $this->running ) { |
|
47 | + return parent::run( $input, $output ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // We use the command name as the application name |
51 | - $application = new Application($this->getName() ?: 'UNKNOWN', $this->version); |
|
52 | - $application->setAutoExit($this->autoExit); |
|
51 | + $application = new Application( $this->getName() ?: 'UNKNOWN', $this->version ); |
|
52 | + $application->setAutoExit( $this->autoExit ); |
|
53 | 53 | // Fix the usage of the command displayed with "--help" |
54 | - $this->setName($_SERVER['argv'][0]); |
|
55 | - $application->add($this); |
|
56 | - $application->setDefaultCommand($this->getName(), true); |
|
54 | + $this->setName( $_SERVER[ 'argv' ][ 0 ] ); |
|
55 | + $application->add( $this ); |
|
56 | + $application->setDefaultCommand( $this->getName(), true ); |
|
57 | 57 | |
58 | 58 | $this->running = true; |
59 | 59 | try { |
60 | - $ret = $application->run($input, $output); |
|
60 | + $ret = $application->run( $input, $output ); |
|
61 | 61 | } finally { |
62 | 62 | $this->running = false; |
63 | 63 | } |
@@ -18,8 +18,7 @@ |
||
18 | 18 | /** |
19 | 19 | * @author Grégoire Pineau <[email protected]> |
20 | 20 | */ |
21 | -class SingleCommandApplication extends Command |
|
22 | -{ |
|
21 | +class SingleCommandApplication extends Command { |
|
23 | 22 | private $version = 'UNKNOWN'; |
24 | 23 | private $autoExit = true; |
25 | 24 | private $running = false; |
@@ -11,6 +11,5 @@ |
||
11 | 11 | |
12 | 12 | namespace Symfony\Component\String\Exception; |
13 | 13 | |
14 | -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface |
|
15 | -{ |
|
14 | +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface { |
|
16 | 15 | } |
@@ -11,6 +11,5 @@ |
||
11 | 11 | |
12 | 12 | namespace Symfony\Component\String\Exception; |
13 | 13 | |
14 | -interface ExceptionInterface extends \Throwable |
|
15 | -{ |
|
14 | +interface ExceptionInterface extends \Throwable { |
|
16 | 15 | } |