format() public method

使用所给的样式格式化文字
public format ( string $message ) : string
$message string 文字
return string
Example #1
0
 public function write($messages, $newline = false, $type = Output::OUTPUT_NORMAL, $stream = null)
 {
     if (Output::VERBOSITY_QUIET === $this->output->getVerbosity()) {
         return;
     }
     $messages = (array) $messages;
     foreach ($messages as $message) {
         switch ($type) {
             case Output::OUTPUT_NORMAL:
                 $message = $this->formatter->format($message);
                 break;
             case Output::OUTPUT_RAW:
                 break;
             case Output::OUTPUT_PLAIN:
                 $message = strip_tags($this->formatter->format($message));
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
         }
         $this->doWrite($message, $newline, $stream);
     }
 }
Example #2
0
 public static function strlenWithoutDecoration(Formatter $formatter, $string)
 {
     $isDecorated = $formatter->isDecorated();
     $formatter->setDecorated(false);
     // remove <...> formatting
     $string = $formatter->format($string);
     // remove already formatted characters
     $string = preg_replace("/\\[[^m]*m/", '', $string);
     $formatter->setDecorated($isDecorated);
     return self::strlen($string);
 }