Platformsh\Cli\Util\Table::render PHP Method

render() public method

Render a table of data to output.
public render ( array $rows, array $header = [] )
$rows array The table rows.
$header array The table header (optional).
    public function render(array $rows, array $header = [])
    {
        $format = $this->getFormat();
        switch ($format) {
            case 'csv':
                $this->renderCsv($rows, $header);
                break;
            case 'tsv':
                $this->renderCsv($rows, $header, "\t");
                break;
            case null:
            case 'table':
                $this->renderTable($rows, $header);
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Invalid format: %s', $format));
        }
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     $project = $this->getSelectedProject();
     try {
         $domains = $project->getDomains();
     } catch (ClientException $e) {
         $this->handleApiException($e, $project);
         return 1;
     }
     if (empty($domains)) {
         $this->stdErr->writeln('No domains found for ' . $this->api()->getProjectLabel($project) . '.');
         $this->stdErr->writeln("\nAdd a domain to the project by running <info>" . self::$config->get('application.executable') . " domain:add [domain-name]</info>");
         return 1;
     }
     $table = new Table($input, $output);
     $header = ['Name', 'SSL enabled', 'Creation date'];
     $rows = $this->buildDomainRows($domains);
     if ($table->formatIsMachineReadable()) {
         $table->render($rows, $header);
         return 0;
     }
     $this->stdErr->writeln("Your domains are: ");
     $table->render($rows, $header);
     $this->stdErr->writeln('');
     $this->stdErr->writeln('To add a new domain, run: <info>' . self::$config->get('application.executable') . ' domain:add [domain-name]</info>');
     $this->stdErr->writeln('To view a domain, run: <info>' . self::$config->get('application.executable') . ' domain:get [domain-name]</info>');
     $this->stdErr->writeln('To delete a domain, run: <info>' . self::$config->get('application.executable') . ' domain:delete [domain-name]</info>');
     return 0;
 }
All Usage Examples Of Platformsh\Cli\Util\Table::render