@param FinderItem|null $finder

@throws \Exception

@return LengthAwarePaginator
198738
public function search(FinderItem $finder = null): LengthAwarePaginator
    {
        if ($finder) {
            $this->query = $finder($this->query);
        }

        return $this->query->paginate();
    }
229811
public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = [])
    {
        $queryParams = array_diff_key($_GET, array_flip(['page']));
        $paginator->appends($queryParams);
        
        $resource = new Collection($paginator->items(), $transformer, $resourceKey);
        $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));

        foreach ($meta as $metaKey => $metaValue) {
            $resource->setMetaValue($metaKey, $metaValue);
        }

        $rootScope = $this->manager->createData($resource);

        return $this->withArray($rootScope->toArray());
    }
1328803
public function search($class, array $finderParams = [], array $serializerOptions = [])
    {
        $queryParams = self::parseQueryParams($finderParams);
        $page = $queryParams['page'];
        $limit = $queryParams['limit'];
        $filters = $queryParams['filters'];
        $allFilters = $queryParams['allFilters'];
        $sortBy = $queryParams['sortBy'];
        // count the total results (without pagination)
        $count = $this->fetch($class, $allFilters, $sortBy, $page, $limit, true);
        // get the list of data for the current search and page
        $data = $this->fetch($class, $allFilters, $sortBy, $page, $limit);

        if (0 < $count && empty($data)) {
            // search should have returned results, but we have requested a non existent page => get the last page
            $page = ceil($count / $limit) - 1;
            // load last page data
            $data = $this->fetch($class, $allFilters, $sortBy, $page, $limit);
        }

        return self::formatPaginatedData(
            array_map(function ($result) use ($serializerOptions) {
                return $this->serializer->serialize($result, $serializerOptions);
            }, $data),
            $count,
            $page,
            $limit,
            $filters,
            $sortBy
        );
    }
1121494
protected function initBuildUrlClosure(LengthAwarePaginator $paginator, $url, array $parameters = [])
    {
        if ($this->buildUrlClosure === null) {
            $pageSize   = $paginator->perPage();
            $urlLength  = strlen($url);
            $separator  = $urlLength > 0 && substr($url, -1) === '/' ? '?' : '/?';

            $this->buildUrlClosure = function ($pageNumber) use ($url, $parameters, $separator, $pageSize) {
                $paramsWithPaging = array_merge($parameters, [
                    QueryParametersParserInterface::PARAM_PAGE => [
                        self::PARAM_PAGING_SIZE   => $pageSize,
                        self::PARAM_PAGING_NUMBER => $pageNumber,
                    ]
                ]);
                $fullUrl = $url . $separator . http_build_query($paramsWithPaging);

                return $fullUrl;
            };
        }
    }
201481
public function getManyFiles(Block $block, QueryBuilder $builder): LengthAwarePaginator
    {
        $query = $block->files(false)->with(['type','translations']);

        $count = clone $query->getQuery();

        $results = $query->limit($builder->getPageSize())
            ->offset($builder->getPageSize() * ($builder->getPage() - 1))
            ->get(['files.*']);

        return new LengthAwarePaginator(
            $results,
            $count->select('files.id')->get()->count(),
            $builder->getPageSize(),
            $builder->getPage()
        );
    }
794493
public function setLength($length = null)
    {
        $length = (null === $length) ? $this->datasetCount : $length;
        $this->length = (\abs($length) > $this->datasetCount) ? $this->datasetCount : $length;

        return $this;
    }
207290
private function loadSerializerClassMap(Finder $finder)
    {
        $classMap = [];
        foreach ($finder as $file) {
            $document = new \DOMDocument();
            $document->load($file);

            $xpath = new \DOMXPath($document);

            $classMap = array_reduce(
                iterator_to_array($xpath->query('//class')),
                function (array $classMap, \DOMElement $element) {
                    $classMap[$element->getAttribute('name')] = $element;
                    return $classMap;
                },
                $classMap
            );
        }

        return $classMap;
    }
1345438
public function findByXpath($locator)
    {
        $locator = \Normalizer::normalize($locator, \Normalizer::FORM_D);
        return parent::find($locator);
    }
704662
public function build()
    {
        $result = new Finder();
        if (method_exists($result, 'useBestAdapter')) {
            $result->useBestAdapter();
        }
        $result->ignoreDotFiles(false);
        $result->ignoreVCS(false);

        return $result;
    }
550392
public static function create($data = null, $transformer = null, $serializer = null)
    {
        $fractal = parent::create($data, $transformer, $serializer);

        if (config('fractal.auto_includes.enabled')) {
            $requestKey = config('fractal.auto_includes.request_key');

            if ($include = app('request')->query($requestKey)) {
                $fractal->parseIncludes($include);
            }
        }

        if (empty($serializer)) {
            $serializer = config('fractal.default_serializer');
        }

        if ($data instanceof LengthAwarePaginator) {
            $paginator = config('fractal.default_paginator');

            if (empty($paginator)) {
                $paginator = IlluminatePaginatorAdapter::class;
            }

            $fractal->paginateWith(new $paginator($data));
        }

        if (empty($serializer)) {
            return $fractal;
        }

        if ($serializer instanceof SerializerAbstract) {
            return $fractal->serializeWith($serializer);
        }

        if ($serializer instanceof Closure) {
            return $fractal->serializeWith($serializer());
        }

        if ($serializer == JsonApiSerializer::class) {
            $baseUrl = config('fractal.base_url');

            return $fractal->serializeWith(new $serializer($baseUrl));
        }

        return $fractal->serializeWith(new $serializer);
    }
475814
public static function SubsequenceWithLength( $iter, $startingLoc, $length )
	{
		if ( $startingLoc instanceof XPath2Item )
		{
			$startingLoc = $startingLoc->getTypedValue();
		}

		$startingLoc = round( $startingLoc );

		if ( $length instanceof XPath2Item )
		{
			$length = $length->getTypedValue();
		}

		$length = round( $length );

		if ( $startingLoc == INF || $startingLoc == -INF || is_nan( $startingLoc ) || is_nan( $length ) )
		{
			return EmptyIterator::$Shared;
		}
		return new NodeIterator( function() use( $iter, $startingLoc, $length ) { return ExtFuncs::SubsequenceIterator( $iter->CloneInstance(), $startingLoc, $length ); } );
	}
737669
public function getPaginator( $where = null, $order = null )
    {
        return new Paginator\Paginator(
            new Paginator\Adapter\Iterator(
                $this->findIterator( $where, $order )
            )
        );
    }
165272
public function addFinder(FormatFinder ...$finder) {
        foreach ($finder as $f) {
            if (false === array_search($f, $this->finders, true)) {
                $this->finders[] = $f;
            }
        }
    }
91073
protected function finderWrapperInject($finder)
    {
        foreach ($this->wrappedMethodHistory as $row) {
            call_user_func_array(array($finder, $row['method']), $row['args']);
        }
    }
872744
public function do_length($topic, $priority = null)
    {
        $redis = is_object($this->_redis) ? $this->_redis : $this->_getRedis();
        if ($priority === null) {
            $length = 0;
            foreach ($this->_priorities as $p) {
                $length += $redis->lLen($this->_prefix . $topic . ':' . $p);
            }

            return $length;
        } else {
            return $redis->lLen($this->_prefix . $topic . ':' . $priority);
        }
    }
563015
public function paginateES(int $size = 20, string $sortBy = "", string $sortType = "ASC", int $page = null) : LengthAwarePaginator
    {
        if(!$page) {
            $page = (Input::get("page") ? Input::get("page") : 1);
        }

        $from = (($page * $size) - $size);

        $data = $this->getESItems($size, $from, $sortBy, $sortType);
        return new LengthAwarePaginator($data['items'], $data['elasticData']['hits']['total'], $size, $page);
    }
272489
public static function minLength($value, $length)
    {
        return Validator::string()->length($length, null)->validate($value);
    }