/** * @param string $type * * @return string[] */ private function getIncludePathsByType($type) { // if include paths are set in params use them otherwise use default include paths from schema $includePaths = $this->parameters->getIncludePaths(); if (empty($includePaths) === false) { $typePaths = $includePaths; } else { $schema = $this->container->getSchemaByResourceType($type); $typePaths = $schema->getIncludePaths(); } return $typePaths; }
/** * @param ErrorCollection $errors * @param EncodingParametersInterface $parameters * * @return array */ public function mapParameters(ErrorCollection $errors, EncodingParametersInterface $parameters) { $filters = $this->mapFilterParameters($errors, $parameters->getFilteringParameters()); $sorts = $this->mapSortParameters($errors, $parameters->getSortParameters()); $includes = $this->mapIncludeParameters($errors, $parameters->getIncludePaths()); $paging = $parameters->getPaginationParameters(); return [$filters, $sorts, $includes, $paging]; }
/** * @param ErrorCollection $errors * @param EncodingParametersInterface $parameters */ protected function checkUnrecognized(ErrorCollection $errors, EncodingParametersInterface $parameters) { if ($this->allowUnrecognized === false && empty($parameters->getUnrecognizedParameters()) === false) { foreach ($parameters->getUnrecognizedParameters() as $name => $value) { $errors->addQueryParameterError($name, T::t('Parameter is not allowed.')); } } }
/** * @inheritdoc */ public function search(Builder $builder, EncodingParametersInterface $parameters) { $filters = new Collection((array) $parameters->getFilteringParameters()); if ($this->isFindMany($filters)) { return $this->findMany($builder, $filters); } $this->filter($builder, $filters); $this->sort($builder, (array) $parameters->getSortParameters()); if ($this->isSearchOne($filters)) { return $this->first($builder); } return $this->isPaginated() ? $this->paginate($builder) : $this->all($builder); }
/** * @param string $key * @param mixed $default * @param EncodingParametersInterface|null $parameters * * @return mixed */ protected function getPagingParameter($key, $default, EncodingParametersInterface $parameters = null) { $value = $default; if ($parameters !== null) { $paging = $parameters->getPaginationParameters(); if (empty($paging) === false && array_key_exists($key, $paging) === true) { $tmp = (int) $paging[$key]; $value = $tmp < 0 || $tmp > static::MAX_PAGE_SIZE ? static::MAX_PAGE_SIZE : $tmp; } } return $value; }
/** * @param FilterValidatorInterface $validator * @param EncodingParametersInterface $parameters * @throws JsonApiException */ private function checkFilterParameters(FilterValidatorInterface $validator, EncodingParametersInterface $parameters) { if (!$validator->isValid((array) $parameters->getFilteringParameters())) { throw new ValidationException($validator->getErrors()); } }