Use {@link none()}, {@link ascii()} or {@link solid()} to obtain predefined border styles.
Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Ejemplo n.º 1
0
 /**
  * A borderless style.
  *
  * @return TableStyle The style.
  */
 public static function borderless()
 {
     if (!self::$borderless) {
         $borderStyle = BorderStyle::none();
         $borderStyle->setLineVCChar('  ');
         self::$borderless = new static();
         self::$borderless->setBorderStyle($borderStyle);
         self::$borderless->setHeaderCellStyle(Style::noTag()->bold());
     }
     return clone self::$borderless;
 }
Ejemplo n.º 2
0
 /**
  * Draws a bordered row of cells.
  *
  * @param IO          $io            The I/O.
  * @param BorderStyle $style         The border style.
  * @param string[]    $row           The row cells.
  * @param int[]       $columnLengths The lengths of the cells.
  * @param int[]       $alignments    The alignments of the cells.
  * @param string      $cellFormat    The cell format.
  * @param Style       $cellStyle     The cell style.
  * @param string      $paddingChar   The character used to pad cells.
  * @param int         $indentation   The number of spaces to indent.
  */
 public static function drawRow(IO $io, BorderStyle $style, array $row, array $columnLengths, array $alignments, $cellFormat, Style $cellStyle = null, $paddingChar, $indentation = 0)
 {
     $totalLines = 0;
     // Split all cells into lines
     foreach ($row as $col => $cell) {
         $row[$col] = explode("\n", $cell);
         $totalLines = max($totalLines, count($row[$col]));
     }
     $nbColumns = count($row);
     $borderVLChar = $io->format($style->getLineVLChar(), $style->getStyle());
     $borderVCChar = $io->format($style->getLineVCChar(), $style->getStyle());
     $borderVRChar = $io->format($style->getLineVRChar(), $style->getStyle());
     for ($i = 0; $i < $totalLines; ++$i) {
         $line = str_repeat(' ', $indentation);
         $line .= $borderVLChar;
         foreach ($row as $col => &$remainingLines) {
             $cellLine = $remainingLines ? array_shift($remainingLines) : '';
             $totalPadLength = $columnLengths[$col] - StringUtil::getLength($cellLine, $io);
             $paddingLeft = '';
             $paddingRight = '';
             if ($totalPadLength > 0) {
                 $alignment = isset($alignments[$col]) ? $alignments[$col] : Alignment::LEFT;
                 switch ($alignment) {
                     case Alignment::LEFT:
                         $paddingRight = str_repeat($paddingChar, $totalPadLength);
                         break;
                     case Alignment::RIGHT:
                         $paddingLeft = str_repeat($paddingChar, $totalPadLength);
                         break;
                     case Alignment::CENTER:
                         $leftPadLength = floor($totalPadLength / 2);
                         $paddingLeft = str_repeat($paddingChar, $leftPadLength);
                         $paddingRight = str_repeat($paddingChar, $totalPadLength - $leftPadLength);
                         break;
                 }
             }
             $line .= $io->format(sprintf($cellFormat, $paddingLeft . $cellLine . $paddingRight), $cellStyle);
             $line .= $col < $nbColumns - 1 ? $borderVCChar : $borderVRChar;
         }
         // Remove trailing space
         $io->write(rtrim($line) . "\n");
     }
 }
Ejemplo n.º 3
0
 /**
  * A style that uses Unicode characters for drawing solid borders.
  *
  * @return TableStyle The style.
  */
 public static function solidBorder()
 {
     if (!self::$solidBorder) {
         self::$solidBorder = new static();
         self::$solidBorder->headerCellFormat = ' %s ';
         self::$solidBorder->cellFormat = ' %s ';
         self::$solidBorder->borderStyle = BorderStyle::solid();
     }
     return clone self::$solidBorder;
 }