public function paginate(AdapterInterface $adapter, PaginatedCollectionRequestInterface $paginationInfo = null)
    {
        if (is_null($paginationInfo)) {
            if (is_null($this->paginationInfoProvider)) {
                throw new \LogicException(
                    'A PaginatedCollectionRequestProviderInterface must be injected if you want to use pagination '.
                    'and don\t want to handle the pagination info with your own logic.'
                );
            }

            $paginationInfo = $this->paginationInfoProvider->getPaginatedCollectionRequest();

            if (is_null($paginationInfo)) {
                throw new \LogicException(
                    'No pagination could be provided by the PaginatedCollectionRequestProviderInterface. The provider '.
                    'must at least provide default pagination information in order to use the paginate() method.'
                );
            }
        }

        $pager = new Pagerfanta($adapter);

        try {
            $pager
                ->setMaxPerPage($paginationInfo->getItemsPerPage())
                ->setCurrentPage($paginationInfo->getPage());
        } catch (LessThan1CurrentPageException $e) {
            $invalidPageException = new InvalidRequestedPage();

            $invalidPageException
                ->setRequestedPage($paginationInfo->getPage())
                ->setTargetPage(1);

            throw $invalidPageException;
        } catch (OutOfRangeCurrentPageException $e) {
            $invalidPageException = new InvalidRequestedPage();

            $invalidPageException
                ->setRequestedPage($paginationInfo->getPage())
                ->setTargetPage($pager->getNbPages() - 1);

            throw $invalidPageException;
        }

        return $pager;
    }