$ruleScope, 'type' => $ruleType, 'action' => $ruleAction, 'value' => $ruleValue, 'origin' => $origin, ] as $field => $value) { if ($value === '') { throw new \InvalidArgumentException("Firewall rule events require a rule {$field}."); } } foreach ([ 'scope' => $ruleScope, 'type' => $ruleType, 'action' => $ruleAction, 'value' => $ruleValue, 'origin' => $origin, ] as $field => $value) { if ($value === '') { throw new \InvalidArgumentException("Firewall rule events require a rule {$field}."); } } parent::__construct( static::class, [ 'ruleId' => $ruleId, 'ruleScope' => $ruleScope, 'ruleType' => $ruleType, 'ruleAction' => $ruleAction, 'ruleValue' => $ruleValue, 'reason' => $reason, 'origin' => $origin, 'expiresAt' => $expiresAt, ...$details, ], $tenantId, $identityId, ); } public static function fromRule( FirewallRuleObject $rule, ?string $actorId = null, array $change = [], ): static { $metadata = $rule->getMetadata() ?? []; $details = [...$metadata, ...$change]; foreach ([ 'ruleId', 'ruleScope', 'ruleType', 'ruleAction', 'ruleValue', 'reason', 'origin', 'expiresAt', ] as $reservedKey) { unset($details[$reservedKey]); } return new static( ruleId: (string) $rule->getId(), ruleScope: (string) $rule->getScope(), ruleType: (string) $rule->getType(), ruleAction: (string) $rule->getAction(), ruleValue: (string) $rule->getValue(), reason: $rule->getReason(), origin: (string) ($metadata['origin'] ?? 'manual'), expiresAt: $rule->getExpiresAt()?->format(\DateTimeInterface::ATOM), details: $details, tenantId: $rule->getTenantId(), identityId: $actorId ?? $rule->getCreatedBy(), ); } public function getRuleId(): string { return $this->ruleId; } public function getRuleScope(): string { return $this->ruleScope; } public function getRuleType(): string { return $this->ruleType; } public function getRuleAction(): string { return $this->ruleAction; } public function getRuleValue(): string { return $this->ruleValue; } public function getOrigin(): string { return $this->origin; } public function getExpiresAt(): ?string { return $this->expiresAt; } public function getDetails(): array { return $this->details; } public function getUserId(): ?string { return null; } public function getReason(): ?string { return $this->reason; } public function getSeverity(): SecurityEventSeverity { return SecurityEventSeverity::INFO; } }