context = $context; $this->timestamp = microtime(true); $this->identifier = bin2hex(random_bytes(16)); } /** * Get the event label */ public function label(): string { return $this->label; } /** * Get a context value by key */ public function get(string $key, mixed $default = null): mixed { return $this->context[$key] ?? $default; } /** * Check if a context key exists */ public function has(string $key): bool { return array_key_exists($key, $this->context); } /** * Get the event context */ public function context(): array { return $this->context; } /** * Get all event context */ public function all(): array { return $this->context; } /** * Get the event timestamp */ public function timestamp(): float { return $this->timestamp; } public function identifier(): string { return $this->identifier; } /** * Stop event propagation to subsequent listeners */ public function stopPropagation(): void { $this->propagationStopped = true; } /** * Check if propagation is stopped */ public function isPropagationStopped(): bool { return $this->propagationStopped; } /** * Get tenant ID for multi-tenant context */ public function tenantIdentifier(): ?string { return $this->tenantIdentifier; } /** * Get the identity of the actor who triggered the event */ public function actorIdentity(): ?string { return $this->actorIdentity; } private static function validateContext(array $context): void { foreach ($context as $value) { if (is_array($value)) { self::validateContext($value); continue; } if ($value !== null && !is_scalar($value)) { throw new \InvalidArgumentException( 'Event context must contain only scalar, null, or array values.', ); } } } }