@param $builder
@param $transformer
@param string $key
@param int $perPage

@return array
421555
protected function paginatedCollection($builder, $transformer, string $key = 'data', $perPage = 14): array
    {
        $paginator = $builder->paginate($perPage);

        return [
            $key => fractal(
                $paginator->getCollection(),
                $transformer,
                new DataArraySerializer()
            )->withResourceName(false)->toArray(),

            'meta' => [
                'service' => env('APP_SERVICE_NAME'),
                'entity' => $transformer->getEntity(),
                'pagination' => [
                    'total' => $paginator->total(),
                    'count' => $paginator->count(),
                    'per_page' => $paginator->perPage(),
                    'current_page' => $paginator->currentPage(),
                    'last_page' => $paginator->lastPage(),
                    'first_page_url' => $paginator->url(1),
                    'last_page_url' => $paginator->url($paginator->lastPage()),
                    'next_page_url' => $paginator->nextPageUrl(),
                    'prev_page_url' => $paginator->previousPageUrl(),
                    'from' => $paginator->firstItem(),
                    'to' => $paginator->lastItem(),
                    'has_more' => $paginator->hasMorePages(),
                ],
            ],
        ];
    }
574437
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
    {
        $this->parse();

        return $this->getHandler()->paginate($this->input('limit', $perPage), $this->getColumns($columns), $this->config('prefix', '').$pageName, $page);
    }
1041954
protected function paginate($keys, $page, $perPage)
    {
        return new LengthAwarePaginator(
            $this->chunk($keys, $page, $perPage),
            count($keys),
            20,
            $page,
            [
                'path' => Paginator::resolveCurrentPath(),
                'pageName' => 'page',
            ]
        );
    }
776159
public function getAll($identity, $page = 1, $perPage = 25)
    {
        $params = array(
            'page' => $page,
            'per_page' => $perPage
        );

        return $this->_user->get('account/identity/' . $identity . '/token', $params);
    }
127580
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
    {
        $cacheKey = $this->generateKey([$perPage, $columns, $pageName, $page]);

        return $this->cacheResults(get_called_class(), __FUNCTION__, $cacheKey, function () use ($perPage, $columns, $pageName, $page) {
            return $this->model->paginate($perPage, $columns, $pageName, $page);
        });
    }
418299
public function getList($user, $perPage = 25, $page = 1, $pageName = 'page')
    {
        return $this->getConversationsList($user, $perPage, $page, $pageName);
    }
86539
public function paginate($per_page = 15, $page = null, $page_name = 'page') {
        $page = $page ?: Paginator::resolveCurrentPage($page_name);

        $results = ($total = $this->count()) ? $this->forPage($page, $per_page) : $this->all();

        return $this->paginator($results, $total, $per_page, $page, [
            'path'      => Paginator::resolveCurrentPath(),
            'pageName'  => $page_name,
        ]);
    }
1070247
public function paginate(Model $model, $per_page = 15, array $filters = [], array $columns = ['*'])
    {
        $this->onlyTrashed($model);
        $this->model = $this->relation->apply($this->model, $this);
        $this->model = $this->filter->apply($this->model, $this, $filters);

        return $this->model->order()->paginate($per_page, $columns)->toArray();
    }
1037756
public function fetch($page = 1, $perPage = 15, array $columns = ['*'], array $filter = [], array $sort = [])
    {
        $this->instance = $this->repository->makeQuery();

        $this->multiFilterBy($filter)->multiSortBy($sort);

        $this->parseAliases($this->instance);

        $count = $this->instance->count();
        $items = $this->instance->forPage($page, $perPage)->get($columns);

        $options = [
            'path'  => $this->app->make('request')->url(),
            'query' => compact('page', 'perPage'),
        ];

        return new LengthAwarePaginator($items, $count, $perPage, $page, $options);
    }
1192744
public static function all($perPage = -1, $orderby = 'menu_order', $order = 'ASC')
    {
        $order = strtoupper($order);

        $args = [
            'posts_per_page' => $perPage,
            'orderby'       => $orderby,
            'order'         => $order,
        ];

        return static::query($args);
    }
753286
public function forPage($page, $perPage)
    {
        $offset = max(0, ($page - 1) * $perPage);

        return $this->slice($offset, $perPage);
    }
712729
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
    {
        $page = $page ?: Paginator::resolveCurrentPage($pageName);

        $perPage = $perPage ?: $this->model->getPerPage();

        $results = ($total = $this->toBase()->getCountForPagination())
                                    ? $this->forPage($page, $perPage)->get($columns)
                                    : $this->model->newCollection();

        return $this->paginator($results, $total, $perPage, $page, [
            'path' => Paginator::resolveCurrentPath(),
            'pageName' => $pageName,
        ]);
    }
1035010
public function transform($events, $eventsCount, $page, $maxPerPage)
    {
        $pageCount = count($events);
        $eventsCollection = new EventCollectionObjectRepresentation(
            (int) $page,
            (int) $maxPerPage,
            (int) $numberOfPages = ceil($eventsCount/$maxPerPage),
            (int) $eventsCount,
            $this->calculateLinks($page, $numberOfPages)
        );
        foreach ($events as $event) {
            $eventsCollection->addEvent(new EventObjectRepresentation($event));
        }

        $response = new Response(
            $this->serializer->serialize(
                [
                    $eventsCollection
                ], 'xml'),
            $this->getHttpStatusCode($pageCount)
        );

        $response->headers->set('Content-type', 'text/xml');
        $response->setCharset('utf-8');

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

        return $response;
    }
126129
public function paginate(Builder $builder, $perPage, $page)
    {
        $results = $this->performSearch($builder);

        if ($builder->limit) {
            $results['hits'] = $builder->limit;
        }

        $filtered = $this->discardIdsFromResultSetByConstraints($builder, $results['ids']);

        $results['hits'] = $filtered->count();

        $chunks = array_chunk($filtered->toArray(), $perPage);

        if (empty($chunks)) {
            return $results;
        }

        if (array_key_exists($page - 1, $chunks)) {
            $results['ids'] = $chunks[$page - 1];
        } else {
            $results['ids'] = end($chunks);
        }

        return $results;
    }
642418
public function forPage(int $page, int $perPage)
    {
        return $this->slice(($page - 1) * $perPage, $perPage);
    }
769652
protected function respondWithCollection($builder, $transformer, string $key = 'data'): JsonResponse
    {
        if (to_boolean($this->request->get('paginate', true)) === false) {
            $collection = fractal()->collection($builder)
                ->transformWith($transformer)
                ->withResourceName($key)
                ->toArray();

            $collection['meta'] = [
                'service' => env('APP_SERVICE_NAME'),
                'entity' => $transformer->getEntity()
            ];
        } else {
            $collection = $this->paginatedCollection(
                $builder,
                $transformer,
                $key,
                $this->request->get('per_page', 20)
            );
        }

        $collection['meta'] = $collection['meta'] ?? [];
        $collection['meta']['service'] = env('APP_SERVICE_NAME');
        $collection['meta']['entity'] = $transformer->getEntity();

        return $this->respondWithSuccess(
            $collection
        );
    }
1246382
public function loadTransformations(Transformer $transformer)
    {
        /** @var ConfigurationHelper $configurationHelper */
        $configurationHelper = $this->getHelper('phpdocumentor_configuration');

        $received = array();
        $transformations = $configurationHelper->getConfigValueFromPath('transformations/transformations');
        if (is_array($transformations)) {
            if (isset($transformations['writer'])) {
                $received[] = $this->createTransformation($transformations);
            } else {
                foreach ($transformations as $transformation) {
                    if (is_array($transformation)) {
                        $received[] = $this->createTransformation($transformations);
                    }
                }
            }
        }

        $this->appendReceivedTransformations($transformer, $received);
    }