offset = $offset; $this->size = $size; } /** * Returns the current offset. * * @return int * The query offset. */ public function getOffset() { return $this->offset; } /** * Returns the page size. * * @return int * The requested size of the query result. */ public function getSize() { return $this->size; } /** * Creates an OffsetPage object from a query parameter. * * @param mixed $parameter * The `page` query parameter from the Symfony request object. * * @return static * An OffsetPage object with defaults. */ public static function createFromQueryParameter($parameter) { if (!is_array($parameter)) { $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:page']); throw new CacheableBadRequestHttpException($cacheability, 'The page parameter needs to be an array.'); } $expanded = $parameter + [ static::OFFSET_KEY => static::DEFAULT_OFFSET, static::SIZE_KEY => static::SIZE_MAX, ]; if ($expanded[static::SIZE_KEY] > static::SIZE_MAX) { $expanded[static::SIZE_KEY] = static::SIZE_MAX; } return new static($expanded[static::OFFSET_KEY], $expanded[static::SIZE_KEY]); } }