Webmozart\Console\Util\StringUtil::getMaxLineLength PHP Method

getMaxLineLength() public static method

public static getMaxLineLength ( $string, Webmozart\Console\Api\Formatter\Formatter $formatter = null )
$formatter Webmozart\Console\Api\Formatter\Formatter
    public static function getMaxLineLength($string, Formatter $formatter = null)
    {
        if ($formatter) {
            $string = $formatter->removeFormat($string);
        }
        $maxLength = 0;
        $lines = explode("\n", $string);
        foreach ($lines as $word) {
            // No need to pass the formatter because the tags are already
            // removed
            $maxLength = max($maxLength, self::getLength($word));
        }
        return $maxLength;
    }

Usage Example

Esempio n. 1
0
 private function wrapColumn($col, $columnLength, Formatter $formatter)
 {
     foreach ($this->wrappedRows as $i => $row) {
         $cell = $row[$col];
         $cellLength = $this->cellLengths[$i][$col];
         if ($cellLength > $columnLength) {
             $this->wordWraps = true;
             if (!$this->wordCuts) {
                 $minLengthWithoutCut = StringUtil::getMaxWordLength($cell, $formatter);
                 if ($minLengthWithoutCut > $columnLength) {
                     $this->wordCuts = true;
                 }
             }
             // TODO use format aware wrapper
             // true: Words may be cut in two
             $wrappedCell = wordwrap($cell, $columnLength, "\n", true);
             $this->wrappedRows[$i][$col] = $wrappedCell;
             // Refresh cell length
             $this->cellLengths[$i][$col] = StringUtil::getMaxLineLength($wrappedCell, $formatter);
         }
     }
 }