Flarum\Api\Controller\ListPostsController::extractOffset PHP Méthode

extractOffset() protected méthode

protected extractOffset ( Psr\Http\Message\ServerRequestInterface $request )
$request Psr\Http\Message\ServerRequestInterface
    protected function extractOffset(ServerRequestInterface $request)
    {
        $actor = $request->getAttribute('actor');
        $queryParams = $request->getQueryParams();
        $sort = $this->extractSort($request);
        $limit = $this->extractLimit($request);
        $filter = $this->extractFilter($request);
        if (($near = array_get($queryParams, 'page.near')) > 1) {
            if (count($filter) > 1 || !isset($filter['discussion']) || $sort) {
                throw new InvalidParameterException('You can only use page[near] with filter[discussion] and the default sort order');
            }
            $offset = $this->posts->getIndexForNumber($filter['discussion'], $near, $actor);
            return max(0, $offset - $limit / 2);
        }
        return parent::extractOffset($request);
    }