Ejemplo n.º 1
0
 /**
  * @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());
 }
Ejemplo n.º 2
0
 /**
  * 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);
     };
 }
Ejemplo n.º 3
0
 /**
  * @param object                                                             $resource
  * @param array<string,\Neomerx\JsonApi\Contracts\Schema\LinkInterface>|null $links
  * @param mixed                                                              $meta
  *
  * @return Response
  */
 protected function getCreatedResponse($resource, $links = null, $meta = null)
 {
     $parameters = $this->getParameters();
     $encoder = $this->codecMatcher->getEncoder();
     $outputMediaType = $this->codecMatcher->getEncoderRegisteredMatchedType();
     $content = $encoder->encode($resource, $links, $meta, $parameters);
     $urlPrefix = $encoder->getEncoderOptions() === null ? null : $encoder->getEncoderOptions()->getUrlPrefix();
     $location = $urlPrefix . $this->schemaContainer->getSchema($resource)->getSelfSubLink($resource)->getSubHref();
     return $this->responses->getCreatedResponse($location, $outputMediaType, $content, $this->supportedExtensions);
 }
Ejemplo n.º 4
0
 /**
  * @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());
 }