15
15
use Symfony \Component \Console \Descriptor \XmlDescriptor ;
16
16
use Symfony \Component \Console \Formatter \OutputFormatter ;
17
17
use Symfony \Component \Console \Helper \DebugFormatterHelper ;
18
+ use Symfony \Component \Console \Helper \Helper ;
18
19
use Symfony \Component \Console \Helper \ProcessHelper ;
19
20
use Symfony \Component \Console \Helper \QuestionHelper ;
20
21
use Symfony \Component \Console \Input \InputInterface ;
@@ -653,7 +654,7 @@ public function renderException($e, $output)
653
654
do {
654
655
$ title = sprintf (' [%s] ' , get_class ($ e ));
655
656
656
- $ len = $ this -> stringWidth ($ title );
657
+ $ len = Helper:: strlen ($ title );
657
658
658
659
$ width = $ this ->getTerminalWidth () ? $ this ->getTerminalWidth () - 1 : PHP_INT_MAX ;
659
660
// 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
@@ -664,7 +665,7 @@ public function renderException($e, $output)
664
665
foreach (preg_split ('/\r?\n/ ' , $ e ->getMessage ()) as $ line ) {
665
666
foreach ($ this ->splitStringByWidth ($ line , $ width - 4 ) as $ line ) {
666
667
// pre-format lines to get the right string length
667
- $ lineLength = $ this -> stringWidth ($ line ) + 4 ;
668
+ $ lineLength = Helper:: strlen ($ line ) + 4 ;
668
669
$ lines [] = array ($ line , $ lineLength );
669
670
670
671
$ len = max ($ lineLength , $ len );
@@ -673,7 +674,7 @@ public function renderException($e, $output)
673
674
674
675
$ messages = array ();
675
676
$ messages [] = $ emptyLine = sprintf ('<error>%s</error> ' , str_repeat (' ' , $ len ));
676
- $ messages [] = sprintf ('<error>%s%s</error> ' , $ title , str_repeat (' ' , max (0 , $ len - $ this -> stringWidth ($ title ))));
677
+ $ messages [] = sprintf ('<error>%s%s</error> ' , $ title , str_repeat (' ' , max (0 , $ len - Helper:: strlen ($ title ))));
677
678
foreach ($ lines as $ line ) {
678
679
$ messages [] = sprintf ('<error> %s %s</error> ' , OutputFormatter::escape ($ line [0 ]), str_repeat (' ' , $ len - $ line [1 ]));
679
680
}
@@ -1086,19 +1087,6 @@ public function setDefaultCommand($commandName)
1086
1087
$ this ->defaultCommand = $ commandName ;
1087
1088
}
1088
1089
1089
- private function stringWidth ($ string )
1090
- {
1091
- if (!function_exists ('mb_strwidth ' )) {
1092
- return strlen ($ string );
1093
- }
1094
-
1095
- if (false === $ encoding = mb_detect_encoding ($ string , null , true )) {
1096
- return strlen ($ string );
1097
- }
1098
-
1099
- return mb_strwidth ($ string , $ encoding );
1100
- }
1101
-
1102
1090
private function splitStringByWidth ($ string , $ width )
1103
1091
{
1104
1092
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
0 commit comments