You are here

public function Logger::requestTemplates in MongoDB 8.2

Return an array of templates uses during a given request.

Plugin annotation

@SuppressWarnings(PHPMD . UnusedFormalParameter);

Parameters

string $unsafeRequestId: A request "unique_id".

Return value

\Drupal\mongodb_watchdog\EventTemplate[] An array of EventTemplate instances.

See also

https://github.com/phpmd/phpmd/issues/561

2 calls to Logger::requestTemplates()
Logger::requestEvents in modules/mongodb_watchdog/src/Logger.php
Return the events having occurred during a given request.
Logger::requestEventsCount in modules/mongodb_watchdog/src/Logger.php
Count events matching a request unique_id.

File

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

Class

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

Namespace

Drupal\mongodb_watchdog

Code

public function requestTemplates($unsafeRequestId) : array {
  $selector = [
    // Variable quoted to avoid passing an object and risk a NoSQL injection.
    'requestId' => "{$unsafeRequestId}",
  ];
  $cursor = $this
    ->trackerCollection()
    ->find($selector, static::LEGACY_TYPE_MAP + [
    'projection' => [
      '_id' => 0,
      'template_id' => 1,
    ],
  ]);
  $templateIds = [];
  foreach ($cursor as $request) {
    $templateIds[] = $request['template_id'];
  }
  if (empty($templateIds)) {
    return [];
  }
  $selector = [
    '_id' => [
      '$in' => $templateIds,
    ],
  ];
  $options = [
    'typeMap' => [
      'array' => 'array',
      'document' => 'array',
      'root' => '\\Drupal\\mongodb_watchdog\\EventTemplate',
    ],
  ];
  $templates = [];
  $cursor = $this
    ->templateCollection()
    ->find($selector, $options);

  /** @var \Drupal\mongodb_watchdog\EventTemplate $template */
  foreach ($cursor as $template) {
    $templates[$template->_id] = $template;
  }
  return $templates;
}