/**
  * @param array      $rows
  * @param array|null $headers
  */
 protected function renderTable(array $rows, $headers = null)
 {
     $table = new Table($this->output);
     if (!empty($headers)) {
         $table->setHeaders($headers);
     } elseif ($headers === null && !empty($rows)) {
         $firstRow = reset($rows);
         if ($firstRow instanceof AbstractModel || $firstRow instanceof PayloadResponseInterface) {
             $firstRow = $this->serializeObjectToArray($firstRow);
         }
         $table->setHeaders(array_keys($firstRow));
     }
     $table->setRows($this->simplifyRows($rows));
     $style = Table::getStyleDefinition('default');
     $style->setCellRowFormat('<fg=yellow>%s</>');
     $table->render();
 }
Example #2
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Style "absent" is not defined.
  */
 public function testGetStyleDefinition()
 {
     Table::getStyleDefinition('absent');
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function table(array $headers, array $rows)
 {
     $style = clone Table::getStyleDefinition('symfony-style-guide');
     $style->setCellHeaderFormat('<info>%s</info>');
     $table = new Table($this);
     $table->setHeaders($headers);
     $table->setRows($rows);
     $table->setStyle($style);
     $table->render();
     $this->newLine();
 }