AuditEmitter.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Audit;
  4. /**
  5. * Writes one row to `audit_log` per successful state-changing operation.
  6. *
  7. * Implementations MUST swallow infra failures (DB hiccup, OOM during
  8. * JSON encode) and log them — emitting an audit row is observability,
  9. * not a transactional invariant. A failed emit must never propagate
  10. * an exception that aborts the originating request.
  11. */
  12. interface AuditEmitter
  13. {
  14. /**
  15. * @param array<string, mixed> $payload Free-form event payload, JSON-encoded into details_json.
  16. * MUST NOT contain raw secrets (raw tokens, passwords).
  17. * @param string|null $entityLabel Human-readable identifier (name, slug, IP, CIDR, prefix).
  18. * Frozen at write time — later renames don't rewrite history. Pass null only when no
  19. * meaningful label exists (system-wide actions like maintenance.purged).
  20. */
  21. public function emit(
  22. string $action,
  23. ?string $entityType,
  24. int|string|null $entityId,
  25. array $payload,
  26. AuditContext $context,
  27. ?string $entityLabel = null,
  28. ): void;
  29. }