function EventLogSubscriber::logEventInfo

Same name and namespace in other branches
  1. 11.x core/modules/package_manager/tests/modules/package_manager_test_event_logger/src/EventSubscriber/EventLogSubscriber.php \Drupal\package_manager_test_event_logger\EventSubscriber\EventLogSubscriber::logEventInfo()

Logs all events in the stage life cycle.

Parameters

\Drupal\package_manager\Event\SandboxEvent $event: The event object.

File

core/modules/package_manager/tests/modules/package_manager_test_event_logger/src/EventSubscriber/EventLogSubscriber.php, line 46

Class

EventLogSubscriber
Defines an event subscriber to test logging during events in Package Manager.

Namespace

Drupal\package_manager_test_event_logger\EventSubscriber

Code

public function logEventInfo(SandboxEvent $event) : void {
  $log_file = \Drupal::service(PathLocator::class)->getProjectRoot() . '/' . self::LOG_FILE_NAME;
  if (file_exists($log_file)) {
    $log_data = file_get_contents($log_file);
    $log_data = json_decode($log_data, TRUE, flags: JSON_THROW_ON_ERROR);
  }
  else {
    $log_data = [];
  }
  $log_data[] = [
    'event' => $event::class,
    'stage' => $event->sandboxManager::class,
  ];
  file_put_contents($log_file, json_encode($log_data, JSON_UNESCAPED_SLASHES));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.