$input * @param callable():T $operation * @return T */ public function run(User $actor, Opportunity $before, string $action, array $input, callable $operation): mixed { try { return $operation(); } catch (Throwable $failure) { if ($failure instanceof ValidationException || $failure instanceof AuthorizationException || $failure instanceof AuthenticationException || $failure instanceof ModelNotFoundException || ($failure instanceof HttpExceptionInterface && $failure->getStatusCode() < 500) || ($failure instanceof HttpResponseException && $failure->getResponse()->getStatusCode() < 500)) { throw $failure; } $etag = is_string($input['etag'] ?? null) && preg_match('/^[a-f0-9]{64}$/D', $input['etag']) === 1 ? $input['etag'] : ''; $incident = $this->incidents->record($actor, $before, $action, $etag, $failure); throw new OpportunityWorkflowUnavailable($incident['reference'], $incident['recorded'], $failure); } } }