Esempio n. 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);
     }
 }
Esempio n. 2
0
 /**
  * Find decoder with media type equal to media type in 'Content-Type' header.
  *
  * @param HeaderInterface $contentTypeHeader
  *
  * @return void
  */
 public function matchDecoder(HeaderInterface $contentTypeHeader)
 {
     foreach ($contentTypeHeader->getMediaTypes() as $headerMediaType) {
         /** @var MediaTypeInterface $registeredType */
         foreach ($this->inputMediaTypes as list($registeredType, $closure)) {
             if ($registeredType->equalsTo($headerMediaType) === true) {
                 $this->decoderHeaderMatchedType = $headerMediaType;
                 $this->decoderRegisteredMatchedType = $registeredType;
                 $this->foundDecoder = $closure;
                 return;
             }
         }
     }
     $this->decoderHeaderMatchedType = null;
     $this->decoderRegisteredMatchedType = null;
     $this->foundDecoder = null;
 }