Neomerx\JsonApi\Contracts\Codec\CodecMatcherInterface::getDecoderHeaderMatchedType PHP Method

getDecoderHeaderMatchedType() public method

Get media type from 'Content-Type' header that matched to one of the registered decoder media types.
public getDecoderHeaderMatchedType ( ) : Neomerx\JsonApi\Contracts\Http\Headers\MediaTypeInterface | null
return Neomerx\JsonApi\Contracts\Http\Headers\MediaTypeInterface | null
    public function getDecoderHeaderMatchedType();

Usage Example

Example #1
0
 /**
  * Check content type header
  *
  * @param HeaderInterface $header
  */
 private function checkContentTypeHeader(HeaderInterface $header)
 {
     if (count($header->getMediaTypes()) > 1) {
         throw new JsonApiException($this->createApiError(JsonApiException::HTTP_CODE_BAD_REQUEST, self::INVALID_CONTENT_TYPE_ERROR, "Invalid content type"), JsonApiException::HTTP_CODE_BAD_REQUEST);
     }
     $this->matcher->matchDecoder($header);
     if (null === $this->matcher->getDecoderHeaderMatchedType()) {
         throw new JsonApiException($this->createApiError(JsonApiException::HTTP_CODE_UNSUPPORTED_MEDIA_TYPE, self::UNSUPPORTED_CONTENT_TYPE_ERROR, 'Unsupported content type'), JsonApiException::HTTP_CODE_UNSUPPORTED_MEDIA_TYPE);
     }
 }
All Usage Examples Of Neomerx\JsonApi\Contracts\Codec\CodecMatcherInterface::getDecoderHeaderMatchedType