Beispiel #1
0
 /**
  * 输出异常错误信息
  *
  * @param mixed $e
  */
 public static function writeException($e)
 {
     if ($e instanceof \Exception) {
         $text = sprintf("%s\n[%s]\n%s", $e->getFile() . ':' . $e->getLine(), get_class($e), $e->getMessage());
     } else {
         $text = $e;
     }
     $box = new Box($text, '*');
     $out = Colour::colour($box, [Colour::WHITE, 0], Colour::RED);
     $format = new Format(['indent' => 2]);
     $out = $format->format($out);
     self::writeln($out, STDERR);
 }
Beispiel #2
0
 /**
  * 格式化输出
  *
  * @param Format $format
  * @param array $args
  */
 private function formatEcho(Format $format, $args)
 {
     foreach ($args as $group => $list) {
         if (is_array($list)) {
             $this->writeln($format->format($group));
             foreach ($list as $name => $desc) {
                 $this->writeln($format->format('  ' . $name . str_repeat(' ', $this->commandLength - 2 - strlen($name)) . $desc));
             }
         } else {
             $this->writeln($format->format($group . str_repeat(' ', $this->commandLength - strlen($group)) . $list));
         }
     }
 }
Beispiel #3
0
 /**
  * 格式化文本
  *
  * @param string $text 要格式化的文本
  * @param array $option 格式化选项 @see Format
  *
  * @return string
  */
 public function format($text, $option = [])
 {
     $format = new Format($option);
     return $format->format($text);
 }