ConsoleKit\Colors::colorizeLines PHP Method

colorizeLines() public static method

Returns a text with each lines colorized independently
public static colorizeLines ( string $text, string $fgcolor = null, string $bgcolor = null ) : string
$text string
$fgcolor string
$bgcolor string
return string
    public static function colorizeLines($text, $fgcolor = null, $bgcolor = null)
    {
        $lines = explode("\n", $text);
        foreach ($lines as &$line) {
            $line = self::colorize($line, $fgcolor, $bgcolor);
        }
        return implode("\n", $lines);
    }

Usage Example

示例#1
0
 /**
  * Writes an error message to stderr
  *
  * @param \Exception $e
  * @return Console
  */
 public function writeException(\Exception $e)
 {
     if ($this->verboseException) {
         $text = sprintf("[%s]\n%s\nIn %s at line %s\n%s", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
     } else {
         $text = sprintf("\n[%s]\n%s\n", get_class($e), $e->getMessage());
     }
     $box = new Widgets\Box($this->textWriter, $text, '');
     $out = Colors::colorizeLines($box, Colors::WHITE, Colors::RED);
     $out = TextFormater::apply($out, array('indent' => 2));
     $this->textWriter->writeln($out);
     return $this;
 }