delegate()->ok($data); } public function created(array $data = [], ?string $location = null): ResponseInterface { return $this->delegate()->created($data, $location); } public function noContent(): ResponseInterface { return $this->delegate()->noContent(); } public function error(int $status, string $title, ?string $detail = null, array $extra = []): ResponseInterface { return $this->delegate()->error($status, $title, $detail, $extra); } public function fromArray(array $payload, int $status = 200): ResponseInterface { return $this->delegate()->fromArray($payload, $status); } private function delegate(): ApiResponseFactoryInterface { $req = RequestContext::get(); $format = $req?->getAttribute(Negotiation::ATTR_API_FORMAT) ?? 'rest'; return $format === 'jsonapi' ? $this->jsonapi : $this->rest; } }