You are here

public function Logger::templates in MongoDB 8.2

Return templates matching type and level criteria.

Parameters

string[] $types: An array of EventTemplate types. May be a hash.

string[]|int[] $levels: An array of severity levels.

int $skip: The number of templates to skip before the first one displayed.

int $limit: The maximum number of templates to return.

Return value

\MongoDB\Driver\Cursor A query result for the templates.

File

modules/mongodb_watchdog/src/Logger.php, line 819

Class

Logger
Class Logger is a PSR/3 Logger using a MongoDB data store.

Namespace

Drupal\mongodb_watchdog

Code

public function templates(array $types = [], array $levels = [], $skip = 0, $limit = 0) : Cursor {
  $selector = [];
  if (!empty($types)) {
    $selector['type'] = [
      '$in' => array_values($types),
    ];
  }
  if (!empty($levels) && count($levels) !== count(RfcLogLevel::getLevels())) {

    // Severity levels come back from the session as strings, not integers.
    $selector['severity'] = [
      '$in' => array_values(array_map('intval', $levels)),
    ];
  }
  $options = [
    'sort' => [
      'count' => -1,
      'changed' => -1,
    ],
    'typeMap' => [
      'array' => 'array',
      'document' => 'array',
      'root' => '\\Drupal\\mongodb_watchdog\\EventTemplate',
    ],
  ];
  if ($skip) {
    $options['skip'] = $skip;
  }
  if ($limit) {
    $options['limit'] = $limit;
  }
  $cursor = $this
    ->templateCollection()
    ->find($selector, $options);
  return $cursor;
}