You are here

public function Logger::requestEvents in MongoDB 8.2

Return the events having occurred during a given request.

Parameters

string $requestId: The request unique_id.

int $skip: The number of events to skip in the result.

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

Return value

\Drupal\mongodb_watchdog\EventTemplate|\Drupal\mongodb_watchdog\Event[] An array of [template, event] arrays, ordered by occurrence order.

File

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

Class

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

Namespace

Drupal\mongodb_watchdog

Code

public function requestEvents($requestId, $skip = 0, $limit = 0) : array {
  $templates = $this
    ->requestTemplates($requestId);
  $selector = [
    'requestTracking_id' => $requestId,
    'requestTracking_sequence' => [
      '$gte' => $skip,
      '$lt' => $skip + $limit,
    ],
  ];
  $events = [];
  $options = [
    'typeMap' => [
      'array' => 'array',
      'document' => 'array',
      'root' => '\\Drupal\\mongodb_watchdog\\Event',
    ],
  ];

  /** @var string $templateId */

  /** @var \Drupal\mongodb_watchdog\EventTemplate $template */
  foreach ($templates as $templateId => $template) {
    $eventCollection = $this
      ->eventCollection($templateId);
    $cursor = $eventCollection
      ->find($selector, $options);

    /** @var \Drupal\mongodb_watchdog\Event $event */
    foreach ($cursor as $event) {
      $events[$event->requestTracking_sequence] = [
        $template,
        $event,
      ];
    }
  }
  ksort($events);
  return $events;
}