You are here

class Event in MongoDB 8.2

Class Event is a value object for a logged event.

@package Drupal\mongodb_watchdog

Since this is essentially a value object, naming is constrained by the property names in MongoDB, so ignore variable naming rules for fields.

Plugin annotation


@SuppressWarnings(PHPMD.CamelCasePropertyName)
@SuppressWarnings(Variable)

Hierarchy

  • class \Drupal\mongodb_watchdog\Event implements \MongoDB\BSON\Unserializable

Expanded class hierarchy of Event

2 files declare their use of Event
OverviewController.php in modules/mongodb_watchdog/src/Controller/OverviewController.php
RequestController.php in modules/mongodb_watchdog/src/Controller/RequestController.php
1 string reference to 'Event'
RequestController::buildMainTableHeader in modules/mongodb_watchdog/src/Controller/RequestController.php
Build the main table header.

File

modules/mongodb_watchdog/src/Event.php, line 21

Namespace

Drupal\mongodb_watchdog
View source
class Event implements Unserializable {
  const KEYS = [
    '_id',
    'hostname',
    'link',
    'location',
    'message',
    'referrer',
    'severity',
    'timestamp',
    'type',
    'uid',
    'variables',
    'requestTracking_id',
    'requestTracking_sequence',
  ];

  // @codingStandardsIgnoreStart

  /**
   * The string representation of a MongoId.
   *
   * @var int
   */
  public $_id;

  // @codingStandardsIgnoreEnd

  /**
   * User id. Use uid() instead for type safety.
   *
   * @var int
   */
  public $uid;

  /**
   * Event type, often a module name.
   *
   * @var string
   */
  public $type;

  /**
   * Event template.
   *
   * @var string
   */
  public $message;

  // @codingStandardsIgnoreStart

  /**
   * The identifier of the request during which this event occurred.
   *
   * Coding standards are suspended for requestTracking_id which is required by
   * the MongoDB property.
   *
   * @var string
   */
  public $requestTracking_id;

  // @codingStandardsIgnoreEnd
  // @codingStandardsIgnoreStart

  /**
   * The sequence number of the event during the request when it happened.
   *
   * Coding standards are suspended for requestTracking_sequence which is
   * required by the MongoDB property.
   *
   * @var int
   */
  public $requestTracking_sequence = 0;

  // @codingStandardsIgnoreEnd

  /**
   * The template parameters.
   *
   * @var array
   */
  public $variables = [];

  /**
   * A RFC5424 severity level.
   *
   * @var int
   */
  public $severity = RfcLogLevel::DEBUG;

  /**
   * A link provided by the event emitter. Optional.
   *
   * @var string
   */
  public $link;

  /**
   * The absolute URL for the path on which event was logged. Use location().
   *
   * @var string
   */
  public $location;

  /**
   * A HTTP referrer for the path on which the event was logged. Optional.
   *
   * @var string
   */
  public $referrer;

  /**
   * The server host.
   *
   * @var string
   */
  public $hostname;

  /**
   * The timestamp at which the event was logged.
   *
   * @var int
   */
  public $timestamp = 0;

  /**
   * Constructor.
   *
   * @param array $event
   *   The event in array form.
   */
  public function __construct(array $event) {
    $this
      ->bsonUnserialize($event);
  }

  /**
   * {@inheritdoc}
   */
  public function bsonUnserialize(array $data) : void {
    foreach (static::KEYS as $key) {
      if (isset($data[$key])) {
        $this->{$key} = $data[$key];
      }
    }
  }

  /**
   * Type-safe getter for location.
   *
   * @return string
   *   The location property, always as a string, never NULL.
   */
  public function location() : string {
    return (string) $this->location ?? '';
  }

  /**
   * Type-safe getter for uid.
   *
   * @return int
   *   The uid property, always as an int, never NULL.
   */
  public function uid() : int {
    return (int) $this->uid;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Event::$hostname public property The server host.
Event::$link public property A link provided by the event emitter. Optional.
Event::$location public property The absolute URL for the path on which event was logged. Use location().
Event::$message public property Event template.
Event::$referrer public property A HTTP referrer for the path on which the event was logged. Optional.
Event::$requestTracking_id public property The identifier of the request during which this event occurred.
Event::$requestTracking_sequence public property The sequence number of the event during the request when it happened.
Event::$severity public property A RFC5424 severity level.
Event::$timestamp public property The timestamp at which the event was logged.
Event::$type public property Event type, often a module name.
Event::$uid public property User id. Use uid() instead for type safety.
Event::$variables public property The template parameters.
Event::$_id public property The string representation of a MongoId.
Event::bsonUnserialize public function
Event::KEYS constant
Event::location public function Type-safe getter for location.
Event::uid public function Type-safe getter for uid.
Event::__construct public function Constructor.