/** * @inheritdoc */ public function render(Exception $exception) { $mediaType = $this->getMediaType(); // Media type should be specified for exception renderers $mediaType !== null ?: Exceptions::throwInvalidArgument('mediaType', $mediaType); return $this->responses->getResponse($this->getStatusCode(), $mediaType, $this->getContent($exception), $this->getSupportedExtensions(), $this->getHeaders()); }
/** * Get render that returns JSON API response with JSON API Error objects and specified HTTP status code. * * @param int $statusCode * * @return Closure */ protected function getErrorsRender($statusCode) { /** * @param ErrorInterface[] $errors * @param EncoderOptions $encodeOptions * * @return mixed */ return function (array $errors, EncoderOptions $encodeOptions = null) use($statusCode) { $extensionsClosure = $this->extensionsClosure; /** @var SupportedExtensionsInterface $supportedExtensions */ $supportedExtensions = $extensionsClosure(); $content = Encoder::instance([], $encodeOptions)->errors($errors); $mediaType = $this->factory->createMediaType(MediaTypeInterface::JSON_API_TYPE, MediaTypeInterface::JSON_API_SUB_TYPE); return $this->responses->getResponse($statusCode, $mediaType, $content, $supportedExtensions); }; }
/** * Get response with regular JSON API Document in body. * * @param object|array $data * @param int $statusCode * @param array<string,\Neomerx\JsonApi\Contracts\Schema\LinkInterface>|null $links * @param mixed $meta * * @return Response */ protected function getContentResponse($data, $statusCode = Response::HTTP_OK, $links = null, $meta = null) { $parameters = $this->getParameters(); $encoder = $this->codecMatcher->getEncoder(); $outputMediaType = $this->codecMatcher->getEncoderRegisteredMatchedType(); $content = $encoder->encode($data, $links, $meta, $parameters); return $this->responses->getResponse($statusCode, $outputMediaType, $content, $this->supportedExtensions); }
/** * @inheritdoc */ public function render(Exception $exception) { $mediaType = $this->getMediaType(); assert('$mediaType !== null', 'Media type should be specified for exception renderers.'); return $this->responses->getResponse($this->getStatusCode(), $mediaType, $this->getContent($exception), $this->getSupportedExtensions(), $this->getHeaders()); }