Ejemplo n.º 1
0
 /**
  *
  * {@inheritDoc}
  *
  * @see \SK\ITCBundle\Service\Table\Adapter\IAdapter::write()
  */
 public function write(Table $table, OutputInterface $output)
 {
     $style = new TableStyle();
     $style->setHorizontalBorderChar('<fg=magenta>-</>')->setVerticalBorderChar('<fg=magenta>|</>')->setCrossingChar('<fg=magenta>+</>');
     $stable = new STable($output);
     $stable->setStyle('default');
     $stable->setHeaders($table->getHeaders());
     $columns = $table->getColumns();
     $colspan = count($columns);
     $rows = $table->getRows();
     foreach ($rows as $row) {
         $rowModificated = [];
         foreach ($columns as $iCol => $col) {
             if (is_int($iCol)) {
                 $iCol = $col;
             }
             if (array_key_exists($iCol, $row)) {
                 $rowModificated[$iCol] = wordwrap($row[$iCol], $table->getMaxColWidth(), "\n", true);
             } else {
                 $rowModificated[$iCol] = "";
             }
         }
         $stable->addRow($rowModificated);
         $stable->addRow(array(new TableSeparator(array('colspan' => $colspan))));
     }
     $stable->addRow(array(new TableCell("", array('colspan' => $colspan))));
     $stable->addRow(array(new TableCell(sprintf("Found %s results.", count($rows)), array('colspan' => $colspan))));
     $stable->render();
 }
Ejemplo n.º 2
0
 private static function initStyles()
 {
     $borderless = new TableStyle();
     $borderless->setHorizontalBorderChar('=')->setVerticalBorderChar(' ')->setCrossingChar(' ');
     $compact = new TableStyle();
     $compact->setHorizontalBorderChar('')->setVerticalBorderChar(' ')->setCrossingChar('')->setCellRowContentFormat('%s');
     return array('default' => new TableStyle(), 'borderless' => $borderless, 'compact' => $compact);
 }
Ejemplo n.º 3
0
 /**
  * Display validation errors.
  *
  * @param Validator       $validator The json-schema validator.
  * @param OutputInterface $output    An OutputInterface instance.
  */
 public static function displayErrors(Validator $validator, OutputInterface $output)
 {
     $table = new Table($output);
     $style = new TableStyle();
     $style->setCellHeaderFormat('<error>%s</error>');
     $style->setHorizontalBorderChar(' ');
     $style->setVerticalBorderChar(' ');
     $style->setCrossingChar(' ');
     $table->setHeaders(['Property', 'Error']);
     $table->setRows($validator->getErrors());
     $table->setStyle($style);
     $table->render();
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function table(array $headers, array $rows)
 {
     $headers = array_map(function ($value) {
         return sprintf("<info>%s</info>", $value);
     }, $headers);
     $styleGuide = new TableStyle();
     $styleGuide->setHorizontalBorderChar('-')->setVerticalBorderChar('|')->setCrossingChar('+')->setCellHeaderFormat('%s');
     $table = new Table($this);
     $table->setHeaders($headers);
     $table->setRows($rows);
     $table->setStyle($styleGuide);
     $table->render();
     $this->newLine();
 }
Ejemplo n.º 5
0
 public function displayTableResults(OutputInterface $output, $object, array $keysOnly = [], $maxWidth = 35, $count = false)
 {
     $table = new Table($output);
     $style = new TableStyle();
     $style->setHorizontalBorderChar('<fg=magenta>-</>')->setVerticalBorderChar('<fg=magenta>|</>')->setCrossingChar(' ');
     $table->setStyle($style);
     if ($object instanceof CollectionAbstract) {
         $list = $object->toArray();
     } else {
         $list = $object;
     }
     $i = 0;
     foreach ($list as $item) {
         if (!is_array($item)) {
             continue;
         }
         ++$i;
         foreach ($item as $key => $value) {
             if (!empty($keysOnly) && !in_array($key, $keysOnly, true)) {
                 unset($item[$key]);
                 continue;
             }
             if (is_array($value)) {
                 $value = json_encode($value);
             }
             if (is_float($value)) {
                 $value = number_format($value, 3);
             }
             $value = str_replace(['["', '"]', '{"', '"', '}'], [], $value);
             if (empty($value)) {
                 $value = '~';
             }
             $value = substr($value, 0, $maxWidth);
             $item[$key] = $value;
         }
         if (true === $count) {
             $item = array_merge(['#' => $i], $item);
         }
         if (!isset($headers)) {
             $headers = array_keys($item);
             $table->setHeaders($headers);
         }
         $table->addRow($item);
     }
     return $table->render($output);
 }
Ejemplo n.º 6
0
    public function testStyle()
    {
        $style = new TableStyle();
        $style->setHorizontalBorderChar('.')->setVerticalBorderChar('.')->setCrossingChar('.');
        Table::setStyleDefinition('dotfull', $style);
        $table = new Table($output = $this->getOutputStream());
        $table->setHeaders(array('Foo'))->setRows(array(array('Bar')))->setStyle('dotfull');
        $table->render();
        $expected = <<<TABLE
.......
. Foo .
.......
. Bar .
.......

TABLE;
        $this->assertEquals($expected, $this->getOutputContent($output));
    }
 /**
  * Add our custom table style(s) to the table.
  */
 protected static function addCustomTableStyles($table)
 {
     // The 'consolidation' style is the same as the 'symfony-style-guide'
     // style, except it maintains the colored headers used in 'default'.
     $consolidationStyle = new TableStyle();
     $consolidationStyle->setHorizontalBorderChar('-')->setVerticalBorderChar(' ')->setCrossingChar(' ');
     $table->setStyleDefinition('consolidation', $consolidationStyle);
 }
 /**
  * @param string[] $rows
  * @param string[] $headers
  */
 public function table(array $rows, array $headers = null)
 {
     $rows = array_map(function ($value) {
         if (!is_array($value)) {
             return $value;
         }
         $header = array_shift($value);
         array_unshift($value, sprintf('<fg=blue>%s</>', $header));
         return $value;
     }, $rows);
     $style = new TableStyle();
     $style->setVerticalBorderChar('<fg=blue>|</>');
     $style->setHorizontalBorderChar('<fg=blue>-</>');
     $style->setCrossingChar('<fg=blue>+</>');
     $style->setCellHeaderFormat('%s');
     $table = new Table($this);
     $table->setStyle($style);
     if ($headers) {
         $table->setHeaders($headers);
     }
     $table->setRows($rows);
     $table->render();
     $this->newLine();
 }