/** * @param FREST\Resource $resource * @param array $queryParameterSpecs * @return int * @throws FREST\Exception */ private function generateLimit($resource, &$queryParameterSpecs) { $limit = isset($this->parameters['limit']) ? $this->parameters['limit'] : $resource->getDefaultLimit(); $castedLimit = Type\Variable::castValue($limit, Type\Variable::INT); if (!isset($castedLimit)) { $typeString = Type\Variable::getString(Type\Variable::INT); throw new FREST\Exception(FREST\Exception::InvalidType, "Expecting offset to be of type '{$typeString}' but received '{$limit}'."); } $maxLimit = $resource->getMaxLimit(); if ($castedLimit > $maxLimit) { throw new FREST\Exception(FREST\Exception::InvalidValue, "The limit for this resource must not exceed {$maxLimit}. A limit of {$castedLimit} was supplied."); } $limitQueryParameter = new Spec\QueryParameter('limit', ':_limit', $castedLimit, Type\Variable::INT); $queryParameterSpecs['_limit'] = $limitQueryParameter; return $castedLimit; }