/** * @inheritdoc */ protected function getMediaType() { $type = $this->service->getApi()->getCodecMatcher()->getEncoderRegisteredMatchedType(); if (!$type instanceof MediaTypeInterface) { throw new RuntimeException('No matching media type for encoded JSON-API response.'); } return $type; }
/** * @inheritdoc */ public function getPerPage($default = 15, $max = null) { $key = $this->service->getApi()->getPagingStrategy()->getPerPage(); $perPage = (int) $this->getParam($key); if (is_int($max) && $perPage > $max) { $perPage = $max; } return 0 < $perPage ? $perPage : $default; }
/** * @param int|null $page * @param int $perPage * @param array $parameters * @param array|object|null $meta * @return LinkInterface|null */ protected function createLink($page, $perPage, array $parameters = [], $meta = null) { if (!is_int($page)) { return null; } $strategy = $this->service->getApi()->getPagingStrategy(); return $this->linkTo()->current(array_merge($parameters, [QueryParametersParserInterface::PARAM_PAGE => [$strategy->getPage() => $page, $strategy->getPerPage() => $perPage]]), $meta); }
/** * @param ResourceIdentifierInterface $identifier * @return Model */ protected function findRelated(ResourceIdentifierInterface $identifier) { $model = $this->service->getApi()->getStore()->find($identifier); if (!$model instanceof Model) { throw new RuntimeException('Expecting a related resource to be an Eloquent model'); } return $model; }