You are here

private function AcquiaContentHubWebhookInterestCommands::renderTable in Acquia Content Hub 8.2

Render a message and table with headers.

Parameters

string $message: String to display above the table. Pass empty string to display nothing.

bool $use_headers: Show Individual column headers?

mixed ... $cols // @codingStandardsIgnoreLine: Columns of data to render into rows. Variable length.

1 call to AcquiaContentHubWebhookInterestCommands::renderTable()
AcquiaContentHubWebhookInterestCommands::contenthubWebhookInterestsList in src/Commands/AcquiaContentHubWebhookInterestCommands.php
Perform a webhook interest management operation.

File

src/Commands/AcquiaContentHubWebhookInterestCommands.php, line 258

Class

AcquiaContentHubWebhookInterestCommands
Tests commands that interact with webhook interests.

Namespace

Drupal\acquia_contenthub\Commands

Code

private function renderTable(string $message, bool $use_headers = FALSE, ...$cols) {
  $rows_mapper = function (...$items) {
    return $items;
  };
  if (!empty($message)) {
    $this
      ->output()
      ->writeln($message);
  }
  $table = new Table($this
    ->output());
  $headers = [];
  if ($use_headers) {
    foreach ($cols as &$col) {
      $keys = array_keys($col);
      $headers[] = $col[$keys[0]];
      unset($col[$keys[0]]);
    }
    $table
      ->setHeaders($headers);
  }
  $rows = array_map($rows_mapper, ...$cols);
  $table
    ->setRows($rows)
    ->render();
}