Example #1
0
 /**
  * @param array $parameters
  * @param string $name
  *
  * @return string|null
  */
 private function getStringParamOrNull(array $parameters, $name)
 {
     $value = $this->getParamOrNull($parameters, $name);
     $isStringOrNull = $value === null || is_string($value) === true;
     $isStringOrNull === true ?: $this->exceptionThrower->throwBadRequest();
     return $value;
 }
 /**
  * @param ParametersInterface $parameters
  *
  * @return void
  */
 protected function checkContentTypeHeader(ParametersInterface $parameters)
 {
     // Do not allow specify more than 1 media type for input data. Otherwise which one is correct?
     if (count($parameters->getContentTypeHeader()->getMediaTypes()) > 1) {
         $this->exceptionThrower->throwBadRequest();
     }
     $this->codecMatcher->findDecoder($parameters->getContentTypeHeader());
     // From spec: Servers MUST respond with a 415 Unsupported Media Type status code
     // if a request specifies the header Content-Type: application/vnd.api+json with
     // any media type parameters.
     // We return 415 if no match found for decoder (media type with or wo parameters)
     // If no decoders were configured for media types with parameters we return 415 anyway
     if ($this->codecMatcher->getDecoderHeaderMatchedType() === null) {
         $this->exceptionThrower->throwUnsupportedMediaType();
     }
 }
 /**
  * @param array $parameters
  *
  * @return SortParameterInterface[]|null
  */
 protected function getSortParameters(array $parameters)
 {
     $sortParams = null;
     $sortParam = $this->getParamOrNull($parameters, self::PARAM_SORT);
     if ($sortParam !== null) {
         foreach (explode(',', $sortParam) as $param) {
             $isDesc = false;
             empty($param) === false ? $isDesc = $param[0] === '-' : $this->exceptionThrower->throwBadRequest();
             $sortField = ltrim($param, '+-');
             empty($sortField) === false ?: $this->exceptionThrower->throwBadRequest();
             $sortParams[] = $this->factory->createSortParam($sortField, $isDesc === false);
         }
     }
     return $sortParams;
 }
 /**
  * @param ParametersInterface $parameters
  */
 protected function checkUnrecognized(ParametersInterface $parameters)
 {
     $this->allowUnrecognized === true || empty($parameters->getUnrecognizedParameters()) === true ?: $this->exceptionThrower->throwBadRequest();
 }
Example #5
0
 /**
  * @return void
  */
 protected function checkParametersEmpty()
 {
     $this->getParameters()->isEmpty() === true ?: $this->exceptionThrower->throwBadRequest();
 }