getEncoderHeaderMatchedType() public method

Get media type from 'Accept' header that matched to one of the registered encoder media types.
public getEncoderHeaderMatchedType ( ) : Neomerx\JsonApi\Contracts\Http\Headers\AcceptMediaTypeInterface | null
return Neomerx\JsonApi\Contracts\Http\Headers\AcceptMediaTypeInterface | null
Beispiel #1
0
 /**
  * Check accept header
  *
  * @param AcceptHeaderInterface $header
  * @return Error
  */
 private function checkAcceptHeader(AcceptHeaderInterface $header)
 {
     $this->matcher->matchEncoder($header);
     if (null === $this->matcher->getEncoderHeaderMatchedType()) {
         throw new JsonApiException($this->createApiError(JsonApiException::HTTP_CODE_UNSUPPORTED_MEDIA_TYPE, self::UNSUPPORTED_ACCEPT_ERROR, 'Unsupported media type'), JsonApiException::HTTP_CODE_UNSUPPORTED_MEDIA_TYPE);
     }
 }
 /**
  * @param HeaderParametersInterface $parameters
  *
  * @return void
  */
 protected function checkAcceptHeader(HeaderParametersInterface $parameters)
 {
     $this->codecMatcher->matchEncoder($parameters->getAcceptHeader());
     // From spec: Servers MUST respond with a 406 Not Acceptable status code
     // if a request's Accept header contains the JSON API media type and all
     // instances of that media type are modified with media type parameters.
     // We return 406 if no match found for encoder (media type with or wo parameters)
     // If no encoders were configured for media types with parameters we return 406 anyway
     if ($this->codecMatcher->getEncoderHeaderMatchedType() === null) {
         throw new E([], E::HTTP_CODE_NOT_ACCEPTABLE);
     }
 }