You are here

private function MemcacheStatisticsController::statsTablesOutput in Memcache API and Integration 8.2

Generates render array for output.

1 call to MemcacheStatisticsController::statsTablesOutput()
MemcacheStatisticsController::statsTable in memcache_admin/src/Controller/MemcacheStatisticsController.php
Callback for the Memcache Stats page.

File

memcache_admin/src/Controller/MemcacheStatisticsController.php, line 170

Class

MemcacheStatisticsController
Memcache Statistics.

Namespace

Drupal\memcache_admin\Controller

Code

private function statsTablesOutput($bin, $servers, $stats) {
  $memcache = \Drupal::service('memcache.factory')
    ->get(NULL, TRUE);
  $memcache_bins = $memcache
    ->getBins();
  $links = [];
  if (!is_array($servers)) {
    return;
  }
  foreach ($servers as $server) {

    // Convert socket file path so it works with an argument, this should
    // have no impact on non-socket configurations. Convert / to !.
    $links[] = Link::fromTextandUrl($server, Url::fromUri('base:/admin/reports/memcache/' . $memcache_bins[$bin] . '/' . str_replace('/', '!', $server)))
      ->toString();
  }
  if (count($servers) > 1) {
    $headers = array_merge([
      '',
      $this
        ->t('Totals'),
    ], $links);
  }
  else {
    $headers = array_merge([
      '',
    ], $links);
  }
  $output = [];
  foreach ($stats as $table => $data) {
    $rows = [];
    foreach ($data as $data_row) {
      $row = [];
      $row[] = $data_row['label'];
      if (isset($data_row['total'])) {
        $row[] = $data_row['total'];
      }
      foreach ($data_row['servers'] as $server) {
        $row[] = $server;
      }
      $rows[] = $row;
    }
    $output[$table] = [
      '#theme' => 'table',
      '#header' => $headers,
      '#rows' => $rows,
    ];
  }
  return $output;
}