16
16
use Symfony \Component \Console \Exception \ExceptionInterface ;
17
17
use Symfony \Component \Console \Formatter \OutputFormatter ;
18
18
use Symfony \Component \Console \Helper \DebugFormatterHelper ;
19
+ use Symfony \Component \Console \Helper \Helper ;
19
20
use Symfony \Component \Console \Helper \ProcessHelper ;
20
21
use Symfony \Component \Console \Helper \QuestionHelper ;
21
22
use Symfony \Component \Console \Input \InputInterface ;
@@ -656,7 +657,7 @@ public function renderException($e, $output)
656
657
do {
657
658
$ title = sprintf (' [%s] ' , get_class ($ e ));
658
659
659
- $ len = $ this -> stringWidth ($ title );
660
+ $ len = Helper:: strlen ($ title );
660
661
661
662
$ width = $ this ->getTerminalWidth () ? $ this ->getTerminalWidth () - 1 : PHP_INT_MAX ;
662
663
// 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
@@ -667,7 +668,7 @@ public function renderException($e, $output)
667
668
foreach (preg_split ('/\r?\n/ ' , $ e ->getMessage ()) as $ line ) {
668
669
foreach ($ this ->splitStringByWidth ($ line , $ width - 4 ) as $ line ) {
669
670
// pre-format lines to get the right string length
670
- $ lineLength = $ this -> stringWidth ($ line ) + 4 ;
671
+ $ lineLength = Helper:: strlen ($ line ) + 4 ;
671
672
$ lines [] = array ($ line , $ lineLength );
672
673
673
674
$ len = max ($ lineLength , $ len );
@@ -676,7 +677,7 @@ public function renderException($e, $output)
676
677
677
678
$ messages = array ();
678
679
$ messages [] = $ emptyLine = sprintf ('<error>%s</error> ' , str_repeat (' ' , $ len ));
679
- $ messages [] = sprintf ('<error>%s%s</error> ' , $ title , str_repeat (' ' , max (0 , $ len - $ this -> stringWidth ($ title ))));
680
+ $ messages [] = sprintf ('<error>%s%s</error> ' , $ title , str_repeat (' ' , max (0 , $ len - Helper:: strlen ($ title ))));
680
681
foreach ($ lines as $ line ) {
681
682
$ messages [] = sprintf ('<error> %s %s</error> ' , OutputFormatter::escape ($ line [0 ]), str_repeat (' ' , $ len - $ line [1 ]));
682
683
}
@@ -1097,15 +1098,6 @@ public function setDefaultCommand($commandName)
1097
1098
$ this ->defaultCommand = $ commandName ;
1098
1099
}
1099
1100
1100
- private function stringWidth ($ string )
1101
- {
1102
- if (false === $ encoding = mb_detect_encoding ($ string , null , true )) {
1103
- return strlen ($ string );
1104
- }
1105
-
1106
- return mb_strwidth ($ string , $ encoding );
1107
- }
1108
-
1109
1101
private function splitStringByWidth ($ string , $ width )
1110
1102
{
1111
1103
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
0 commit comments