@param AdapterInterface $adapter
@param int              $page
@param int              $count

@return PagerfantaPaginatorAdapter
163905
private function createPaginator(AdapterInterface $adapter, $page, $count)
    {
        $pager = new Pagerfanta($adapter);

        try {
            $pager->setMaxPerPage($count)->setCurrentPage($page);
        } catch (NotValidCurrentPageException $e) {
            // Do nothing, because we don't care ...
        }

        return new PagerfantaPaginatorAdapter($pager, function ($page) {
            return "page={$page}";
        });
    }
911935
public PageFilter withPage(int pageNumber, int amountPerPage) {
        parameters.put("page", pageNumber);
        parameters.put("per_page", amountPerPage);
        return this;
    }
1011454
public function countPages(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collPagesPartial && !$this->isNew();
        if (null === $this->collPages || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collPages) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getPages());
            }

            $query = ChildPageQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySource($this)
                ->count($con);
        }

        return count($this->collPages);
    }
1075575
public function prependAdapter(AdapterInterface $adapter)
    {
        $priority = self::DEFAULT_PRIORITY;

        if (!$this->adapters->isEmpty()) {
            $extractedNodes = $this->adapters->toArray(PriorityQueue::EXTR_PRIORITY);

            rsort($extractedNodes, SORT_NUMERIC);

            $priority = $extractedNodes[0] + 1;
        }

        $this->adapters->insert($adapter, $priority);

        return $this;
    }
720910
final public function limit($offsetOrCount, $count = null)
    {
        $this->getQuery()->limit($offsetOrCount, $count);
        $this->pagedQuery = true;

        return $this;
    }
1249549
protected function createPager(AdapterInterface $adapter, $currentPage, $maxPerPage, Tag $tag = null)
    {
        if ($adapter instanceof TagAdapterInterface && $tag instanceof Tag) {
            $adapter->setTag($tag);
        }

        $pager = new Pagerfanta($adapter);

        $pager->setNormalizeOutOfRangePages(true);
        $pager->setMaxPerPage($maxPerPage);
        $pager->setCurrentPage($currentPage > 0 ? $currentPage : 1);

        return $pager;
    }
383239
public function fetch($class, array $filters = [], array $sortBy = null, $page = 0, $limit = -1, $count = false)
    {
        try {
            return $this->get($class)->find($filters, $sortBy, $page, $limit, $count);
        } catch (FinderException $e) {
            $data = $this->om->getRepository($class)->findBy($filters, null, 0 < $limit ? $limit : null, $page);

            return $count ? count($data) : $data;
        }
    }
640232
public function setAdapter(AdapterInterface $adapter)
    {
        $adapter->setClient($this);

        $this->adapter = $adapter;

        return $this;
    }
347420
public function iterNextPage($count = 3)
    {
        if ($this->getPage() == 1 && $this->getPagesCount() >= $count * 2) {
            $count *= 2;
        }
        $pages = [];
        foreach (range(1, $count) as $i) {
            $page = $this->getPage() + $i;
            if ($page <= $this->getPagesCount()) {
                $pages[] = $page;
            }
        }

        return $pages;
    }
1080134
public function getTransactionDetailsForUser($user_id, $count = 10, $paginated_url = null, $page = 1){
        if($paginated_url) {
            $url = $paginated_url;
        }else {
            $url = $this->authenticationService->getServerEndPoint() . Endpoints::VERSION . Endpoints::BASE_WALLET
                . Endpoints::WALLET_TRANSACTIONS_USER . ($paginated_url ? '' : '?page=' . (int) $page);
            $url = sprintf($url, $user_id, $count);
        }

        $result = $this->authenticationService->getTransport()->fetch($url);

        if($result["code"] == APIResponse::RESPONSE_SUCCESS){
            $this->maskData($result['results']['data']);
            $paginatedResult = new PaginatedResults($result['results'],array($this,'getTransactionDetailsForUser'),array($user_id,$count));
            return $paginatedResult;
        }else{
            return new PaginatedResults(array(),null,null);
        }

    }
207132
private function decidePaginatorFormat(
        DoctrinePaginator $paginator,
        string $parameterType,
        int $limitPerPage,
        int $page
    ) {
        if (Pagerfanta::class === $parameterType) {
            $paginator = new Pagerfanta(new DoctrineORMAdapter($paginator->getQuery()));
            $paginator->setMaxPerPage($limitPerPage);
            $paginator->setCurrentPage($page);
        }
        if (PaginationInterface::class === $parameterType) {
            $knp = new KnpPaginator();
            $paginator = $knp->paginate($paginator->getQuery(), $page, $limitPerPage);
        }

        return $paginator;
    }
1141205
private function setPager($query, $page, $maxPerPage)
    {
        $adapter = new DoctrineORMAdapter($query);
        $pager = new PagerFanta($adapter);
        $pager
            ->setMaxPerPage($maxPerPage)
            ->setCurrentPage($page)
        ;

        // Pagerfanta returns a traversable object, not directly serializable
        $posts = [];
        foreach ($pager->getCurrentPageResults() as $post) {
            $posts[] = $post;
        }

        return [
            'total' => $pager->getNbResults(),
            'count' => count($posts),
            'posts' => $posts,
        ];
    }
181897
public function getRowsCount($offset, $count)
    {
        //check whether worksheet name is set or not
        if ($this->worksheetName == '')
            throw new Exception('Worksheet name not specified');
        $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() .
            '/worksheets/' . $this->worksheetName . '/cells/rows?offset=' . $offset . '&count=' . $count;
        $signedURI = Utils::sign($strURI);
        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
        $json = json_decode($responseStream);
        return $json->Rows->RowsCount;

    }
886198
public function pagination($page, $limit, $query = null, $orderBy = null, $sort = 'ASC', $filter = null)
    {
        $entityClassAlias = $this->getEntityClassAlias();

        // Create a Doctrine Collection
        $queryBuilder = $this->getObjectManager()->createQueryBuilder();
        $queryBuilder->select($entityClassAlias)
                     ->from($this->getEntityClass(), $entityClassAlias);

        $paramCounter = 0;

        if (is_array($filter)) {
            $paramCounter = $this->addFilterToQueryBuilder($filter, $queryBuilder);
        }

        //Add joins to query builder
        $this->addJoinTablesToQueryBuilder($queryBuilder);

        if (null !== $query) {
            $properties    = $this->getQueryableProperties();
            $orExpressions = array();
            $paramCounter++;

            foreach ($properties as $property) {
                $orExpressions[] = $queryBuilder->expr()->like($property, '?' . $paramCounter);
            }

            $queryBuilder->andWhere(
                call_user_func_array(array($queryBuilder->expr(), "orX"), $orExpressions)
            );

            $queryBuilder->setParameter($paramCounter, $query);
        }

        if ($orderBy) {
            $orderByIdentifier = $this->getOrderByIdentifier($orderBy);

            if (!$sort) {
                $sort = 'ASC';
            }
            $queryBuilder->orderBy($orderByIdentifier, $sort);
        }

        // Create the paginator itself
        $paginator = new Paginator(
            new DoctrinePaginator(new ORMPaginator($queryBuilder))
        );

        $paginator->setCurrentPageNumber($page)
                  ->setItemCountPerPage($limit)
                  ->setPageRange(5);

        return $paginator;
    }
117135
private function handle(Response $response, $count = false)
    {
        $responseData = json_decode($response->getContent(), true);

        if (!$response->isSuccessful()) {
            // @todo get better error
            throw new \RuntimeException($response->getContent());
        }

        if (true === $count) {
            switch ($responseData['kind']) {
                case 'youtube#playlistItemListResponse':
                    return (int) $responseData['pageInfo']['totalResults'];
                    break;

                default:
                    throw new \Exception('unsupported count operation');
                    break;
            }
        }

        if (isset($responseData['nextPageToken'])) {
            $this->nextPageToken = $responseData['nextPageToken'];
        } else {
            $this->nextPageToken = null;
        }
        return $responseData['items'];
    }
159675
protected function getPaginator4QueryBuilder($queryBuilder, $page = 1)
    {
        if (!$queryBuilder) {
            return null;
        }

        $adapter = new DoctrineAdapter(new ORMPaginator($queryBuilder));
        $paginator = new Paginator($adapter);
        $paginator->setDefaultItemCountPerPage($this->defaultItemCountPerPage);
        $paginator->setCurrentPageNumber($page);

        return $paginator;
    }
415392
static public function count($countable, $count, $message = null, $propertyPath = null)
        {
            if ($count !== count($countable)) {
                $message = $message ?: sprintf(
                    'List does not contain exactly "%d" elements.',
                    static::stringify($countable),
                    static::stringify($count)
                );

                throw static::createException($countable, $message, static::INVALID_COUNT, $propertyPath, array('count' => $count));
            }
        }