Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/console/Application.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
12 namespace Symfony\Component\Console; | 12 namespace Symfony\Component\Console; |
13 | 13 |
14 use Symfony\Component\Console\Exception\ExceptionInterface; | 14 use Symfony\Component\Console\Exception\ExceptionInterface; |
15 use Symfony\Component\Console\Formatter\OutputFormatter; | 15 use Symfony\Component\Console\Formatter\OutputFormatter; |
16 use Symfony\Component\Console\Helper\DebugFormatterHelper; | 16 use Symfony\Component\Console\Helper\DebugFormatterHelper; |
17 use Symfony\Component\Console\Helper\Helper; | |
17 use Symfony\Component\Console\Helper\ProcessHelper; | 18 use Symfony\Component\Console\Helper\ProcessHelper; |
18 use Symfony\Component\Console\Helper\QuestionHelper; | 19 use Symfony\Component\Console\Helper\QuestionHelper; |
19 use Symfony\Component\Console\Input\InputInterface; | 20 use Symfony\Component\Console\Input\InputInterface; |
20 use Symfony\Component\Console\Input\StreamableInputInterface; | 21 use Symfony\Component\Console\Input\StreamableInputInterface; |
21 use Symfony\Component\Console\Input\ArgvInput; | 22 use Symfony\Component\Console\Input\ArgvInput; |
127 } catch (\Throwable $x) { | 128 } catch (\Throwable $x) { |
128 $e = new FatalThrowableError($x); | 129 $e = new FatalThrowableError($x); |
129 } | 130 } |
130 | 131 |
131 if (null !== $e) { | 132 if (null !== $e) { |
132 if (!$this->catchExceptions) { | 133 if (!$this->catchExceptions || !$x instanceof \Exception) { |
133 throw $x; | 134 throw $x; |
134 } | 135 } |
135 | 136 |
136 if ($output instanceof ConsoleOutputInterface) { | 137 if ($output instanceof ConsoleOutputInterface) { |
137 $this->renderException($e, $output->getErrorOutput()); | 138 $this->renderException($e, $output->getErrorOutput()); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 if (!$name) { | 191 if (!$name) { |
191 $name = $this->defaultCommand; | 192 $name = $this->defaultCommand; |
192 $input = new ArrayInput(array('command' => $this->defaultCommand)); | 193 $this->definition->setArguments(array_merge( |
194 $this->definition->getArguments(), | |
195 array( | |
196 'command' => new InputArgument('command', InputArgument::OPTIONAL, $this->definition->getArgument('command')->getDescription(), $name), | |
197 ) | |
198 )); | |
193 } | 199 } |
194 | 200 |
195 $this->runningCommand = null; | 201 $this->runningCommand = null; |
196 // the command name MUST be the first element of the input | 202 // the command name MUST be the first element of the input |
197 $command = $this->find($name); | 203 $command = $this->find($name); |
636 ' [%s%s] ', | 642 ' [%s%s] ', |
637 get_class($e), | 643 get_class($e), |
638 $output->isVerbose() && 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '' | 644 $output->isVerbose() && 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '' |
639 ); | 645 ); |
640 | 646 |
641 $len = $this->stringWidth($title); | 647 $len = Helper::strlen($title); |
642 | 648 |
643 $width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : PHP_INT_MAX; | 649 $width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : PHP_INT_MAX; |
644 // HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is a 64 bit integer: https://github.com/facebook/hhvm/issues/1327 | 650 // HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is a 64 bit integer: https://github.com/facebook/hhvm/issues/1327 |
645 if (defined('HHVM_VERSION') && $width > 1 << 31) { | 651 if (defined('HHVM_VERSION') && $width > 1 << 31) { |
646 $width = 1 << 31; | 652 $width = 1 << 31; |
647 } | 653 } |
648 $lines = array(); | 654 $lines = array(); |
649 foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) { | 655 foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) { |
650 foreach ($this->splitStringByWidth($line, $width - 4) as $line) { | 656 foreach ($this->splitStringByWidth($line, $width - 4) as $line) { |
651 // pre-format lines to get the right string length | 657 // pre-format lines to get the right string length |
652 $lineLength = $this->stringWidth($line) + 4; | 658 $lineLength = Helper::strlen($line) + 4; |
653 $lines[] = array($line, $lineLength); | 659 $lines[] = array($line, $lineLength); |
654 | 660 |
655 $len = max($lineLength, $len); | 661 $len = max($lineLength, $len); |
656 } | 662 } |
657 } | 663 } |
658 | 664 |
659 $messages = array(); | 665 $messages = array(); |
660 $messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len)); | 666 $messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len)); |
661 $messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title)))); | 667 $messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::strlen($title)))); |
662 foreach ($lines as $line) { | 668 foreach ($lines as $line) { |
663 $messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1])); | 669 $messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1])); |
664 } | 670 } |
665 $messages[] = $emptyLine; | 671 $messages[] = $emptyLine; |
666 $messages[] = ''; | 672 $messages[] = ''; |
1036 } | 1042 } |
1037 | 1043 |
1038 return $this; | 1044 return $this; |
1039 } | 1045 } |
1040 | 1046 |
1041 private function stringWidth($string) | |
1042 { | |
1043 if (false === $encoding = mb_detect_encoding($string, null, true)) { | |
1044 return strlen($string); | |
1045 } | |
1046 | |
1047 return mb_strwidth($string, $encoding); | |
1048 } | |
1049 | |
1050 private function splitStringByWidth($string, $width) | 1047 private function splitStringByWidth($string, $width) |
1051 { | 1048 { |
1052 // str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly. | 1049 // str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly. |
1053 // additionally, array_slice() is not enough as some character has doubled width. | 1050 // additionally, array_slice() is not enough as some character has doubled width. |
1054 // we need a function to split string not by character count but by string width | 1051 // we need a function to split string not by character count but by string width |