@param string $collector
@param int    $page
@param int    $maxItemPerPage

@return Paginator
505137
public function findByCollector($collector, $page, $maxItemPerPage)
    {
        $query = $this
            ->createQueryBuilder('c')
            ->where('c.collector = :collector')
            ->setParameter('collector', $collector)
            ->getQuery()
        ;

        $paginator = new Paginator($query);
        $paginator
            ->getQuery()
            ->setFirstResult($maxItemPerPage * ($page - 1))
            ->setMaxResults($maxItemPerPage)
        ;

        return $paginator;
    }
162512
public function getPager($criteria, $page = 1)
    {
        $container = $this->getContainer();

        $paginator = $container->get('knp_paginator');

        $settings = $this->getSettings();

        $limit = $settings['articles_per_page'];

        $parameters = [];

        /** @var ArticlesRepository $repository */
        $repository = $this->getRepository();

        $qb = $repository->createQueryBuilder('p');

        $qb->select('p')->orderBy('p.publicationAt', 'DESC');

        if (!isset($criteria['enabled'])) {
            $criteria['enabled'] = true;
        }

        if (isset($criteria['enabled'])) {
            $currentTime = new \DateTime();

            $qb->andWhere('p.enabled = :enabled');
            $qb->andWhere(
                $qb->expr()->lt('p.publicationAt', ':datetime')
            );

            $parameters['datetime'] = $currentTime;
            $parameters['enabled'] = $criteria['enabled'];
        }

        $qb->setParameters($parameters);

        $pagination = $paginator->paginate(
            $qb,
            $page,
            $limit
        );

        return $pagination;
    }
496791
public function paginate($size = null, $page = null)
    {
        $this->page($size, $page);

        $items = $this->fetch(true);

        if ($this->_limit === null) {
            $count = count($items);
        } elseif (count($items) % $this->_limit === 0) {
            $count = $this->count();
        } else {
            $count = $this->_offset + count($items);
        }

        $paginator = $this->paginator;

        $paginator->items = $items;

        return $paginator->paginate($count, $this->_limit, (int)($this->_offset / $this->_limit) + 1);
    }
657133
protected function paginate($items, $perPage = 15)
    {
        $currentPage = LengthAwarePaginator::resolveCurrentPage();

        $currentPageItems = collect($items)->slice(($currentPage - 1) * $perPage, $perPage);

        return new LengthAwarePaginator($currentPageItems, count($items), $perPage);
    }
328343
protected function addPagination(QueryBuilder $queryBuilder, $elementsPerPage, $page = 1)
    {
        $elementsPerPage = (int)$elementsPerPage;
        $page = (int)$page;

        return $queryBuilder
            ->setMaxResults($elementsPerPage)
            ->setFirstResult($elementsPerPage * ($page - 1));
    }
1114628
public function createPaginator(string $parameter, int $limit = 25): PaginatorInterface
    {
        if (!$this->container->has(ServerRequestInterface::class)) {
            throw new ScopeException("Unable to create paginator, no request scope found");
        }
        /**
         * @var array $query
         */
        $query = $this->container->get(ServerRequestInterface::class)->getQueryParams();

        //Getting page number
        $page = 0;
        if (!empty($query[$parameter]) && is_scalar($query[$parameter])) {
            $page = (int)$query[$parameter];
        }

        return $this->factory->make(Paginator::class, compact('limit', 'parameter'))->withPage($page);
    }
618851
public function aggregate($uuid, $page = 1, $maxPerPage = 25)
    {
        return $this->dataTransformer->transform(
            $this->paginateAggregate($this->eventQuery->fromAggregate($uuid), $page, $maxPerPage),
            $this->eventQuery->streamCount($uuid),
            $page,
            $maxPerPage
        );
    }
346139
public function getMessagesPager(Subject $subject, $page = 1, $max = 20)
    {
        $messages = $this->messageRepo->findBySubject($subject);

        return $this->pagerFactory->createPagerFromArray($messages, $page, $max);
    }
137349
protected function getPage($records, $maxshown, $numpages) {
        $show = floor($numpages / 2);
        if (self::$lastpage > $numpages) {
            self::$page = (self::$current > $show ? (self::$current - $show) : 1);
            if (self::$current < (self::$lastpage - $show)) {
                self::$lastpage = ((self::$current <= $show) ? (self::$current + ($numpages - self::$current)) : (self::$current + $show));
            }
            else { self::$page = self::$current - ($numpages - ((ceil(intval($records) / ($maxshown >= 1 ? intval($maxshown) : 1)) - self::$current)) - 1); }
        }
        else { self::$page = 1; }
    }
620482
public function paginate($page, $perPage = 30)
	{
		$this->set('from', max(0, $perPage * ($page - 1)));
		$this->set('size', $perPage);

		return $this;
	}
372377
public function paginate($items, $perPage = 10, $page = null, $options = [])
    {
        $page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
        $items = $items instanceof Collection ? $items : Collection::make($items);

        return new LengthAwarePaginator(
            $items->forPage($page, $perPage),
            $items->count(),
            $perPage,
            $page,
            $options
        );
    }
666693
public function transform($events, $eventsCount, $page, $maxPerPage)
    {
        $pageCount = count($events);
        $jsonResponse = new JsonResponse(
            $this->serializer->serialize(
                [
                    '_meta' => [
                        'page' => $page,
                        'records_per_page' => $maxPerPage,
                        'total_pages' => $numberOfPages = ceil($eventsCount/$maxPerPage),
                        'total_count' => $eventsCount
                    ],
                    '_links' => [
                        $this->calculateLinks($page, $numberOfPages)
                    ],
                    'events' => (is_array($events)) ? $events : $this->convertEventsDataToArray($events)
                ], 'json'),
            $this->getHttpStatusCode($pageCount),
            [],
            true
        );

        // set infinite cache if page is complete
        if ($maxPerPage === $pageCount) {
            $jsonResponse
                ->setMaxAge(60 * 60 * 24 * 365)
                ->setSharedMaxAge(60 * 60 * 24 * 365);
        }

        return $jsonResponse;
    }
1034126
public function paginate($per_page = 10, $page_name = "page", $page = null)
    {

        $this->take($per_page);

        $page = $page ?: Request::get($page_name, 1);

        $this->skip(($page * $per_page) - $per_page);

        $objects = $this->get();

        return new Pagination($objects, $objects->total, $per_page, $page, ['path' => Request::url(), 'query' => Request::query()]);
    }
943661
private function createCollectionPaginator(Collection $collection, $page, $count)
    {
        return $this->createPaginator(new DoctrineCollectionAdapter($collection), $page, $count);
    }
624531
public static function fromRequest(AbstractQuery $query, $perPage = 15, $pageName = 'page', $fetchJoinCollection = true)
    {
        return new static(
            $query,
            $perPage,
            function () use ($pageName) {
                return Paginator::resolveCurrentPage($pageName);
            },
            $fetchJoinCollection
        );
    }
944868
public static function paginated($perPage, $item = [], $options = [], $query = null)
    {
        $request = new Request();

        if (is_null($query)) {
            $query = 'page';
        }

        if (!count($item)) {
            $item = static::all();
        }

        $currentPage = $request->input($query, null);
        if (is_null($currentPage)) {
            $currentPage = 1;
        }

        $collection = new Collection($item);
        $currentPageResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all();

        if (!isset($options['path'])) {
            $options['path'] = $request->path();
        }

        return new Paginator(
            $currentPageResults, count($collection), $perPage, $currentPage, $options
        );
    }
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,
        ];
    }