@@ -22,13 +22,11 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @author Fabien Potencier <[email protected]> |
24 | 24 | */ |
25 | -class ListCommand extends Command |
|
26 | -{ |
|
25 | +class ListCommand extends Command { |
|
27 | 26 | /** |
28 | 27 | * {@inheritdoc} |
29 | 28 | */ |
30 | - protected function configure() |
|
31 | - { |
|
29 | + protected function configure() { |
|
32 | 30 | $this |
33 | 31 | ->setName('list') |
34 | 32 | ->setDefinition([ |
@@ -62,8 +60,7 @@ discard block |
||
62 | 60 | /** |
63 | 61 | * {@inheritdoc} |
64 | 62 | */ |
65 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
66 | - { |
|
63 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
67 | 64 | $helper = new DescriptorHelper(); |
68 | 65 | $helper->describe($output, $this->getApplication(), [ |
69 | 66 | 'format' => $input->getOption('format'), |
@@ -54,7 +54,7 @@ |
||
54 | 54 | It's also possible to get raw list of commands (useful for embedding command runner): |
55 | 55 | |
56 | 56 | <info>%command.full_name% --raw</info> |
57 | -EOF |
|
57 | +eof |
|
58 | 58 | ) |
59 | 59 | ; |
60 | 60 | } |
@@ -27,21 +27,21 @@ discard block |
||
27 | 27 | */ |
28 | 28 | class ListCommand extends Command |
29 | 29 | { |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected function configure() |
|
34 | - { |
|
35 | - $this |
|
36 | - ->setName('list') |
|
37 | - ->setDefinition([ |
|
38 | - new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), |
|
39 | - new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), |
|
40 | - new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'), |
|
41 | - new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'), |
|
42 | - ]) |
|
43 | - ->setDescription('List commands') |
|
44 | - ->setHelp(<<<'EOF' |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected function configure() |
|
34 | + { |
|
35 | + $this |
|
36 | + ->setName('list') |
|
37 | + ->setDefinition([ |
|
38 | + new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), |
|
39 | + new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), |
|
40 | + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'), |
|
41 | + new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'), |
|
42 | + ]) |
|
43 | + ->setDescription('List commands') |
|
44 | + ->setHelp(<<<'EOF' |
|
45 | 45 | The <info>%command.name%</info> command lists all commands: |
46 | 46 | |
47 | 47 | <info>%command.full_name%</info> |
@@ -58,38 +58,38 @@ discard block |
||
58 | 58 | |
59 | 59 | <info>%command.full_name% --raw</info> |
60 | 60 | EOF |
61 | - ) |
|
62 | - ; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
69 | - { |
|
70 | - $helper = new DescriptorHelper(); |
|
71 | - $helper->describe($output, $this->getApplication(), [ |
|
72 | - 'format' => $input->getOption('format'), |
|
73 | - 'raw_text' => $input->getOption('raw'), |
|
74 | - 'namespace' => $input->getArgument('namespace'), |
|
75 | - 'short' => $input->getOption('short'), |
|
76 | - ]); |
|
77 | - |
|
78 | - return 0; |
|
79 | - } |
|
80 | - |
|
81 | - public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
|
82 | - { |
|
83 | - if ($input->mustSuggestArgumentValuesFor('namespace')) { |
|
84 | - $descriptor = new ApplicationDescription($this->getApplication()); |
|
85 | - $suggestions->suggestValues(array_keys($descriptor->getNamespaces())); |
|
86 | - |
|
87 | - return; |
|
88 | - } |
|
89 | - |
|
90 | - if ($input->mustSuggestOptionValuesFor('format')) { |
|
91 | - $helper = new DescriptorHelper(); |
|
92 | - $suggestions->suggestValues($helper->getFormats()); |
|
93 | - } |
|
94 | - } |
|
61 | + ) |
|
62 | + ; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
69 | + { |
|
70 | + $helper = new DescriptorHelper(); |
|
71 | + $helper->describe($output, $this->getApplication(), [ |
|
72 | + 'format' => $input->getOption('format'), |
|
73 | + 'raw_text' => $input->getOption('raw'), |
|
74 | + 'namespace' => $input->getArgument('namespace'), |
|
75 | + 'short' => $input->getOption('short'), |
|
76 | + ]); |
|
77 | + |
|
78 | + return 0; |
|
79 | + } |
|
80 | + |
|
81 | + public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
|
82 | + { |
|
83 | + if ($input->mustSuggestArgumentValuesFor('namespace')) { |
|
84 | + $descriptor = new ApplicationDescription($this->getApplication()); |
|
85 | + $suggestions->suggestValues(array_keys($descriptor->getNamespaces())); |
|
86 | + |
|
87 | + return; |
|
88 | + } |
|
89 | + |
|
90 | + if ($input->mustSuggestOptionValuesFor('format')) { |
|
91 | + $helper = new DescriptorHelper(); |
|
92 | + $suggestions->suggestValues($helper->getFormats()); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | } |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | protected function configure() |
34 | 34 | { |
35 | 35 | $this |
36 | - ->setName('list') |
|
37 | - ->setDefinition([ |
|
38 | - new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), |
|
39 | - new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), |
|
40 | - new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'), |
|
41 | - new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'), |
|
42 | - ]) |
|
43 | - ->setDescription('List commands') |
|
44 | - ->setHelp(<<<'EOF' |
|
36 | + ->setName( 'list' ) |
|
37 | + ->setDefinition( [ |
|
38 | + new InputArgument( 'namespace', InputArgument::OPTIONAL, 'The namespace name' ), |
|
39 | + new InputOption( 'raw', null, InputOption::VALUE_NONE, 'To output raw command list' ), |
|
40 | + new InputOption( 'format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt' ), |
|
41 | + new InputOption( 'short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments' ), |
|
42 | + ] ) |
|
43 | + ->setDescription( 'List commands' ) |
|
44 | + ->setHelp( <<<'EOF' |
|
45 | 45 | The <info>%command.name%</info> command lists all commands: |
46 | 46 | |
47 | 47 | <info>%command.full_name%</info> |
@@ -65,31 +65,31 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * {@inheritdoc} |
67 | 67 | */ |
68 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
68 | + protected function execute( InputInterface $input, OutputInterface $output ) |
|
69 | 69 | { |
70 | 70 | $helper = new DescriptorHelper(); |
71 | - $helper->describe($output, $this->getApplication(), [ |
|
72 | - 'format' => $input->getOption('format'), |
|
73 | - 'raw_text' => $input->getOption('raw'), |
|
74 | - 'namespace' => $input->getArgument('namespace'), |
|
75 | - 'short' => $input->getOption('short'), |
|
76 | - ]); |
|
71 | + $helper->describe( $output, $this->getApplication(), [ |
|
72 | + 'format' => $input->getOption( 'format' ), |
|
73 | + 'raw_text' => $input->getOption( 'raw' ), |
|
74 | + 'namespace' => $input->getArgument( 'namespace' ), |
|
75 | + 'short' => $input->getOption( 'short' ), |
|
76 | + ] ); |
|
77 | 77 | |
78 | 78 | return 0; |
79 | 79 | } |
80 | 80 | |
81 | - public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
|
81 | + public function complete( CompletionInput $input, CompletionSuggestions $suggestions ): void |
|
82 | 82 | { |
83 | - if ($input->mustSuggestArgumentValuesFor('namespace')) { |
|
84 | - $descriptor = new ApplicationDescription($this->getApplication()); |
|
85 | - $suggestions->suggestValues(array_keys($descriptor->getNamespaces())); |
|
83 | + if ( $input->mustSuggestArgumentValuesFor( 'namespace' ) ) { |
|
84 | + $descriptor = new ApplicationDescription( $this->getApplication() ); |
|
85 | + $suggestions->suggestValues( array_keys( $descriptor->getNamespaces() ) ); |
|
86 | 86 | |
87 | 87 | return; |
88 | 88 | } |
89 | 89 | |
90 | - if ($input->mustSuggestOptionValuesFor('format')) { |
|
90 | + if ( $input->mustSuggestOptionValuesFor( 'format' ) ) { |
|
91 | 91 | $helper = new DescriptorHelper(); |
92 | - $suggestions->suggestValues($helper->getFormats()); |
|
92 | + $suggestions->suggestValues( $helper->getFormats() ); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
@@ -20,13 +20,11 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @author Nicolas Grekas <[email protected]> |
22 | 22 | */ |
23 | -final class LazyCommand extends Command |
|
24 | -{ |
|
23 | +final class LazyCommand extends Command { |
|
25 | 24 | private $command; |
26 | 25 | private $isEnabled; |
27 | 26 | |
28 | - public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true) |
|
29 | - { |
|
27 | + public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true) { |
|
30 | 28 | $this->setName($name) |
31 | 29 | ->setAliases($aliases) |
32 | 30 | ->setHidden($isHidden) |
@@ -180,8 +178,7 @@ discard block |
||
180 | 178 | /** |
181 | 179 | * @return mixed |
182 | 180 | */ |
183 | - public function getHelper(string $name) |
|
184 | - { |
|
181 | + public function getHelper(string $name) { |
|
185 | 182 | return $this->getCommand()->getHelper($name); |
186 | 183 | } |
187 | 184 |
@@ -24,195 +24,195 @@ |
||
24 | 24 | */ |
25 | 25 | final class LazyCommand extends Command |
26 | 26 | { |
27 | - private $command; |
|
28 | - private $isEnabled; |
|
29 | - |
|
30 | - public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true) |
|
31 | - { |
|
32 | - $this->setName($name) |
|
33 | - ->setAliases($aliases) |
|
34 | - ->setHidden($isHidden) |
|
35 | - ->setDescription($description); |
|
36 | - |
|
37 | - $this->command = $commandFactory; |
|
38 | - $this->isEnabled = $isEnabled; |
|
39 | - } |
|
40 | - |
|
41 | - public function ignoreValidationErrors(): void |
|
42 | - { |
|
43 | - $this->getCommand()->ignoreValidationErrors(); |
|
44 | - } |
|
45 | - |
|
46 | - public function setApplication(Application $application = null): void |
|
47 | - { |
|
48 | - if ($this->command instanceof parent) { |
|
49 | - $this->command->setApplication($application); |
|
50 | - } |
|
51 | - |
|
52 | - parent::setApplication($application); |
|
53 | - } |
|
54 | - |
|
55 | - public function setHelperSet(HelperSet $helperSet): void |
|
56 | - { |
|
57 | - if ($this->command instanceof parent) { |
|
58 | - $this->command->setHelperSet($helperSet); |
|
59 | - } |
|
60 | - |
|
61 | - parent::setHelperSet($helperSet); |
|
62 | - } |
|
63 | - |
|
64 | - public function isEnabled(): bool |
|
65 | - { |
|
66 | - return $this->isEnabled ?? $this->getCommand()->isEnabled(); |
|
67 | - } |
|
68 | - |
|
69 | - public function run(InputInterface $input, OutputInterface $output): int |
|
70 | - { |
|
71 | - return $this->getCommand()->run($input, $output); |
|
72 | - } |
|
73 | - |
|
74 | - public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
|
75 | - { |
|
76 | - $this->getCommand()->complete($input, $suggestions); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return $this |
|
81 | - */ |
|
82 | - public function setCode(callable $code): self |
|
83 | - { |
|
84 | - $this->getCommand()->setCode($code); |
|
85 | - |
|
86 | - return $this; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @internal |
|
91 | - */ |
|
92 | - public function mergeApplicationDefinition(bool $mergeArgs = true): void |
|
93 | - { |
|
94 | - $this->getCommand()->mergeApplicationDefinition($mergeArgs); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return $this |
|
99 | - */ |
|
100 | - public function setDefinition($definition): self |
|
101 | - { |
|
102 | - $this->getCommand()->setDefinition($definition); |
|
103 | - |
|
104 | - return $this; |
|
105 | - } |
|
106 | - |
|
107 | - public function getDefinition(): InputDefinition |
|
108 | - { |
|
109 | - return $this->getCommand()->getDefinition(); |
|
110 | - } |
|
111 | - |
|
112 | - public function getNativeDefinition(): InputDefinition |
|
113 | - { |
|
114 | - return $this->getCommand()->getNativeDefinition(); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return $this |
|
119 | - */ |
|
120 | - public function addArgument(string $name, int $mode = null, string $description = '', $default = null): self |
|
121 | - { |
|
122 | - $this->getCommand()->addArgument($name, $mode, $description, $default); |
|
123 | - |
|
124 | - return $this; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @return $this |
|
129 | - */ |
|
130 | - public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null): self |
|
131 | - { |
|
132 | - $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default); |
|
133 | - |
|
134 | - return $this; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return $this |
|
139 | - */ |
|
140 | - public function setProcessTitle(string $title): self |
|
141 | - { |
|
142 | - $this->getCommand()->setProcessTitle($title); |
|
143 | - |
|
144 | - return $this; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return $this |
|
149 | - */ |
|
150 | - public function setHelp(string $help): self |
|
151 | - { |
|
152 | - $this->getCommand()->setHelp($help); |
|
153 | - |
|
154 | - return $this; |
|
155 | - } |
|
156 | - |
|
157 | - public function getHelp(): string |
|
158 | - { |
|
159 | - return $this->getCommand()->getHelp(); |
|
160 | - } |
|
161 | - |
|
162 | - public function getProcessedHelp(): string |
|
163 | - { |
|
164 | - return $this->getCommand()->getProcessedHelp(); |
|
165 | - } |
|
166 | - |
|
167 | - public function getSynopsis(bool $short = false): string |
|
168 | - { |
|
169 | - return $this->getCommand()->getSynopsis($short); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @return $this |
|
174 | - */ |
|
175 | - public function addUsage(string $usage): self |
|
176 | - { |
|
177 | - $this->getCommand()->addUsage($usage); |
|
178 | - |
|
179 | - return $this; |
|
180 | - } |
|
181 | - |
|
182 | - public function getUsages(): array |
|
183 | - { |
|
184 | - return $this->getCommand()->getUsages(); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @return mixed |
|
189 | - */ |
|
190 | - public function getHelper(string $name) |
|
191 | - { |
|
192 | - return $this->getCommand()->getHelper($name); |
|
193 | - } |
|
194 | - |
|
195 | - public function getCommand(): parent |
|
196 | - { |
|
197 | - if (!$this->command instanceof \Closure) { |
|
198 | - return $this->command; |
|
199 | - } |
|
200 | - |
|
201 | - $command = $this->command = ($this->command)(); |
|
202 | - $command->setApplication($this->getApplication()); |
|
203 | - |
|
204 | - if (null !== $this->getHelperSet()) { |
|
205 | - $command->setHelperSet($this->getHelperSet()); |
|
206 | - } |
|
207 | - |
|
208 | - $command->setName($this->getName()) |
|
209 | - ->setAliases($this->getAliases()) |
|
210 | - ->setHidden($this->isHidden()) |
|
211 | - ->setDescription($this->getDescription()); |
|
212 | - |
|
213 | - // Will throw if the command is not correctly initialized. |
|
214 | - $command->getDefinition(); |
|
215 | - |
|
216 | - return $command; |
|
217 | - } |
|
27 | + private $command; |
|
28 | + private $isEnabled; |
|
29 | + |
|
30 | + public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true) |
|
31 | + { |
|
32 | + $this->setName($name) |
|
33 | + ->setAliases($aliases) |
|
34 | + ->setHidden($isHidden) |
|
35 | + ->setDescription($description); |
|
36 | + |
|
37 | + $this->command = $commandFactory; |
|
38 | + $this->isEnabled = $isEnabled; |
|
39 | + } |
|
40 | + |
|
41 | + public function ignoreValidationErrors(): void |
|
42 | + { |
|
43 | + $this->getCommand()->ignoreValidationErrors(); |
|
44 | + } |
|
45 | + |
|
46 | + public function setApplication(Application $application = null): void |
|
47 | + { |
|
48 | + if ($this->command instanceof parent) { |
|
49 | + $this->command->setApplication($application); |
|
50 | + } |
|
51 | + |
|
52 | + parent::setApplication($application); |
|
53 | + } |
|
54 | + |
|
55 | + public function setHelperSet(HelperSet $helperSet): void |
|
56 | + { |
|
57 | + if ($this->command instanceof parent) { |
|
58 | + $this->command->setHelperSet($helperSet); |
|
59 | + } |
|
60 | + |
|
61 | + parent::setHelperSet($helperSet); |
|
62 | + } |
|
63 | + |
|
64 | + public function isEnabled(): bool |
|
65 | + { |
|
66 | + return $this->isEnabled ?? $this->getCommand()->isEnabled(); |
|
67 | + } |
|
68 | + |
|
69 | + public function run(InputInterface $input, OutputInterface $output): int |
|
70 | + { |
|
71 | + return $this->getCommand()->run($input, $output); |
|
72 | + } |
|
73 | + |
|
74 | + public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
|
75 | + { |
|
76 | + $this->getCommand()->complete($input, $suggestions); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return $this |
|
81 | + */ |
|
82 | + public function setCode(callable $code): self |
|
83 | + { |
|
84 | + $this->getCommand()->setCode($code); |
|
85 | + |
|
86 | + return $this; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @internal |
|
91 | + */ |
|
92 | + public function mergeApplicationDefinition(bool $mergeArgs = true): void |
|
93 | + { |
|
94 | + $this->getCommand()->mergeApplicationDefinition($mergeArgs); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return $this |
|
99 | + */ |
|
100 | + public function setDefinition($definition): self |
|
101 | + { |
|
102 | + $this->getCommand()->setDefinition($definition); |
|
103 | + |
|
104 | + return $this; |
|
105 | + } |
|
106 | + |
|
107 | + public function getDefinition(): InputDefinition |
|
108 | + { |
|
109 | + return $this->getCommand()->getDefinition(); |
|
110 | + } |
|
111 | + |
|
112 | + public function getNativeDefinition(): InputDefinition |
|
113 | + { |
|
114 | + return $this->getCommand()->getNativeDefinition(); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return $this |
|
119 | + */ |
|
120 | + public function addArgument(string $name, int $mode = null, string $description = '', $default = null): self |
|
121 | + { |
|
122 | + $this->getCommand()->addArgument($name, $mode, $description, $default); |
|
123 | + |
|
124 | + return $this; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @return $this |
|
129 | + */ |
|
130 | + public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null): self |
|
131 | + { |
|
132 | + $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default); |
|
133 | + |
|
134 | + return $this; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return $this |
|
139 | + */ |
|
140 | + public function setProcessTitle(string $title): self |
|
141 | + { |
|
142 | + $this->getCommand()->setProcessTitle($title); |
|
143 | + |
|
144 | + return $this; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return $this |
|
149 | + */ |
|
150 | + public function setHelp(string $help): self |
|
151 | + { |
|
152 | + $this->getCommand()->setHelp($help); |
|
153 | + |
|
154 | + return $this; |
|
155 | + } |
|
156 | + |
|
157 | + public function getHelp(): string |
|
158 | + { |
|
159 | + return $this->getCommand()->getHelp(); |
|
160 | + } |
|
161 | + |
|
162 | + public function getProcessedHelp(): string |
|
163 | + { |
|
164 | + return $this->getCommand()->getProcessedHelp(); |
|
165 | + } |
|
166 | + |
|
167 | + public function getSynopsis(bool $short = false): string |
|
168 | + { |
|
169 | + return $this->getCommand()->getSynopsis($short); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @return $this |
|
174 | + */ |
|
175 | + public function addUsage(string $usage): self |
|
176 | + { |
|
177 | + $this->getCommand()->addUsage($usage); |
|
178 | + |
|
179 | + return $this; |
|
180 | + } |
|
181 | + |
|
182 | + public function getUsages(): array |
|
183 | + { |
|
184 | + return $this->getCommand()->getUsages(); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @return mixed |
|
189 | + */ |
|
190 | + public function getHelper(string $name) |
|
191 | + { |
|
192 | + return $this->getCommand()->getHelper($name); |
|
193 | + } |
|
194 | + |
|
195 | + public function getCommand(): parent |
|
196 | + { |
|
197 | + if (!$this->command instanceof \Closure) { |
|
198 | + return $this->command; |
|
199 | + } |
|
200 | + |
|
201 | + $command = $this->command = ($this->command)(); |
|
202 | + $command->setApplication($this->getApplication()); |
|
203 | + |
|
204 | + if (null !== $this->getHelperSet()) { |
|
205 | + $command->setHelperSet($this->getHelperSet()); |
|
206 | + } |
|
207 | + |
|
208 | + $command->setName($this->getName()) |
|
209 | + ->setAliases($this->getAliases()) |
|
210 | + ->setHidden($this->isHidden()) |
|
211 | + ->setDescription($this->getDescription()); |
|
212 | + |
|
213 | + // Will throw if the command is not correctly initialized. |
|
214 | + $command->getDefinition(); |
|
215 | + |
|
216 | + return $command; |
|
217 | + } |
|
218 | 218 | } |
@@ -27,12 +27,12 @@ discard block |
||
27 | 27 | private $command; |
28 | 28 | private $isEnabled; |
29 | 29 | |
30 | - public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true) |
|
30 | + public function __construct( string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true ) |
|
31 | 31 | { |
32 | - $this->setName($name) |
|
33 | - ->setAliases($aliases) |
|
34 | - ->setHidden($isHidden) |
|
35 | - ->setDescription($description); |
|
32 | + $this->setName( $name ) |
|
33 | + ->setAliases( $aliases ) |
|
34 | + ->setHidden( $isHidden ) |
|
35 | + ->setDescription( $description ); |
|
36 | 36 | |
37 | 37 | $this->command = $commandFactory; |
38 | 38 | $this->isEnabled = $isEnabled; |
@@ -43,22 +43,22 @@ discard block |
||
43 | 43 | $this->getCommand()->ignoreValidationErrors(); |
44 | 44 | } |
45 | 45 | |
46 | - public function setApplication(Application $application = null): void |
|
46 | + public function setApplication( Application $application = null ): void |
|
47 | 47 | { |
48 | - if ($this->command instanceof parent) { |
|
49 | - $this->command->setApplication($application); |
|
48 | + if ( $this->command instanceof parent ) { |
|
49 | + $this->command->setApplication( $application ); |
|
50 | 50 | } |
51 | 51 | |
52 | - parent::setApplication($application); |
|
52 | + parent::setApplication( $application ); |
|
53 | 53 | } |
54 | 54 | |
55 | - public function setHelperSet(HelperSet $helperSet): void |
|
55 | + public function setHelperSet( HelperSet $helperSet ): void |
|
56 | 56 | { |
57 | - if ($this->command instanceof parent) { |
|
58 | - $this->command->setHelperSet($helperSet); |
|
57 | + if ( $this->command instanceof parent ) { |
|
58 | + $this->command->setHelperSet( $helperSet ); |
|
59 | 59 | } |
60 | 60 | |
61 | - parent::setHelperSet($helperSet); |
|
61 | + parent::setHelperSet( $helperSet ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public function isEnabled(): bool |
@@ -66,22 +66,22 @@ discard block |
||
66 | 66 | return $this->isEnabled ?? $this->getCommand()->isEnabled(); |
67 | 67 | } |
68 | 68 | |
69 | - public function run(InputInterface $input, OutputInterface $output): int |
|
69 | + public function run( InputInterface $input, OutputInterface $output ): int |
|
70 | 70 | { |
71 | - return $this->getCommand()->run($input, $output); |
|
71 | + return $this->getCommand()->run( $input, $output ); |
|
72 | 72 | } |
73 | 73 | |
74 | - public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
|
74 | + public function complete( CompletionInput $input, CompletionSuggestions $suggestions ): void |
|
75 | 75 | { |
76 | - $this->getCommand()->complete($input, $suggestions); |
|
76 | + $this->getCommand()->complete( $input, $suggestions ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @return $this |
81 | 81 | */ |
82 | - public function setCode(callable $code): self |
|
82 | + public function setCode( callable $code ): self |
|
83 | 83 | { |
84 | - $this->getCommand()->setCode($code); |
|
84 | + $this->getCommand()->setCode( $code ); |
|
85 | 85 | |
86 | 86 | return $this; |
87 | 87 | } |
@@ -89,17 +89,17 @@ discard block |
||
89 | 89 | /** |
90 | 90 | * @internal |
91 | 91 | */ |
92 | - public function mergeApplicationDefinition(bool $mergeArgs = true): void |
|
92 | + public function mergeApplicationDefinition( bool $mergeArgs = true ): void |
|
93 | 93 | { |
94 | - $this->getCommand()->mergeApplicationDefinition($mergeArgs); |
|
94 | + $this->getCommand()->mergeApplicationDefinition( $mergeArgs ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @return $this |
99 | 99 | */ |
100 | - public function setDefinition($definition): self |
|
100 | + public function setDefinition( $definition ): self |
|
101 | 101 | { |
102 | - $this->getCommand()->setDefinition($definition); |
|
102 | + $this->getCommand()->setDefinition( $definition ); |
|
103 | 103 | |
104 | 104 | return $this; |
105 | 105 | } |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | /** |
118 | 118 | * @return $this |
119 | 119 | */ |
120 | - public function addArgument(string $name, int $mode = null, string $description = '', $default = null): self |
|
120 | + public function addArgument( string $name, int $mode = null, string $description = '', $default = null ): self |
|
121 | 121 | { |
122 | - $this->getCommand()->addArgument($name, $mode, $description, $default); |
|
122 | + $this->getCommand()->addArgument( $name, $mode, $description, $default ); |
|
123 | 123 | |
124 | 124 | return $this; |
125 | 125 | } |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * @return $this |
129 | 129 | */ |
130 | - public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null): self |
|
130 | + public function addOption( string $name, $shortcut = null, int $mode = null, string $description = '', $default = null ): self |
|
131 | 131 | { |
132 | - $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default); |
|
132 | + $this->getCommand()->addOption( $name, $shortcut, $mode, $description, $default ); |
|
133 | 133 | |
134 | 134 | return $this; |
135 | 135 | } |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * @return $this |
139 | 139 | */ |
140 | - public function setProcessTitle(string $title): self |
|
140 | + public function setProcessTitle( string $title ): self |
|
141 | 141 | { |
142 | - $this->getCommand()->setProcessTitle($title); |
|
142 | + $this->getCommand()->setProcessTitle( $title ); |
|
143 | 143 | |
144 | 144 | return $this; |
145 | 145 | } |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | /** |
148 | 148 | * @return $this |
149 | 149 | */ |
150 | - public function setHelp(string $help): self |
|
150 | + public function setHelp( string $help ): self |
|
151 | 151 | { |
152 | - $this->getCommand()->setHelp($help); |
|
152 | + $this->getCommand()->setHelp( $help ); |
|
153 | 153 | |
154 | 154 | return $this; |
155 | 155 | } |
@@ -164,17 +164,17 @@ discard block |
||
164 | 164 | return $this->getCommand()->getProcessedHelp(); |
165 | 165 | } |
166 | 166 | |
167 | - public function getSynopsis(bool $short = false): string |
|
167 | + public function getSynopsis( bool $short = false ): string |
|
168 | 168 | { |
169 | - return $this->getCommand()->getSynopsis($short); |
|
169 | + return $this->getCommand()->getSynopsis( $short ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * @return $this |
174 | 174 | */ |
175 | - public function addUsage(string $usage): self |
|
175 | + public function addUsage( string $usage ): self |
|
176 | 176 | { |
177 | - $this->getCommand()->addUsage($usage); |
|
177 | + $this->getCommand()->addUsage( $usage ); |
|
178 | 178 | |
179 | 179 | return $this; |
180 | 180 | } |
@@ -187,28 +187,28 @@ discard block |
||
187 | 187 | /** |
188 | 188 | * @return mixed |
189 | 189 | */ |
190 | - public function getHelper(string $name) |
|
190 | + public function getHelper( string $name ) |
|
191 | 191 | { |
192 | - return $this->getCommand()->getHelper($name); |
|
192 | + return $this->getCommand()->getHelper( $name ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | public function getCommand(): parent |
196 | 196 | { |
197 | - if (!$this->command instanceof \Closure) { |
|
197 | + if ( ! $this->command instanceof \Closure ) { |
|
198 | 198 | return $this->command; |
199 | 199 | } |
200 | 200 | |
201 | - $command = $this->command = ($this->command)(); |
|
202 | - $command->setApplication($this->getApplication()); |
|
201 | + $command = $this->command = ( $this->command )(); |
|
202 | + $command->setApplication( $this->getApplication() ); |
|
203 | 203 | |
204 | - if (null !== $this->getHelperSet()) { |
|
205 | - $command->setHelperSet($this->getHelperSet()); |
|
204 | + if ( null !== $this->getHelperSet() ) { |
|
205 | + $command->setHelperSet( $this->getHelperSet() ); |
|
206 | 206 | } |
207 | 207 | |
208 | - $command->setName($this->getName()) |
|
209 | - ->setAliases($this->getAliases()) |
|
210 | - ->setHidden($this->isHidden()) |
|
211 | - ->setDescription($this->getDescription()); |
|
208 | + $command->setName( $this->getName() ) |
|
209 | + ->setAliases( $this->getAliases() ) |
|
210 | + ->setHidden( $this->isHidden() ) |
|
211 | + ->setDescription( $this->getDescription() ); |
|
212 | 212 | |
213 | 213 | // Will throw if the command is not correctly initialized. |
214 | 214 | $command->getDefinition(); |
@@ -30,24 +30,24 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * Locks a command. |
32 | 32 | */ |
33 | - private function lock(string $name = null, bool $blocking = false): bool |
|
33 | + private function lock( string $name = null, bool $blocking = false ): bool |
|
34 | 34 | { |
35 | - if (!class_exists(SemaphoreStore::class)) { |
|
36 | - throw new LogicException('To enable the locking feature you must install the symfony/lock component.'); |
|
35 | + if ( ! class_exists( SemaphoreStore::class ) ) { |
|
36 | + throw new LogicException( 'To enable the locking feature you must install the symfony/lock component.' ); |
|
37 | 37 | } |
38 | 38 | |
39 | - if (null !== $this->lock) { |
|
40 | - throw new LogicException('A lock is already in place.'); |
|
39 | + if ( null !== $this->lock ) { |
|
40 | + throw new LogicException( 'A lock is already in place.' ); |
|
41 | 41 | } |
42 | 42 | |
43 | - if (SemaphoreStore::isSupported()) { |
|
43 | + if ( SemaphoreStore::isSupported() ) { |
|
44 | 44 | $store = new SemaphoreStore(); |
45 | 45 | } else { |
46 | 46 | $store = new FlockStore(); |
47 | 47 | } |
48 | 48 | |
49 | - $this->lock = (new LockFactory($store))->createLock($name ?: $this->getName()); |
|
50 | - if (!$this->lock->acquire($blocking)) { |
|
49 | + $this->lock = ( new LockFactory( $store ) )->createLock( $name ?: $this->getName() ); |
|
50 | + if ( ! $this->lock->acquire( $blocking ) ) { |
|
51 | 51 | $this->lock = null; |
52 | 52 | |
53 | 53 | return false; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | private function release() |
63 | 63 | { |
64 | - if ($this->lock) { |
|
64 | + if ( $this->lock ) { |
|
65 | 65 | $this->lock->release(); |
66 | 66 | $this->lock = null; |
67 | 67 | } |
@@ -24,46 +24,46 @@ |
||
24 | 24 | */ |
25 | 25 | trait LockableTrait |
26 | 26 | { |
27 | - /** @var LockInterface|null */ |
|
28 | - private $lock; |
|
27 | + /** @var LockInterface|null */ |
|
28 | + private $lock; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Locks a command. |
|
32 | - */ |
|
33 | - private function lock(string $name = null, bool $blocking = false): bool |
|
34 | - { |
|
35 | - if (!class_exists(SemaphoreStore::class)) { |
|
36 | - throw new LogicException('To enable the locking feature you must install the symfony/lock component.'); |
|
37 | - } |
|
30 | + /** |
|
31 | + * Locks a command. |
|
32 | + */ |
|
33 | + private function lock(string $name = null, bool $blocking = false): bool |
|
34 | + { |
|
35 | + if (!class_exists(SemaphoreStore::class)) { |
|
36 | + throw new LogicException('To enable the locking feature you must install the symfony/lock component.'); |
|
37 | + } |
|
38 | 38 | |
39 | - if (null !== $this->lock) { |
|
40 | - throw new LogicException('A lock is already in place.'); |
|
41 | - } |
|
39 | + if (null !== $this->lock) { |
|
40 | + throw new LogicException('A lock is already in place.'); |
|
41 | + } |
|
42 | 42 | |
43 | - if (SemaphoreStore::isSupported()) { |
|
44 | - $store = new SemaphoreStore(); |
|
45 | - } else { |
|
46 | - $store = new FlockStore(); |
|
47 | - } |
|
43 | + if (SemaphoreStore::isSupported()) { |
|
44 | + $store = new SemaphoreStore(); |
|
45 | + } else { |
|
46 | + $store = new FlockStore(); |
|
47 | + } |
|
48 | 48 | |
49 | - $this->lock = (new LockFactory($store))->createLock($name ?: $this->getName()); |
|
50 | - if (!$this->lock->acquire($blocking)) { |
|
51 | - $this->lock = null; |
|
49 | + $this->lock = (new LockFactory($store))->createLock($name ?: $this->getName()); |
|
50 | + if (!$this->lock->acquire($blocking)) { |
|
51 | + $this->lock = null; |
|
52 | 52 | |
53 | - return false; |
|
54 | - } |
|
53 | + return false; |
|
54 | + } |
|
55 | 55 | |
56 | - return true; |
|
57 | - } |
|
56 | + return true; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Releases the command lock if there is one. |
|
61 | - */ |
|
62 | - private function release() |
|
63 | - { |
|
64 | - if ($this->lock) { |
|
65 | - $this->lock->release(); |
|
66 | - $this->lock = null; |
|
67 | - } |
|
68 | - } |
|
59 | + /** |
|
60 | + * Releases the command lock if there is one. |
|
61 | + */ |
|
62 | + private function release() |
|
63 | + { |
|
64 | + if ($this->lock) { |
|
65 | + $this->lock->release(); |
|
66 | + $this->lock = null; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
@@ -22,8 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @author Geoffrey Brier <[email protected]> |
24 | 24 | */ |
25 | -trait LockableTrait |
|
26 | -{ |
|
25 | +trait LockableTrait { |
|
27 | 26 | /** @var LockInterface|null */ |
28 | 27 | private $lock; |
29 | 28 | |
@@ -59,8 +58,7 @@ discard block |
||
59 | 58 | /** |
60 | 59 | * Releases the command lock if there is one. |
61 | 60 | */ |
62 | - private function release() |
|
63 | - { |
|
61 | + private function release() { |
|
64 | 62 | if ($this->lock) { |
65 | 63 | $this->lock->release(); |
66 | 64 | $this->lock = null; |
@@ -16,30 +16,30 @@ |
||
16 | 16 | */ |
17 | 17 | class BufferedOutput extends Output |
18 | 18 | { |
19 | - private $buffer = ''; |
|
19 | + private $buffer = ''; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Empties buffer and returns its content. |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function fetch() |
|
27 | - { |
|
28 | - $content = $this->buffer; |
|
29 | - $this->buffer = ''; |
|
21 | + /** |
|
22 | + * Empties buffer and returns its content. |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function fetch() |
|
27 | + { |
|
28 | + $content = $this->buffer; |
|
29 | + $this->buffer = ''; |
|
30 | 30 | |
31 | - return $content; |
|
32 | - } |
|
31 | + return $content; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * {@inheritdoc} |
|
36 | - */ |
|
37 | - protected function doWrite(string $message, bool $newline) |
|
38 | - { |
|
39 | - $this->buffer .= $message; |
|
34 | + /** |
|
35 | + * {@inheritdoc} |
|
36 | + */ |
|
37 | + protected function doWrite(string $message, bool $newline) |
|
38 | + { |
|
39 | + $this->buffer .= $message; |
|
40 | 40 | |
41 | - if ($newline) { |
|
42 | - $this->buffer .= \PHP_EOL; |
|
43 | - } |
|
44 | - } |
|
41 | + if ($newline) { |
|
42 | + $this->buffer .= \PHP_EOL; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |
@@ -34,11 +34,11 @@ |
||
34 | 34 | /** |
35 | 35 | * {@inheritdoc} |
36 | 36 | */ |
37 | - protected function doWrite(string $message, bool $newline) |
|
37 | + protected function doWrite( string $message, bool $newline ) |
|
38 | 38 | { |
39 | 39 | $this->buffer .= $message; |
40 | 40 | |
41 | - if ($newline) { |
|
41 | + if ( $newline ) { |
|
42 | 42 | $this->buffer .= \PHP_EOL; |
43 | 43 | } |
44 | 44 | } |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @author Jean-François Simon <[email protected]> |
16 | 16 | */ |
17 | -class BufferedOutput extends Output |
|
18 | -{ |
|
17 | +class BufferedOutput extends Output { |
|
19 | 18 | private $buffer = ''; |
20 | 19 | |
21 | 20 | /** |
@@ -23,8 +22,7 @@ discard block |
||
23 | 22 | * |
24 | 23 | * @return string |
25 | 24 | */ |
26 | - public function fetch() |
|
27 | - { |
|
25 | + public function fetch() { |
|
28 | 26 | $content = $this->buffer; |
29 | 27 | $this->buffer = ''; |
30 | 28 | |
@@ -34,8 +32,7 @@ discard block |
||
34 | 32 | /** |
35 | 33 | * {@inheritdoc} |
36 | 34 | */ |
37 | - protected function doWrite(string $message, bool $newline) |
|
38 | - { |
|
35 | + protected function doWrite(string $message, bool $newline) { |
|
39 | 36 | $this->buffer .= $message; |
40 | 37 | |
41 | 38 | if ($newline) { |
@@ -19,14 +19,14 @@ |
||
19 | 19 | */ |
20 | 20 | interface ConsoleOutputInterface extends OutputInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Gets the OutputInterface for errors. |
|
24 | - * |
|
25 | - * @return OutputInterface |
|
26 | - */ |
|
27 | - public function getErrorOutput(); |
|
22 | + /** |
|
23 | + * Gets the OutputInterface for errors. |
|
24 | + * |
|
25 | + * @return OutputInterface |
|
26 | + */ |
|
27 | + public function getErrorOutput(); |
|
28 | 28 | |
29 | - public function setErrorOutput(OutputInterface $error); |
|
29 | + public function setErrorOutput(OutputInterface $error); |
|
30 | 30 | |
31 | - public function section(): ConsoleSectionOutput; |
|
31 | + public function section(): ConsoleSectionOutput; |
|
32 | 32 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | */ |
27 | 27 | public function getErrorOutput(); |
28 | 28 | |
29 | - public function setErrorOutput(OutputInterface $error); |
|
29 | + public function setErrorOutput( OutputInterface $error ); |
|
30 | 30 | |
31 | 31 | public function section(): ConsoleSectionOutput; |
32 | 32 | } |
@@ -17,8 +17,7 @@ |
||
17 | 17 | * |
18 | 18 | * @author Dariusz Górecki <[email protected]> |
19 | 19 | */ |
20 | -interface ConsoleOutputInterface extends OutputInterface |
|
21 | -{ |
|
20 | +interface ConsoleOutputInterface extends OutputInterface { |
|
22 | 21 | /** |
23 | 22 | * Gets the OutputInterface for errors. |
24 | 23 | * |
@@ -29,138 +29,138 @@ |
||
29 | 29 | */ |
30 | 30 | class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface |
31 | 31 | { |
32 | - private $stderr; |
|
33 | - private $consoleSectionOutputs = []; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) |
|
37 | - * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) |
|
38 | - * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
|
39 | - */ |
|
40 | - public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
41 | - { |
|
42 | - parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter); |
|
43 | - |
|
44 | - if (null === $formatter) { |
|
45 | - // for BC reasons, stdErr has it own Formatter only when user don't inject a specific formatter. |
|
46 | - $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated); |
|
47 | - |
|
48 | - return; |
|
49 | - } |
|
50 | - |
|
51 | - $actualDecorated = $this->isDecorated(); |
|
52 | - $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter()); |
|
53 | - |
|
54 | - if (null === $decorated) { |
|
55 | - $this->setDecorated($actualDecorated && $this->stderr->isDecorated()); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Creates a new output section. |
|
61 | - */ |
|
62 | - public function section(): ConsoleSectionOutput |
|
63 | - { |
|
64 | - return new ConsoleSectionOutput($this->getStream(), $this->consoleSectionOutputs, $this->getVerbosity(), $this->isDecorated(), $this->getFormatter()); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * {@inheritdoc} |
|
69 | - */ |
|
70 | - public function setDecorated(bool $decorated) |
|
71 | - { |
|
72 | - parent::setDecorated($decorated); |
|
73 | - $this->stderr->setDecorated($decorated); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * {@inheritdoc} |
|
78 | - */ |
|
79 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
80 | - { |
|
81 | - parent::setFormatter($formatter); |
|
82 | - $this->stderr->setFormatter($formatter); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * {@inheritdoc} |
|
87 | - */ |
|
88 | - public function setVerbosity(int $level) |
|
89 | - { |
|
90 | - parent::setVerbosity($level); |
|
91 | - $this->stderr->setVerbosity($level); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * {@inheritdoc} |
|
96 | - */ |
|
97 | - public function getErrorOutput() |
|
98 | - { |
|
99 | - return $this->stderr; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * {@inheritdoc} |
|
104 | - */ |
|
105 | - public function setErrorOutput(OutputInterface $error) |
|
106 | - { |
|
107 | - $this->stderr = $error; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Returns true if current environment supports writing console output to |
|
112 | - * STDOUT. |
|
113 | - * |
|
114 | - * @return bool |
|
115 | - */ |
|
116 | - protected function hasStdoutSupport() |
|
117 | - { |
|
118 | - return false === $this->isRunningOS400(); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Returns true if current environment supports writing console output to |
|
123 | - * STDERR. |
|
124 | - * |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - protected function hasStderrSupport() |
|
128 | - { |
|
129 | - return false === $this->isRunningOS400(); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Checks if current executing environment is IBM iSeries (OS400), which |
|
134 | - * doesn't properly convert character-encodings between ASCII to EBCDIC. |
|
135 | - */ |
|
136 | - private function isRunningOS400(): bool |
|
137 | - { |
|
138 | - $checks = [ |
|
139 | - \function_exists('php_uname') ? php_uname('s') : '', |
|
140 | - getenv('OSTYPE'), |
|
141 | - \PHP_OS, |
|
142 | - ]; |
|
143 | - |
|
144 | - return false !== stripos(implode(';', $checks), 'OS400'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return resource |
|
149 | - */ |
|
150 | - private function openOutputStream() |
|
151 | - { |
|
152 | - if (!$this->hasStdoutSupport()) { |
|
153 | - return fopen('php://output', 'w'); |
|
154 | - } |
|
155 | - |
|
156 | - return @fopen('php://stdout', 'w') ?: fopen('php://output', 'w'); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return resource |
|
161 | - */ |
|
162 | - private function openErrorStream() |
|
163 | - { |
|
164 | - return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w'); |
|
165 | - } |
|
32 | + private $stderr; |
|
33 | + private $consoleSectionOutputs = []; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) |
|
37 | + * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) |
|
38 | + * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
|
39 | + */ |
|
40 | + public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
41 | + { |
|
42 | + parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter); |
|
43 | + |
|
44 | + if (null === $formatter) { |
|
45 | + // for BC reasons, stdErr has it own Formatter only when user don't inject a specific formatter. |
|
46 | + $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated); |
|
47 | + |
|
48 | + return; |
|
49 | + } |
|
50 | + |
|
51 | + $actualDecorated = $this->isDecorated(); |
|
52 | + $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter()); |
|
53 | + |
|
54 | + if (null === $decorated) { |
|
55 | + $this->setDecorated($actualDecorated && $this->stderr->isDecorated()); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Creates a new output section. |
|
61 | + */ |
|
62 | + public function section(): ConsoleSectionOutput |
|
63 | + { |
|
64 | + return new ConsoleSectionOutput($this->getStream(), $this->consoleSectionOutputs, $this->getVerbosity(), $this->isDecorated(), $this->getFormatter()); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * {@inheritdoc} |
|
69 | + */ |
|
70 | + public function setDecorated(bool $decorated) |
|
71 | + { |
|
72 | + parent::setDecorated($decorated); |
|
73 | + $this->stderr->setDecorated($decorated); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * {@inheritdoc} |
|
78 | + */ |
|
79 | + public function setFormatter(OutputFormatterInterface $formatter) |
|
80 | + { |
|
81 | + parent::setFormatter($formatter); |
|
82 | + $this->stderr->setFormatter($formatter); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * {@inheritdoc} |
|
87 | + */ |
|
88 | + public function setVerbosity(int $level) |
|
89 | + { |
|
90 | + parent::setVerbosity($level); |
|
91 | + $this->stderr->setVerbosity($level); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * {@inheritdoc} |
|
96 | + */ |
|
97 | + public function getErrorOutput() |
|
98 | + { |
|
99 | + return $this->stderr; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * {@inheritdoc} |
|
104 | + */ |
|
105 | + public function setErrorOutput(OutputInterface $error) |
|
106 | + { |
|
107 | + $this->stderr = $error; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Returns true if current environment supports writing console output to |
|
112 | + * STDOUT. |
|
113 | + * |
|
114 | + * @return bool |
|
115 | + */ |
|
116 | + protected function hasStdoutSupport() |
|
117 | + { |
|
118 | + return false === $this->isRunningOS400(); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Returns true if current environment supports writing console output to |
|
123 | + * STDERR. |
|
124 | + * |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + protected function hasStderrSupport() |
|
128 | + { |
|
129 | + return false === $this->isRunningOS400(); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Checks if current executing environment is IBM iSeries (OS400), which |
|
134 | + * doesn't properly convert character-encodings between ASCII to EBCDIC. |
|
135 | + */ |
|
136 | + private function isRunningOS400(): bool |
|
137 | + { |
|
138 | + $checks = [ |
|
139 | + \function_exists('php_uname') ? php_uname('s') : '', |
|
140 | + getenv('OSTYPE'), |
|
141 | + \PHP_OS, |
|
142 | + ]; |
|
143 | + |
|
144 | + return false !== stripos(implode(';', $checks), 'OS400'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return resource |
|
149 | + */ |
|
150 | + private function openOutputStream() |
|
151 | + { |
|
152 | + if (!$this->hasStdoutSupport()) { |
|
153 | + return fopen('php://output', 'w'); |
|
154 | + } |
|
155 | + |
|
156 | + return @fopen('php://stdout', 'w') ?: fopen('php://output', 'w'); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return resource |
|
161 | + */ |
|
162 | + private function openErrorStream() |
|
163 | + { |
|
164 | + return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w'); |
|
165 | + } |
|
166 | 166 | } |
@@ -30,29 +30,29 @@ discard block |
||
30 | 30 | class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface |
31 | 31 | { |
32 | 32 | private $stderr; |
33 | - private $consoleSectionOutputs = []; |
|
33 | + private $consoleSectionOutputs = [ ]; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) |
37 | 37 | * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) |
38 | 38 | * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
39 | 39 | */ |
40 | - public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
40 | + public function __construct( int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null ) |
|
41 | 41 | { |
42 | - parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter); |
|
42 | + parent::__construct( $this->openOutputStream(), $verbosity, $decorated, $formatter ); |
|
43 | 43 | |
44 | - if (null === $formatter) { |
|
44 | + if ( null === $formatter ) { |
|
45 | 45 | // for BC reasons, stdErr has it own Formatter only when user don't inject a specific formatter. |
46 | - $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated); |
|
46 | + $this->stderr = new StreamOutput( $this->openErrorStream(), $verbosity, $decorated ); |
|
47 | 47 | |
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | 51 | $actualDecorated = $this->isDecorated(); |
52 | - $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter()); |
|
52 | + $this->stderr = new StreamOutput( $this->openErrorStream(), $verbosity, $decorated, $this->getFormatter() ); |
|
53 | 53 | |
54 | - if (null === $decorated) { |
|
55 | - $this->setDecorated($actualDecorated && $this->stderr->isDecorated()); |
|
54 | + if ( null === $decorated ) { |
|
55 | + $this->setDecorated( $actualDecorated && $this->stderr->isDecorated() ); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -61,34 +61,34 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function section(): ConsoleSectionOutput |
63 | 63 | { |
64 | - return new ConsoleSectionOutput($this->getStream(), $this->consoleSectionOutputs, $this->getVerbosity(), $this->isDecorated(), $this->getFormatter()); |
|
64 | + return new ConsoleSectionOutput( $this->getStream(), $this->consoleSectionOutputs, $this->getVerbosity(), $this->isDecorated(), $this->getFormatter() ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * {@inheritdoc} |
69 | 69 | */ |
70 | - public function setDecorated(bool $decorated) |
|
70 | + public function setDecorated( bool $decorated ) |
|
71 | 71 | { |
72 | - parent::setDecorated($decorated); |
|
73 | - $this->stderr->setDecorated($decorated); |
|
72 | + parent::setDecorated( $decorated ); |
|
73 | + $this->stderr->setDecorated( $decorated ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * {@inheritdoc} |
78 | 78 | */ |
79 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
79 | + public function setFormatter( OutputFormatterInterface $formatter ) |
|
80 | 80 | { |
81 | - parent::setFormatter($formatter); |
|
82 | - $this->stderr->setFormatter($formatter); |
|
81 | + parent::setFormatter( $formatter ); |
|
82 | + $this->stderr->setFormatter( $formatter ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * {@inheritdoc} |
87 | 87 | */ |
88 | - public function setVerbosity(int $level) |
|
88 | + public function setVerbosity( int $level ) |
|
89 | 89 | { |
90 | - parent::setVerbosity($level); |
|
91 | - $this->stderr->setVerbosity($level); |
|
90 | + parent::setVerbosity( $level ); |
|
91 | + $this->stderr->setVerbosity( $level ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * {@inheritdoc} |
104 | 104 | */ |
105 | - public function setErrorOutput(OutputInterface $error) |
|
105 | + public function setErrorOutput( OutputInterface $error ) |
|
106 | 106 | { |
107 | 107 | $this->stderr = $error; |
108 | 108 | } |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | private function isRunningOS400(): bool |
137 | 137 | { |
138 | 138 | $checks = [ |
139 | - \function_exists('php_uname') ? php_uname('s') : '', |
|
140 | - getenv('OSTYPE'), |
|
139 | + \function_exists( 'php_uname' ) ? php_uname( 's' ) : '', |
|
140 | + getenv( 'OSTYPE' ), |
|
141 | 141 | \PHP_OS, |
142 | 142 | ]; |
143 | 143 | |
144 | - return false !== stripos(implode(';', $checks), 'OS400'); |
|
144 | + return false !== stripos( implode( ';', $checks ), 'OS400' ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | */ |
150 | 150 | private function openOutputStream() |
151 | 151 | { |
152 | - if (!$this->hasStdoutSupport()) { |
|
153 | - return fopen('php://output', 'w'); |
|
152 | + if ( ! $this->hasStdoutSupport() ) { |
|
153 | + return fopen( 'php://output', 'w' ); |
|
154 | 154 | } |
155 | 155 | |
156 | - return @fopen('php://stdout', 'w') ?: fopen('php://output', 'w'); |
|
156 | + return @fopen( 'php://stdout', 'w' ) ?: fopen( 'php://output', 'w' ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -161,6 +161,6 @@ discard block |
||
161 | 161 | */ |
162 | 162 | private function openErrorStream() |
163 | 163 | { |
164 | - return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w'); |
|
164 | + return fopen( $this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w' ); |
|
165 | 165 | } |
166 | 166 | } |
@@ -27,8 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @author Fabien Potencier <[email protected]> |
29 | 29 | */ |
30 | -class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface |
|
31 | -{ |
|
30 | +class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface { |
|
32 | 31 | private $stderr; |
33 | 32 | private $consoleSectionOutputs = []; |
34 | 33 | |
@@ -37,8 +36,7 @@ discard block |
||
37 | 36 | * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) |
38 | 37 | * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
39 | 38 | */ |
40 | - public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
41 | - { |
|
39 | + public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) { |
|
42 | 40 | parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter); |
43 | 41 | |
44 | 42 | if (null === $formatter) { |
@@ -67,8 +65,7 @@ discard block |
||
67 | 65 | /** |
68 | 66 | * {@inheritdoc} |
69 | 67 | */ |
70 | - public function setDecorated(bool $decorated) |
|
71 | - { |
|
68 | + public function setDecorated(bool $decorated) { |
|
72 | 69 | parent::setDecorated($decorated); |
73 | 70 | $this->stderr->setDecorated($decorated); |
74 | 71 | } |
@@ -76,8 +73,7 @@ discard block |
||
76 | 73 | /** |
77 | 74 | * {@inheritdoc} |
78 | 75 | */ |
79 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
80 | - { |
|
76 | + public function setFormatter(OutputFormatterInterface $formatter) { |
|
81 | 77 | parent::setFormatter($formatter); |
82 | 78 | $this->stderr->setFormatter($formatter); |
83 | 79 | } |
@@ -85,8 +81,7 @@ discard block |
||
85 | 81 | /** |
86 | 82 | * {@inheritdoc} |
87 | 83 | */ |
88 | - public function setVerbosity(int $level) |
|
89 | - { |
|
84 | + public function setVerbosity(int $level) { |
|
90 | 85 | parent::setVerbosity($level); |
91 | 86 | $this->stderr->setVerbosity($level); |
92 | 87 | } |
@@ -94,16 +89,14 @@ discard block |
||
94 | 89 | /** |
95 | 90 | * {@inheritdoc} |
96 | 91 | */ |
97 | - public function getErrorOutput() |
|
98 | - { |
|
92 | + public function getErrorOutput() { |
|
99 | 93 | return $this->stderr; |
100 | 94 | } |
101 | 95 | |
102 | 96 | /** |
103 | 97 | * {@inheritdoc} |
104 | 98 | */ |
105 | - public function setErrorOutput(OutputInterface $error) |
|
106 | - { |
|
99 | + public function setErrorOutput(OutputInterface $error) { |
|
107 | 100 | $this->stderr = $error; |
108 | 101 | } |
109 | 102 | |
@@ -113,8 +106,7 @@ discard block |
||
113 | 106 | * |
114 | 107 | * @return bool |
115 | 108 | */ |
116 | - protected function hasStdoutSupport() |
|
117 | - { |
|
109 | + protected function hasStdoutSupport() { |
|
118 | 110 | return false === $this->isRunningOS400(); |
119 | 111 | } |
120 | 112 | |
@@ -124,8 +116,7 @@ discard block |
||
124 | 116 | * |
125 | 117 | * @return bool |
126 | 118 | */ |
127 | - protected function hasStderrSupport() |
|
128 | - { |
|
119 | + protected function hasStderrSupport() { |
|
129 | 120 | return false === $this->isRunningOS400(); |
130 | 121 | } |
131 | 122 | |
@@ -147,8 +138,7 @@ discard block |
||
147 | 138 | /** |
148 | 139 | * @return resource |
149 | 140 | */ |
150 | - private function openOutputStream() |
|
151 | - { |
|
141 | + private function openOutputStream() { |
|
152 | 142 | if (!$this->hasStdoutSupport()) { |
153 | 143 | return fopen('php://output', 'w'); |
154 | 144 | } |
@@ -159,8 +149,7 @@ discard block |
||
159 | 149 | /** |
160 | 150 | * @return resource |
161 | 151 | */ |
162 | - private function openErrorStream() |
|
163 | - { |
|
152 | + private function openErrorStream() { |
|
164 | 153 | return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w'); |
165 | 154 | } |
166 | 155 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param bool $newline Whether to add a newline |
38 | 38 | * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL |
39 | 39 | */ |
40 | - public function write($messages, bool $newline = false, int $options = 0); |
|
40 | + public function write( $messages, bool $newline = false, int $options = 0 ); |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Writes a message to the output and adds a newline at the end. |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | * @param string|iterable $messages The message as an iterable of strings or a single string |
46 | 46 | * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL |
47 | 47 | */ |
48 | - public function writeln($messages, int $options = 0); |
|
48 | + public function writeln( $messages, int $options = 0 ); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Sets the verbosity of the output. |
52 | 52 | */ |
53 | - public function setVerbosity(int $level); |
|
53 | + public function setVerbosity( int $level ); |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Gets the current verbosity of the output. |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * Sets the decorated flag. |
92 | 92 | */ |
93 | - public function setDecorated(bool $decorated); |
|
93 | + public function setDecorated( bool $decorated ); |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Gets the decorated flag. |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function isDecorated(); |
101 | 101 | |
102 | - public function setFormatter(OutputFormatterInterface $formatter); |
|
102 | + public function setFormatter( OutputFormatterInterface $formatter ); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Returns current output formatter instance. |
@@ -18,8 +18,7 @@ |
||
18 | 18 | * |
19 | 19 | * @author Fabien Potencier <[email protected]> |
20 | 20 | */ |
21 | -interface OutputInterface |
|
22 | -{ |
|
21 | +interface OutputInterface { |
|
23 | 22 | public const VERBOSITY_QUIET = 16; |
24 | 23 | public const VERBOSITY_NORMAL = 32; |
25 | 24 | public const VERBOSITY_VERBOSE = 64; |
@@ -20,91 +20,91 @@ |
||
20 | 20 | */ |
21 | 21 | interface OutputInterface |
22 | 22 | { |
23 | - public const VERBOSITY_QUIET = 16; |
|
24 | - public const VERBOSITY_NORMAL = 32; |
|
25 | - public const VERBOSITY_VERBOSE = 64; |
|
26 | - public const VERBOSITY_VERY_VERBOSE = 128; |
|
27 | - public const VERBOSITY_DEBUG = 256; |
|
28 | - |
|
29 | - public const OUTPUT_NORMAL = 1; |
|
30 | - public const OUTPUT_RAW = 2; |
|
31 | - public const OUTPUT_PLAIN = 4; |
|
32 | - |
|
33 | - /** |
|
34 | - * Writes a message to the output. |
|
35 | - * |
|
36 | - * @param string|iterable $messages The message as an iterable of strings or a single string |
|
37 | - * @param bool $newline Whether to add a newline |
|
38 | - * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL |
|
39 | - */ |
|
40 | - public function write($messages, bool $newline = false, int $options = 0); |
|
41 | - |
|
42 | - /** |
|
43 | - * Writes a message to the output and adds a newline at the end. |
|
44 | - * |
|
45 | - * @param string|iterable $messages The message as an iterable of strings or a single string |
|
46 | - * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL |
|
47 | - */ |
|
48 | - public function writeln($messages, int $options = 0); |
|
49 | - |
|
50 | - /** |
|
51 | - * Sets the verbosity of the output. |
|
52 | - */ |
|
53 | - public function setVerbosity(int $level); |
|
54 | - |
|
55 | - /** |
|
56 | - * Gets the current verbosity of the output. |
|
57 | - * |
|
58 | - * @return int |
|
59 | - */ |
|
60 | - public function getVerbosity(); |
|
61 | - |
|
62 | - /** |
|
63 | - * Returns whether verbosity is quiet (-q). |
|
64 | - * |
|
65 | - * @return bool |
|
66 | - */ |
|
67 | - public function isQuiet(); |
|
68 | - |
|
69 | - /** |
|
70 | - * Returns whether verbosity is verbose (-v). |
|
71 | - * |
|
72 | - * @return bool |
|
73 | - */ |
|
74 | - public function isVerbose(); |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns whether verbosity is very verbose (-vv). |
|
78 | - * |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - public function isVeryVerbose(); |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns whether verbosity is debug (-vvv). |
|
85 | - * |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function isDebug(); |
|
89 | - |
|
90 | - /** |
|
91 | - * Sets the decorated flag. |
|
92 | - */ |
|
93 | - public function setDecorated(bool $decorated); |
|
94 | - |
|
95 | - /** |
|
96 | - * Gets the decorated flag. |
|
97 | - * |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function isDecorated(); |
|
101 | - |
|
102 | - public function setFormatter(OutputFormatterInterface $formatter); |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns current output formatter instance. |
|
106 | - * |
|
107 | - * @return OutputFormatterInterface |
|
108 | - */ |
|
109 | - public function getFormatter(); |
|
23 | + public const VERBOSITY_QUIET = 16; |
|
24 | + public const VERBOSITY_NORMAL = 32; |
|
25 | + public const VERBOSITY_VERBOSE = 64; |
|
26 | + public const VERBOSITY_VERY_VERBOSE = 128; |
|
27 | + public const VERBOSITY_DEBUG = 256; |
|
28 | + |
|
29 | + public const OUTPUT_NORMAL = 1; |
|
30 | + public const OUTPUT_RAW = 2; |
|
31 | + public const OUTPUT_PLAIN = 4; |
|
32 | + |
|
33 | + /** |
|
34 | + * Writes a message to the output. |
|
35 | + * |
|
36 | + * @param string|iterable $messages The message as an iterable of strings or a single string |
|
37 | + * @param bool $newline Whether to add a newline |
|
38 | + * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL |
|
39 | + */ |
|
40 | + public function write($messages, bool $newline = false, int $options = 0); |
|
41 | + |
|
42 | + /** |
|
43 | + * Writes a message to the output and adds a newline at the end. |
|
44 | + * |
|
45 | + * @param string|iterable $messages The message as an iterable of strings or a single string |
|
46 | + * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL |
|
47 | + */ |
|
48 | + public function writeln($messages, int $options = 0); |
|
49 | + |
|
50 | + /** |
|
51 | + * Sets the verbosity of the output. |
|
52 | + */ |
|
53 | + public function setVerbosity(int $level); |
|
54 | + |
|
55 | + /** |
|
56 | + * Gets the current verbosity of the output. |
|
57 | + * |
|
58 | + * @return int |
|
59 | + */ |
|
60 | + public function getVerbosity(); |
|
61 | + |
|
62 | + /** |
|
63 | + * Returns whether verbosity is quiet (-q). |
|
64 | + * |
|
65 | + * @return bool |
|
66 | + */ |
|
67 | + public function isQuiet(); |
|
68 | + |
|
69 | + /** |
|
70 | + * Returns whether verbosity is verbose (-v). |
|
71 | + * |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | + public function isVerbose(); |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns whether verbosity is very verbose (-vv). |
|
78 | + * |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + public function isVeryVerbose(); |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns whether verbosity is debug (-vvv). |
|
85 | + * |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function isDebug(); |
|
89 | + |
|
90 | + /** |
|
91 | + * Sets the decorated flag. |
|
92 | + */ |
|
93 | + public function setDecorated(bool $decorated); |
|
94 | + |
|
95 | + /** |
|
96 | + * Gets the decorated flag. |
|
97 | + * |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function isDecorated(); |
|
101 | + |
|
102 | + public function setFormatter(OutputFormatterInterface $formatter); |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns current output formatter instance. |
|
106 | + * |
|
107 | + * @return OutputFormatterInterface |
|
108 | + */ |
|
109 | + public function getFormatter(); |
|
110 | 110 | } |
@@ -39,19 +39,19 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @throws InvalidArgumentException When first argument is not a real stream |
41 | 41 | */ |
42 | - public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
42 | + public function __construct( $stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null ) |
|
43 | 43 | { |
44 | - if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) { |
|
45 | - throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); |
|
44 | + if ( ! \is_resource( $stream ) || 'stream' !== get_resource_type( $stream ) ) { |
|
45 | + throw new InvalidArgumentException( 'The StreamOutput class needs a stream as its first argument.' ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $this->stream = $stream; |
49 | 49 | |
50 | - if (null === $decorated) { |
|
50 | + if ( null === $decorated ) { |
|
51 | 51 | $decorated = $this->hasColorSupport(); |
52 | 52 | } |
53 | 53 | |
54 | - parent::__construct($verbosity, $decorated, $formatter); |
|
54 | + parent::__construct( $verbosity, $decorated, $formatter ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | /** |
68 | 68 | * {@inheritdoc} |
69 | 69 | */ |
70 | - protected function doWrite(string $message, bool $newline) |
|
70 | + protected function doWrite( string $message, bool $newline ) |
|
71 | 71 | { |
72 | - if ($newline) { |
|
72 | + if ( $newline ) { |
|
73 | 73 | $message .= \PHP_EOL; |
74 | 74 | } |
75 | 75 | |
76 | - @fwrite($this->stream, $message); |
|
76 | + @fwrite( $this->stream, $message ); |
|
77 | 77 | |
78 | - fflush($this->stream); |
|
78 | + fflush( $this->stream ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -94,22 +94,22 @@ discard block |
||
94 | 94 | protected function hasColorSupport() |
95 | 95 | { |
96 | 96 | // Follow https://no-color.org/ |
97 | - if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) { |
|
97 | + if ( isset( $_SERVER[ 'NO_COLOR' ] ) || false !== getenv( 'NO_COLOR' ) ) { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
101 | - if ('Hyper' === getenv('TERM_PROGRAM')) { |
|
101 | + if ( 'Hyper' === getenv( 'TERM_PROGRAM' ) ) { |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | |
105 | - if (\DIRECTORY_SEPARATOR === '\\') { |
|
106 | - return (\function_exists('sapi_windows_vt100_support') |
|
107 | - && @sapi_windows_vt100_support($this->stream)) |
|
108 | - || false !== getenv('ANSICON') |
|
109 | - || 'ON' === getenv('ConEmuANSI') |
|
110 | - || 'xterm' === getenv('TERM'); |
|
105 | + if ( \DIRECTORY_SEPARATOR === '\\' ) { |
|
106 | + return ( \function_exists( 'sapi_windows_vt100_support' ) |
|
107 | + && @sapi_windows_vt100_support( $this->stream ) ) |
|
108 | + || false !== getenv( 'ANSICON' ) |
|
109 | + || 'ON' === getenv( 'ConEmuANSI' ) |
|
110 | + || 'xterm' === getenv( 'TERM' ); |
|
111 | 111 | } |
112 | 112 | |
113 | - return stream_isatty($this->stream); |
|
113 | + return stream_isatty( $this->stream ); |
|
114 | 114 | } |
115 | 115 | } |
@@ -29,87 +29,87 @@ |
||
29 | 29 | */ |
30 | 30 | class StreamOutput extends Output |
31 | 31 | { |
32 | - private $stream; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param resource $stream A stream resource |
|
36 | - * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) |
|
37 | - * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) |
|
38 | - * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
|
39 | - * |
|
40 | - * @throws InvalidArgumentException When first argument is not a real stream |
|
41 | - */ |
|
42 | - public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
43 | - { |
|
44 | - if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) { |
|
45 | - throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); |
|
46 | - } |
|
47 | - |
|
48 | - $this->stream = $stream; |
|
49 | - |
|
50 | - if (null === $decorated) { |
|
51 | - $decorated = $this->hasColorSupport(); |
|
52 | - } |
|
53 | - |
|
54 | - parent::__construct($verbosity, $decorated, $formatter); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Gets the stream attached to this StreamOutput instance. |
|
59 | - * |
|
60 | - * @return resource |
|
61 | - */ |
|
62 | - public function getStream() |
|
63 | - { |
|
64 | - return $this->stream; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * {@inheritdoc} |
|
69 | - */ |
|
70 | - protected function doWrite(string $message, bool $newline) |
|
71 | - { |
|
72 | - if ($newline) { |
|
73 | - $message .= \PHP_EOL; |
|
74 | - } |
|
75 | - |
|
76 | - @fwrite($this->stream, $message); |
|
77 | - |
|
78 | - fflush($this->stream); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Returns true if the stream supports colorization. |
|
83 | - * |
|
84 | - * Colorization is disabled if not supported by the stream: |
|
85 | - * |
|
86 | - * This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo |
|
87 | - * terminals via named pipes, so we can only check the environment. |
|
88 | - * |
|
89 | - * Reference: Composer\XdebugHandler\Process::supportsColor |
|
90 | - * https://github.com/composer/xdebug-handler |
|
91 | - * |
|
92 | - * @return bool true if the stream supports colorization, false otherwise |
|
93 | - */ |
|
94 | - protected function hasColorSupport() |
|
95 | - { |
|
96 | - // Follow https://no-color.org/ |
|
97 | - if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) { |
|
98 | - return false; |
|
99 | - } |
|
100 | - |
|
101 | - if ('Hyper' === getenv('TERM_PROGRAM')) { |
|
102 | - return true; |
|
103 | - } |
|
104 | - |
|
105 | - if (\DIRECTORY_SEPARATOR === '\\') { |
|
106 | - return (\function_exists('sapi_windows_vt100_support') |
|
107 | - && @sapi_windows_vt100_support($this->stream)) |
|
108 | - || false !== getenv('ANSICON') |
|
109 | - || 'ON' === getenv('ConEmuANSI') |
|
110 | - || 'xterm' === getenv('TERM'); |
|
111 | - } |
|
112 | - |
|
113 | - return stream_isatty($this->stream); |
|
114 | - } |
|
32 | + private $stream; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param resource $stream A stream resource |
|
36 | + * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) |
|
37 | + * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) |
|
38 | + * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
|
39 | + * |
|
40 | + * @throws InvalidArgumentException When first argument is not a real stream |
|
41 | + */ |
|
42 | + public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
43 | + { |
|
44 | + if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) { |
|
45 | + throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); |
|
46 | + } |
|
47 | + |
|
48 | + $this->stream = $stream; |
|
49 | + |
|
50 | + if (null === $decorated) { |
|
51 | + $decorated = $this->hasColorSupport(); |
|
52 | + } |
|
53 | + |
|
54 | + parent::__construct($verbosity, $decorated, $formatter); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Gets the stream attached to this StreamOutput instance. |
|
59 | + * |
|
60 | + * @return resource |
|
61 | + */ |
|
62 | + public function getStream() |
|
63 | + { |
|
64 | + return $this->stream; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * {@inheritdoc} |
|
69 | + */ |
|
70 | + protected function doWrite(string $message, bool $newline) |
|
71 | + { |
|
72 | + if ($newline) { |
|
73 | + $message .= \PHP_EOL; |
|
74 | + } |
|
75 | + |
|
76 | + @fwrite($this->stream, $message); |
|
77 | + |
|
78 | + fflush($this->stream); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Returns true if the stream supports colorization. |
|
83 | + * |
|
84 | + * Colorization is disabled if not supported by the stream: |
|
85 | + * |
|
86 | + * This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo |
|
87 | + * terminals via named pipes, so we can only check the environment. |
|
88 | + * |
|
89 | + * Reference: Composer\XdebugHandler\Process::supportsColor |
|
90 | + * https://github.com/composer/xdebug-handler |
|
91 | + * |
|
92 | + * @return bool true if the stream supports colorization, false otherwise |
|
93 | + */ |
|
94 | + protected function hasColorSupport() |
|
95 | + { |
|
96 | + // Follow https://no-color.org/ |
|
97 | + if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) { |
|
98 | + return false; |
|
99 | + } |
|
100 | + |
|
101 | + if ('Hyper' === getenv('TERM_PROGRAM')) { |
|
102 | + return true; |
|
103 | + } |
|
104 | + |
|
105 | + if (\DIRECTORY_SEPARATOR === '\\') { |
|
106 | + return (\function_exists('sapi_windows_vt100_support') |
|
107 | + && @sapi_windows_vt100_support($this->stream)) |
|
108 | + || false !== getenv('ANSICON') |
|
109 | + || 'ON' === getenv('ConEmuANSI') |
|
110 | + || 'xterm' === getenv('TERM'); |
|
111 | + } |
|
112 | + |
|
113 | + return stream_isatty($this->stream); |
|
114 | + } |
|
115 | 115 | } |
@@ -27,8 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @author Fabien Potencier <[email protected]> |
29 | 29 | */ |
30 | -class StreamOutput extends Output |
|
31 | -{ |
|
30 | +class StreamOutput extends Output { |
|
32 | 31 | private $stream; |
33 | 32 | |
34 | 33 | /** |
@@ -39,8 +38,7 @@ discard block |
||
39 | 38 | * |
40 | 39 | * @throws InvalidArgumentException When first argument is not a real stream |
41 | 40 | */ |
42 | - public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
43 | - { |
|
41 | + public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) { |
|
44 | 42 | if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) { |
45 | 43 | throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); |
46 | 44 | } |
@@ -59,16 +57,14 @@ discard block |
||
59 | 57 | * |
60 | 58 | * @return resource |
61 | 59 | */ |
62 | - public function getStream() |
|
63 | - { |
|
60 | + public function getStream() { |
|
64 | 61 | return $this->stream; |
65 | 62 | } |
66 | 63 | |
67 | 64 | /** |
68 | 65 | * {@inheritdoc} |
69 | 66 | */ |
70 | - protected function doWrite(string $message, bool $newline) |
|
71 | - { |
|
67 | + protected function doWrite(string $message, bool $newline) { |
|
72 | 68 | if ($newline) { |
73 | 69 | $message .= \PHP_EOL; |
74 | 70 | } |
@@ -91,8 +87,7 @@ discard block |
||
91 | 87 | * |
92 | 88 | * @return bool true if the stream supports colorization, false otherwise |
93 | 89 | */ |
94 | - protected function hasColorSupport() |
|
95 | - { |
|
90 | + protected function hasColorSupport() { |
|
96 | 91 | // Follow https://no-color.org/ |
97 | 92 | if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) { |
98 | 93 | return false; |
@@ -21,123 +21,123 @@ |
||
21 | 21 | */ |
22 | 22 | class ConsoleSectionOutput extends StreamOutput |
23 | 23 | { |
24 | - private $content = []; |
|
25 | - private $lines = 0; |
|
26 | - private $sections; |
|
27 | - private $terminal; |
|
28 | - |
|
29 | - /** |
|
30 | - * @param resource $stream |
|
31 | - * @param ConsoleSectionOutput[] $sections |
|
32 | - */ |
|
33 | - public function __construct($stream, array &$sections, int $verbosity, bool $decorated, OutputFormatterInterface $formatter) |
|
34 | - { |
|
35 | - parent::__construct($stream, $verbosity, $decorated, $formatter); |
|
36 | - array_unshift($sections, $this); |
|
37 | - $this->sections = &$sections; |
|
38 | - $this->terminal = new Terminal(); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Clears previous output for this section. |
|
43 | - * |
|
44 | - * @param int $lines Number of lines to clear. If null, then the entire output of this section is cleared |
|
45 | - */ |
|
46 | - public function clear(int $lines = null) |
|
47 | - { |
|
48 | - if (empty($this->content) || !$this->isDecorated()) { |
|
49 | - return; |
|
50 | - } |
|
51 | - |
|
52 | - if ($lines) { |
|
53 | - array_splice($this->content, -($lines * 2)); // Multiply lines by 2 to cater for each new line added between content |
|
54 | - } else { |
|
55 | - $lines = $this->lines; |
|
56 | - $this->content = []; |
|
57 | - } |
|
58 | - |
|
59 | - $this->lines -= $lines; |
|
60 | - |
|
61 | - parent::doWrite($this->popStreamContentUntilCurrentSection($lines), false); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Overwrites the previous output with a new message. |
|
66 | - * |
|
67 | - * @param array|string $message |
|
68 | - */ |
|
69 | - public function overwrite($message) |
|
70 | - { |
|
71 | - $this->clear(); |
|
72 | - $this->writeln($message); |
|
73 | - } |
|
74 | - |
|
75 | - public function getContent(): string |
|
76 | - { |
|
77 | - return implode('', $this->content); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @internal |
|
82 | - */ |
|
83 | - public function addContent(string $input) |
|
84 | - { |
|
85 | - foreach (explode(\PHP_EOL, $input) as $lineContent) { |
|
86 | - $this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1; |
|
87 | - $this->content[] = $lineContent; |
|
88 | - $this->content[] = \PHP_EOL; |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * {@inheritdoc} |
|
94 | - */ |
|
95 | - protected function doWrite(string $message, bool $newline) |
|
96 | - { |
|
97 | - if (!$this->isDecorated()) { |
|
98 | - parent::doWrite($message, $newline); |
|
99 | - |
|
100 | - return; |
|
101 | - } |
|
102 | - |
|
103 | - $erasedContent = $this->popStreamContentUntilCurrentSection(); |
|
104 | - |
|
105 | - $this->addContent($message); |
|
106 | - |
|
107 | - parent::doWrite($message, true); |
|
108 | - parent::doWrite($erasedContent, false); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * At initial stage, cursor is at the end of stream output. This method makes cursor crawl upwards until it hits |
|
113 | - * current section. Then it erases content it crawled through. Optionally, it erases part of current section too. |
|
114 | - */ |
|
115 | - private function popStreamContentUntilCurrentSection(int $numberOfLinesToClearFromCurrentSection = 0): string |
|
116 | - { |
|
117 | - $numberOfLinesToClear = $numberOfLinesToClearFromCurrentSection; |
|
118 | - $erasedContent = []; |
|
119 | - |
|
120 | - foreach ($this->sections as $section) { |
|
121 | - if ($section === $this) { |
|
122 | - break; |
|
123 | - } |
|
124 | - |
|
125 | - $numberOfLinesToClear += $section->lines; |
|
126 | - $erasedContent[] = $section->getContent(); |
|
127 | - } |
|
128 | - |
|
129 | - if ($numberOfLinesToClear > 0) { |
|
130 | - // move cursor up n lines |
|
131 | - parent::doWrite(sprintf("\x1b[%dA", $numberOfLinesToClear), false); |
|
132 | - // erase to end of screen |
|
133 | - parent::doWrite("\x1b[0J", false); |
|
134 | - } |
|
135 | - |
|
136 | - return implode('', array_reverse($erasedContent)); |
|
137 | - } |
|
138 | - |
|
139 | - private function getDisplayLength(string $text): int |
|
140 | - { |
|
141 | - return Helper::width(Helper::removeDecoration($this->getFormatter(), str_replace("\t", ' ', $text))); |
|
142 | - } |
|
24 | + private $content = []; |
|
25 | + private $lines = 0; |
|
26 | + private $sections; |
|
27 | + private $terminal; |
|
28 | + |
|
29 | + /** |
|
30 | + * @param resource $stream |
|
31 | + * @param ConsoleSectionOutput[] $sections |
|
32 | + */ |
|
33 | + public function __construct($stream, array &$sections, int $verbosity, bool $decorated, OutputFormatterInterface $formatter) |
|
34 | + { |
|
35 | + parent::__construct($stream, $verbosity, $decorated, $formatter); |
|
36 | + array_unshift($sections, $this); |
|
37 | + $this->sections = &$sections; |
|
38 | + $this->terminal = new Terminal(); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Clears previous output for this section. |
|
43 | + * |
|
44 | + * @param int $lines Number of lines to clear. If null, then the entire output of this section is cleared |
|
45 | + */ |
|
46 | + public function clear(int $lines = null) |
|
47 | + { |
|
48 | + if (empty($this->content) || !$this->isDecorated()) { |
|
49 | + return; |
|
50 | + } |
|
51 | + |
|
52 | + if ($lines) { |
|
53 | + array_splice($this->content, -($lines * 2)); // Multiply lines by 2 to cater for each new line added between content |
|
54 | + } else { |
|
55 | + $lines = $this->lines; |
|
56 | + $this->content = []; |
|
57 | + } |
|
58 | + |
|
59 | + $this->lines -= $lines; |
|
60 | + |
|
61 | + parent::doWrite($this->popStreamContentUntilCurrentSection($lines), false); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Overwrites the previous output with a new message. |
|
66 | + * |
|
67 | + * @param array|string $message |
|
68 | + */ |
|
69 | + public function overwrite($message) |
|
70 | + { |
|
71 | + $this->clear(); |
|
72 | + $this->writeln($message); |
|
73 | + } |
|
74 | + |
|
75 | + public function getContent(): string |
|
76 | + { |
|
77 | + return implode('', $this->content); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @internal |
|
82 | + */ |
|
83 | + public function addContent(string $input) |
|
84 | + { |
|
85 | + foreach (explode(\PHP_EOL, $input) as $lineContent) { |
|
86 | + $this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1; |
|
87 | + $this->content[] = $lineContent; |
|
88 | + $this->content[] = \PHP_EOL; |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * {@inheritdoc} |
|
94 | + */ |
|
95 | + protected function doWrite(string $message, bool $newline) |
|
96 | + { |
|
97 | + if (!$this->isDecorated()) { |
|
98 | + parent::doWrite($message, $newline); |
|
99 | + |
|
100 | + return; |
|
101 | + } |
|
102 | + |
|
103 | + $erasedContent = $this->popStreamContentUntilCurrentSection(); |
|
104 | + |
|
105 | + $this->addContent($message); |
|
106 | + |
|
107 | + parent::doWrite($message, true); |
|
108 | + parent::doWrite($erasedContent, false); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * At initial stage, cursor is at the end of stream output. This method makes cursor crawl upwards until it hits |
|
113 | + * current section. Then it erases content it crawled through. Optionally, it erases part of current section too. |
|
114 | + */ |
|
115 | + private function popStreamContentUntilCurrentSection(int $numberOfLinesToClearFromCurrentSection = 0): string |
|
116 | + { |
|
117 | + $numberOfLinesToClear = $numberOfLinesToClearFromCurrentSection; |
|
118 | + $erasedContent = []; |
|
119 | + |
|
120 | + foreach ($this->sections as $section) { |
|
121 | + if ($section === $this) { |
|
122 | + break; |
|
123 | + } |
|
124 | + |
|
125 | + $numberOfLinesToClear += $section->lines; |
|
126 | + $erasedContent[] = $section->getContent(); |
|
127 | + } |
|
128 | + |
|
129 | + if ($numberOfLinesToClear > 0) { |
|
130 | + // move cursor up n lines |
|
131 | + parent::doWrite(sprintf("\x1b[%dA", $numberOfLinesToClear), false); |
|
132 | + // erase to end of screen |
|
133 | + parent::doWrite("\x1b[0J", false); |
|
134 | + } |
|
135 | + |
|
136 | + return implode('', array_reverse($erasedContent)); |
|
137 | + } |
|
138 | + |
|
139 | + private function getDisplayLength(string $text): int |
|
140 | + { |
|
141 | + return Helper::width(Helper::removeDecoration($this->getFormatter(), str_replace("\t", ' ', $text))); |
|
142 | + } |
|
143 | 143 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class ConsoleSectionOutput extends StreamOutput |
23 | 23 | { |
24 | - private $content = []; |
|
24 | + private $content = [ ]; |
|
25 | 25 | private $lines = 0; |
26 | 26 | private $sections; |
27 | 27 | private $terminal; |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | * @param resource $stream |
31 | 31 | * @param ConsoleSectionOutput[] $sections |
32 | 32 | */ |
33 | - public function __construct($stream, array &$sections, int $verbosity, bool $decorated, OutputFormatterInterface $formatter) |
|
33 | + public function __construct( $stream, array &$sections, int $verbosity, bool $decorated, OutputFormatterInterface $formatter ) |
|
34 | 34 | { |
35 | - parent::__construct($stream, $verbosity, $decorated, $formatter); |
|
36 | - array_unshift($sections, $this); |
|
35 | + parent::__construct( $stream, $verbosity, $decorated, $formatter ); |
|
36 | + array_unshift( $sections, $this ); |
|
37 | 37 | $this->sections = &$sections; |
38 | 38 | $this->terminal = new Terminal(); |
39 | 39 | } |
@@ -43,22 +43,22 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param int $lines Number of lines to clear. If null, then the entire output of this section is cleared |
45 | 45 | */ |
46 | - public function clear(int $lines = null) |
|
46 | + public function clear( int $lines = null ) |
|
47 | 47 | { |
48 | - if (empty($this->content) || !$this->isDecorated()) { |
|
48 | + if ( empty( $this->content ) || ! $this->isDecorated() ) { |
|
49 | 49 | return; |
50 | 50 | } |
51 | 51 | |
52 | - if ($lines) { |
|
53 | - array_splice($this->content, -($lines * 2)); // Multiply lines by 2 to cater for each new line added between content |
|
52 | + if ( $lines ) { |
|
53 | + array_splice( $this->content, -( $lines * 2 ) ); // Multiply lines by 2 to cater for each new line added between content |
|
54 | 54 | } else { |
55 | 55 | $lines = $this->lines; |
56 | - $this->content = []; |
|
56 | + $this->content = [ ]; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->lines -= $lines; |
60 | 60 | |
61 | - parent::doWrite($this->popStreamContentUntilCurrentSection($lines), false); |
|
61 | + parent::doWrite( $this->popStreamContentUntilCurrentSection( $lines ), false ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -66,78 +66,78 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @param array|string $message |
68 | 68 | */ |
69 | - public function overwrite($message) |
|
69 | + public function overwrite( $message ) |
|
70 | 70 | { |
71 | 71 | $this->clear(); |
72 | - $this->writeln($message); |
|
72 | + $this->writeln( $message ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function getContent(): string |
76 | 76 | { |
77 | - return implode('', $this->content); |
|
77 | + return implode( '', $this->content ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * @internal |
82 | 82 | */ |
83 | - public function addContent(string $input) |
|
83 | + public function addContent( string $input ) |
|
84 | 84 | { |
85 | - foreach (explode(\PHP_EOL, $input) as $lineContent) { |
|
86 | - $this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1; |
|
87 | - $this->content[] = $lineContent; |
|
88 | - $this->content[] = \PHP_EOL; |
|
85 | + foreach ( explode( \PHP_EOL, $input ) as $lineContent ) { |
|
86 | + $this->lines += ceil( $this->getDisplayLength( $lineContent ) / $this->terminal->getWidth() ) ?: 1; |
|
87 | + $this->content[ ] = $lineContent; |
|
88 | + $this->content[ ] = \PHP_EOL; |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * {@inheritdoc} |
94 | 94 | */ |
95 | - protected function doWrite(string $message, bool $newline) |
|
95 | + protected function doWrite( string $message, bool $newline ) |
|
96 | 96 | { |
97 | - if (!$this->isDecorated()) { |
|
98 | - parent::doWrite($message, $newline); |
|
97 | + if ( ! $this->isDecorated() ) { |
|
98 | + parent::doWrite( $message, $newline ); |
|
99 | 99 | |
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | 103 | $erasedContent = $this->popStreamContentUntilCurrentSection(); |
104 | 104 | |
105 | - $this->addContent($message); |
|
105 | + $this->addContent( $message ); |
|
106 | 106 | |
107 | - parent::doWrite($message, true); |
|
108 | - parent::doWrite($erasedContent, false); |
|
107 | + parent::doWrite( $message, true ); |
|
108 | + parent::doWrite( $erasedContent, false ); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | 112 | * At initial stage, cursor is at the end of stream output. This method makes cursor crawl upwards until it hits |
113 | 113 | * current section. Then it erases content it crawled through. Optionally, it erases part of current section too. |
114 | 114 | */ |
115 | - private function popStreamContentUntilCurrentSection(int $numberOfLinesToClearFromCurrentSection = 0): string |
|
115 | + private function popStreamContentUntilCurrentSection( int $numberOfLinesToClearFromCurrentSection = 0 ): string |
|
116 | 116 | { |
117 | 117 | $numberOfLinesToClear = $numberOfLinesToClearFromCurrentSection; |
118 | - $erasedContent = []; |
|
118 | + $erasedContent = [ ]; |
|
119 | 119 | |
120 | - foreach ($this->sections as $section) { |
|
121 | - if ($section === $this) { |
|
120 | + foreach ( $this->sections as $section ) { |
|
121 | + if ( $section === $this ) { |
|
122 | 122 | break; |
123 | 123 | } |
124 | 124 | |
125 | 125 | $numberOfLinesToClear += $section->lines; |
126 | - $erasedContent[] = $section->getContent(); |
|
126 | + $erasedContent[ ] = $section->getContent(); |
|
127 | 127 | } |
128 | 128 | |
129 | - if ($numberOfLinesToClear > 0) { |
|
129 | + if ( $numberOfLinesToClear > 0 ) { |
|
130 | 130 | // move cursor up n lines |
131 | - parent::doWrite(sprintf("\x1b[%dA", $numberOfLinesToClear), false); |
|
131 | + parent::doWrite( sprintf( "\x1b[%dA", $numberOfLinesToClear ), false ); |
|
132 | 132 | // erase to end of screen |
133 | - parent::doWrite("\x1b[0J", false); |
|
133 | + parent::doWrite( "\x1b[0J", false ); |
|
134 | 134 | } |
135 | 135 | |
136 | - return implode('', array_reverse($erasedContent)); |
|
136 | + return implode( '', array_reverse( $erasedContent ) ); |
|
137 | 137 | } |
138 | 138 | |
139 | - private function getDisplayLength(string $text): int |
|
139 | + private function getDisplayLength( string $text ): int |
|
140 | 140 | { |
141 | - return Helper::width(Helper::removeDecoration($this->getFormatter(), str_replace("\t", ' ', $text))); |
|
141 | + return Helper::width( Helper::removeDecoration( $this->getFormatter(), str_replace( "\t", ' ', $text ) ) ); |
|
142 | 142 | } |
143 | 143 | } |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | * @author Pierre du Plessis <[email protected]> |
20 | 20 | * @author Gabriel Ostrolucký <[email protected]> |
21 | 21 | */ |
22 | -class ConsoleSectionOutput extends StreamOutput |
|
23 | -{ |
|
22 | +class ConsoleSectionOutput extends StreamOutput { |
|
24 | 23 | private $content = []; |
25 | 24 | private $lines = 0; |
26 | 25 | private $sections; |
@@ -30,8 +29,7 @@ discard block |
||
30 | 29 | * @param resource $stream |
31 | 30 | * @param ConsoleSectionOutput[] $sections |
32 | 31 | */ |
33 | - public function __construct($stream, array &$sections, int $verbosity, bool $decorated, OutputFormatterInterface $formatter) |
|
34 | - { |
|
32 | + public function __construct($stream, array &$sections, int $verbosity, bool $decorated, OutputFormatterInterface $formatter) { |
|
35 | 33 | parent::__construct($stream, $verbosity, $decorated, $formatter); |
36 | 34 | array_unshift($sections, $this); |
37 | 35 | $this->sections = &$sections; |
@@ -43,8 +41,7 @@ discard block |
||
43 | 41 | * |
44 | 42 | * @param int $lines Number of lines to clear. If null, then the entire output of this section is cleared |
45 | 43 | */ |
46 | - public function clear(int $lines = null) |
|
47 | - { |
|
44 | + public function clear(int $lines = null) { |
|
48 | 45 | if (empty($this->content) || !$this->isDecorated()) { |
49 | 46 | return; |
50 | 47 | } |
@@ -66,8 +63,7 @@ discard block |
||
66 | 63 | * |
67 | 64 | * @param array|string $message |
68 | 65 | */ |
69 | - public function overwrite($message) |
|
70 | - { |
|
66 | + public function overwrite($message) { |
|
71 | 67 | $this->clear(); |
72 | 68 | $this->writeln($message); |
73 | 69 | } |
@@ -80,8 +76,7 @@ discard block |
||
80 | 76 | /** |
81 | 77 | * @internal |
82 | 78 | */ |
83 | - public function addContent(string $input) |
|
84 | - { |
|
79 | + public function addContent(string $input) { |
|
85 | 80 | foreach (explode(\PHP_EOL, $input) as $lineContent) { |
86 | 81 | $this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1; |
87 | 82 | $this->content[] = $lineContent; |
@@ -92,8 +87,7 @@ discard block |
||
92 | 87 | /** |
93 | 88 | * {@inheritdoc} |
94 | 89 | */ |
95 | - protected function doWrite(string $message, bool $newline) |
|
96 | - { |
|
90 | + protected function doWrite(string $message, bool $newline) { |
|
97 | 91 | if (!$this->isDecorated()) { |
98 | 92 | parent::doWrite($message, $newline); |
99 | 93 |