@@ -38,7 +38,8 @@ |
||
38 | 38 | public function locateCommands(): array |
39 | 39 | { |
40 | 40 | $commands = []; |
41 | - foreach ($this->commands as $command) { |
|
41 | + foreach ($this->commands as $command) |
|
42 | + { |
|
42 | 43 | $commands[] = $this->factory->get($command); |
43 | 44 | } |
44 | 45 |
@@ -50,18 +50,21 @@ |
||
50 | 50 | public function execute(ContainerInterface $container, OutputInterface $output): void |
51 | 51 | { |
52 | 52 | $function = $this->function; |
53 | - if (is_string($function) && strpos($function, ':') !== false) { |
|
53 | + if (is_string($function) && strpos($function, ':') !== false) |
|
54 | + { |
|
54 | 55 | $function = explode(':', str_replace('::', ':', $function)); |
55 | 56 | } |
56 | 57 | |
57 | - if (is_array($function) && isset($function[0]) && !is_object($function[0])) { |
|
58 | + if (is_array($function) && isset($function[0]) && !is_object($function[0])) |
|
59 | + { |
|
58 | 60 | $function[0] = $container->get($function[0]); |
59 | 61 | } |
60 | 62 | |
61 | 63 | /** @var ResolverInterface $resolver */ |
62 | 64 | $resolver = $container->get(ResolverInterface::class); |
63 | 65 | |
64 | - if (is_array($function)) { |
|
66 | + if (is_array($function)) |
|
67 | + { |
|
65 | 68 | $reflection = new \ReflectionMethod($function[0], $function[1]); |
66 | 69 | $reflection->invokeArgs($function[0], $resolver->resolveArguments($reflection, [ |
67 | 70 | 'output' => $output |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function writeHeader(OutputInterface $output): void |
39 | 39 | { |
40 | - if (!empty($this->header)) { |
|
40 | + if (!empty($this->header)) |
|
41 | + { |
|
41 | 42 | $output->writeln($this->header); |
42 | 43 | } |
43 | 44 | } |
@@ -47,7 +48,8 @@ discard block |
||
47 | 48 | */ |
48 | 49 | public function whiteFooter(OutputInterface $output): void |
49 | 50 | { |
50 | - if (!empty($this->footer)) { |
|
51 | + if (!empty($this->footer)) |
|
52 | + { |
|
51 | 53 | $output->writeln($this->footer); |
52 | 54 | } |
53 | 55 | } |
@@ -32,16 +32,21 @@ |
||
32 | 32 | protected function runSequence(iterable $commands, ContainerInterface $container): int |
33 | 33 | { |
34 | 34 | $errors = 0; |
35 | - foreach ($commands as $sequence) { |
|
35 | + foreach ($commands as $sequence) |
|
36 | + { |
|
36 | 37 | $sequence->writeHeader($this->output); |
37 | 38 | |
38 | - try { |
|
39 | + try |
|
40 | + { |
|
39 | 41 | $sequence->execute($container, $this->output); |
40 | 42 | $sequence->whiteFooter($this->output); |
41 | - } catch (Throwable $e) { |
|
43 | + } |
|
44 | + catch (Throwable $e) |
|
45 | + { |
|
42 | 46 | $errors++; |
43 | 47 | $this->sprintf("<error>%s</error>\n", $e); |
44 | - if (!$this->option('ignore') && $this->option('break')) { |
|
48 | + if (!$this->option('ignore') && $this->option('break')) |
|
49 | + { |
|
45 | 50 | $this->writeln('<fg=red>Aborting.</fg=red>'); |
46 | 51 | |
47 | 52 | return 1; |
@@ -59,7 +59,8 @@ discard block |
||
59 | 59 | */ |
60 | 60 | protected function execute(InputInterface $input, OutputInterface $output) |
61 | 61 | { |
62 | - if ($this->container === null) { |
|
62 | + if ($this->container === null) |
|
63 | + { |
|
63 | 64 | throw new ScopeException('Container is not set'); |
64 | 65 | } |
65 | 66 | |
@@ -69,7 +70,8 @@ discard block |
||
69 | 70 | /** @var ResolverInterface $resolver */ |
70 | 71 | $resolver = $this->container->get(ResolverInterface::class); |
71 | 72 | |
72 | - try { |
|
73 | + try |
|
74 | + { |
|
73 | 75 | list($this->input, $this->output) = [$input, $output]; |
74 | 76 | |
75 | 77 | //Executing perform method with method injection |
@@ -77,7 +79,9 @@ discard block |
||
77 | 79 | $reflection, |
78 | 80 | compact('input', 'output') |
79 | 81 | )); |
80 | - } finally { |
|
82 | + } |
|
83 | + finally |
|
84 | + { |
|
81 | 85 | [$this->input, $this->output] = [null, null]; |
82 | 86 | } |
83 | 87 | } |
@@ -90,11 +94,13 @@ discard block |
||
90 | 94 | $this->setName(static::NAME); |
91 | 95 | $this->setDescription(static::DESCRIPTION); |
92 | 96 | |
93 | - foreach ($this->defineOptions() as $option) { |
|
97 | + foreach ($this->defineOptions() as $option) |
|
98 | + { |
|
94 | 99 | call_user_func_array([$this, 'addOption'], $option); |
95 | 100 | } |
96 | 101 | |
97 | - foreach ($this->defineArguments() as $argument) { |
|
102 | + foreach ($this->defineArguments() as $argument) |
|
103 | + { |
|
98 | 104 | call_user_func_array([$this, 'addArgument'], $argument); |
99 | 105 | } |
100 | 106 | } |
@@ -55,7 +55,8 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function getCommands(): array |
57 | 57 | { |
58 | - if (!array_key_exists('commands', $this->config)) { |
|
58 | + if (!array_key_exists('commands', $this->config)) |
|
59 | + { |
|
59 | 60 | //Legacy config support |
60 | 61 | return []; |
61 | 62 | } |
@@ -73,7 +74,8 @@ discard block |
||
73 | 74 | public function configureSequence(): \Generator |
74 | 75 | { |
75 | 76 | $sequence = $this->config['configure'] ?? $this->config['configureSequence'] ?? []; |
76 | - foreach ($sequence as $item) { |
|
77 | + foreach ($sequence as $item) |
|
78 | + { |
|
77 | 79 | yield $this->parseSequence($item); |
78 | 80 | } |
79 | 81 | } |
@@ -88,7 +90,8 @@ discard block |
||
88 | 90 | public function updateSequence(): \Generator |
89 | 91 | { |
90 | 92 | $sequence = $this->config['update'] ?? $this->config['updateSequence'] ?? []; |
91 | - foreach ($sequence as $item) { |
|
93 | + foreach ($sequence as $item) |
|
94 | + { |
|
92 | 95 | yield $this->parseSequence($item); |
93 | 96 | } |
94 | 97 | } |
@@ -101,15 +104,18 @@ discard block |
||
101 | 104 | */ |
102 | 105 | protected function parseSequence($item): SequenceInterface |
103 | 106 | { |
104 | - if ($item instanceof SequenceInterface) { |
|
107 | + if ($item instanceof SequenceInterface) |
|
108 | + { |
|
105 | 109 | return $item; |
106 | 110 | } |
107 | 111 | |
108 | - if (is_string($item)) { |
|
112 | + if (is_string($item)) |
|
113 | + { |
|
109 | 114 | return new CallableSequence($item); |
110 | 115 | } |
111 | 116 | |
112 | - if (is_array($item) && isset($item['command'])) { |
|
117 | + if (is_array($item) && isset($item['command'])) |
|
118 | + { |
|
113 | 119 | return new CommandSequence( |
114 | 120 | $item['command'], |
115 | 121 | $item['options'] ?? [], |
@@ -118,7 +124,8 @@ discard block |
||
118 | 124 | ); |
119 | 125 | } |
120 | 126 | |
121 | - if (is_array($item) && isset($item['invoke'])) { |
|
127 | + if (is_array($item) && isset($item['invoke'])) |
|
128 | + { |
|
122 | 129 | return new CallableSequence( |
123 | 130 | $item['invoke'], |
124 | 131 | $item['parameters'] ?? [], |
@@ -72,7 +72,8 @@ discard block |
||
72 | 72 | $input = $input ?? new ArgvInput(); |
73 | 73 | $output = $output ?? new ConsoleOutput(); |
74 | 74 | |
75 | - return ContainerScope::runScope($this->container, function () use ($input, $output) { |
|
75 | + return ContainerScope::runScope($this->container, function () use ($input, $output) |
|
76 | + { |
|
76 | 77 | return $this->run( |
77 | 78 | $input->getFirstArgument() ?? 'list', |
78 | 79 | $input, |
@@ -102,11 +103,13 @@ discard block |
||
102 | 103 | |
103 | 104 | $this->configureIO($input, $output); |
104 | 105 | |
105 | - if ($command !== null) { |
|
106 | + if ($command !== null) |
|
107 | + { |
|
106 | 108 | $input = new InputProxy($input, ['firstArgument' => $command]); |
107 | 109 | } |
108 | 110 | |
109 | - $code = ContainerScope::runScope($this->container, function () use ($input, $output) { |
|
111 | + $code = ContainerScope::runScope($this->container, function () use ($input, $output) |
|
112 | + { |
|
110 | 113 | return $this->getApplication()->doRun($input, $output); |
111 | 114 | }); |
112 | 115 | |
@@ -122,7 +125,8 @@ discard block |
||
122 | 125 | */ |
123 | 126 | public function getApplication(): Application |
124 | 127 | { |
125 | - if ($this->application !== null) { |
|
128 | + if ($this->application !== null) |
|
129 | + { |
|
126 | 130 | return $this->application; |
127 | 131 | } |
128 | 132 | |
@@ -130,7 +134,8 @@ discard block |
||
130 | 134 | $this->application->setCatchExceptions(false); |
131 | 135 | $this->application->setAutoExit(false); |
132 | 136 | |
133 | - if ($this->locator !== null) { |
|
137 | + if ($this->locator !== null) |
|
138 | + { |
|
134 | 139 | $this->addCommands($this->locator->locateCommands()); |
135 | 140 | } |
136 | 141 | |
@@ -146,8 +151,10 @@ discard block |
||
146 | 151 | */ |
147 | 152 | private function addCommands(iterable $commands): void |
148 | 153 | { |
149 | - foreach ($commands as $command) { |
|
150 | - if ($command instanceof Command) { |
|
154 | + foreach ($commands as $command) |
|
155 | + { |
|
156 | + if ($command instanceof Command) |
|
157 | + { |
|
151 | 158 | $command->setContainer($this->container); |
152 | 159 | } |
153 | 160 | |
@@ -164,27 +171,36 @@ discard block |
||
164 | 171 | */ |
165 | 172 | private function configureIO(InputInterface $input, OutputInterface $output): void |
166 | 173 | { |
167 | - if (true === $input->hasParameterOption(['--ansi'], true)) { |
|
174 | + if (true === $input->hasParameterOption(['--ansi'], true)) |
|
175 | + { |
|
168 | 176 | $output->setDecorated(true); |
169 | - } elseif (true === $input->hasParameterOption(['--no-ansi'], true)) { |
|
177 | + } |
|
178 | + elseif (true === $input->hasParameterOption(['--no-ansi'], true)) |
|
179 | + { |
|
170 | 180 | $output->setDecorated(false); |
171 | 181 | } |
172 | 182 | |
173 | - if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) { |
|
183 | + if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) |
|
184 | + { |
|
174 | 185 | $input->setInteractive(false); |
175 | - } elseif (\function_exists('posix_isatty')) { |
|
186 | + } |
|
187 | + elseif (\function_exists('posix_isatty')) |
|
188 | + { |
|
176 | 189 | $inputStream = null; |
177 | 190 | |
178 | - if ($input instanceof StreamableInputInterface) { |
|
191 | + if ($input instanceof StreamableInputInterface) |
|
192 | + { |
|
179 | 193 | $inputStream = $input->getStream(); |
180 | 194 | } |
181 | 195 | |
182 | - if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) { |
|
196 | + if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) |
|
197 | + { |
|
183 | 198 | $input->setInteractive(false); |
184 | 199 | } |
185 | 200 | } |
186 | 201 | |
187 | - switch ($shellVerbosity = (int)getenv('SHELL_VERBOSITY')) { |
|
202 | + switch ($shellVerbosity = (int)getenv('SHELL_VERBOSITY')) |
|
203 | + { |
|
188 | 204 | case -1: |
189 | 205 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
190 | 206 | break; |
@@ -207,7 +223,9 @@ discard block |
||
207 | 223 | ) { |
208 | 224 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
209 | 225 | $shellVerbosity = -1; |
210 | - } else { |
|
226 | + } |
|
227 | + else |
|
228 | + { |
|
211 | 229 | if ( |
212 | 230 | $input->hasParameterOption('-vvv', true) |
213 | 231 | || $input->hasParameterOption('--verbose=3', true) |
@@ -215,14 +233,16 @@ discard block |
||
215 | 233 | ) { |
216 | 234 | $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
217 | 235 | $shellVerbosity = 3; |
218 | - } elseif ( |
|
236 | + } |
|
237 | + elseif ( |
|
219 | 238 | $input->hasParameterOption('-vv', true) |
220 | 239 | || $input->hasParameterOption('--verbose=2', true) |
221 | 240 | || 2 === $input->getParameterOption('--verbose', false, true) |
222 | 241 | ) { |
223 | 242 | $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); |
224 | 243 | $shellVerbosity = 2; |
225 | - } elseif ( |
|
244 | + } |
|
245 | + elseif ( |
|
226 | 246 | $input->hasParameterOption('-v', true) |
227 | 247 | || $input->hasParameterOption('--verbose=1', true) |
228 | 248 | || $input->hasParameterOption('--verbose', true) |
@@ -233,7 +253,8 @@ discard block |
||
233 | 253 | } |
234 | 254 | } |
235 | 255 | |
236 | - if (-1 === $shellVerbosity) { |
|
256 | + if (-1 === $shellVerbosity) |
|
257 | + { |
|
237 | 258 | $input->setInteractive(false); |
238 | 259 | } |
239 | 260 |
@@ -126,10 +126,12 @@ |
||
126 | 126 | $this->assertEquals(1, $output->getCode()); |
127 | 127 | } |
128 | 128 | |
129 | - public function do(OutputInterface $output): void |
|
129 | + public function do{ |
|
130 | + (OutputInterface $output): void |
|
130 | 131 | { |
131 | 132 | $output->write('OK'); |
132 | 133 | } |
134 | + } |
|
133 | 135 | |
134 | 136 | public function err(OutputInterface $output): void |
135 | 137 | { |
@@ -125,10 +125,12 @@ |
||
125 | 125 | $this->assertEquals(1, $output->getCode()); |
126 | 126 | } |
127 | 127 | |
128 | - public function do(OutputInterface $output): void |
|
128 | + public function do{ |
|
129 | + (OutputInterface $output): void |
|
129 | 130 | { |
130 | 131 | $output->write('OK'); |
131 | 132 | } |
133 | + } |
|
132 | 134 | |
133 | 135 | public function err(OutputInterface $output): void |
134 | 136 | { |