get Paginator object

@param  \Kitpages\DataGridBundle\Paginator\PaginatorConfig $paginatorConfig
@param  \Symfony\Component\HttpFoundation\Request      $request
@return \Kitpages\DataGridBundle\Paginator\Paginator
199898
public function getPaginator(PaginatorConfig $paginatorConfig, Request $request)
    {
        $queryBuilder = $paginatorConfig->getQueryBuilder();
        // insert default values in paginator config
        $paginatorConfig = clone($paginatorConfig);
        if (is_null($paginatorConfig->getItemCountInPage())) {
            $paginatorConfig->setItemCountInPage($this->paginatorParameterList["item_count_in_page"]);
        }
        if (is_null($paginatorConfig->getVisiblePageCountInPaginator())) {
            $paginatorConfig->setVisiblePageCountInPaginator($this->paginatorParameterList["visible_page_count_in_paginator"]);
        }

        // create paginator object
        $paginator = new Paginator();
        $paginator->setPaginatorConfig($paginatorConfig);
        $paginator->setUrlTool(new UrlTool());
        $paginator->setRequestUri($request->getRequestUri());

        // get currentPage
        $paginator->setCurrentPage($request->query->get($paginatorConfig->getRequestQueryName("currentPage"), 1));

        // calculate total object count
        $countQueryBuilder = clone($queryBuilder);
        $countQueryBuilder->select("count(DISTINCT ".$paginatorConfig->getCountFieldName().")");
        $countQueryBuilder->setMaxResults(null);
        $countQueryBuilder->setFirstResult(null);
        $countQueryBuilder->resetDQLPart('groupBy');
        $countQueryBuilder->resetDQLPart('orderBy');

        // event to change paginator query builder
        $event = new DataGridEvent();
        $event->set("paginator", $paginator);
        $event->set("paginatorQueryBuilder", $countQueryBuilder);
        $event->set("request", $request);
        $this->dispatcher->dispatch(KitpagesDataGridEvents::ON_GET_PAGINATOR_QUERY, $event);

        if (!$event->isDefaultPrevented()) {
            $query = $countQueryBuilder->getQuery();
            $event->set("query", $query);
        }
        $this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_GET_PAGINATOR_QUERY, $event);

        // hack : recover query from the event so the developper can build a new query
        // from the paginatorQueryBuilder in the listener and reinject it in the event.
        $query = $event->get("query");

        try {
            $totalCount = $query->getSingleScalarResult();
            $paginator->setTotalItemCount($totalCount);
        } catch (\Doctrine\ORM\NoResultException $e) {
            $paginator->setTotalItemCount(0);
        }

        // calculate total page count
        if ($paginator->getTotalItemCount() == 0) {
            $paginator->setTotalPageCount(0);
        } else {
            $paginator->setTotalPageCount(
                (int) ((($paginator->getTotalItemCount() - 1) / $paginatorConfig->getItemCountInPage()) + 1)
            );
        }

        // change current page if needed
        if ($paginator->getCurrentPage() > $paginator->getTotalPageCount()) {
            $paginator->setCurrentPage(1);
        }

        // calculate nbPageLeft and nbPageRight
        $nbPageLeft = (int) ($paginatorConfig->getVisiblePageCountInPaginator() / 2);
        $nbPageRight = $paginatorConfig->getVisiblePageCountInPaginator() - 1 - $nbPageLeft ;

        // calculate lastPage to display
        $maxPage = min($paginator->getTotalPageCount(), $paginator->getCurrentPage() + $nbPageRight);
        // adapt minPage and maxPage
        $minPage = max(1, $maxPage-($paginatorConfig->getVisiblePageCountInPaginator() - 1));
        $maxPage = min($paginator->getTotalPageCount(), $minPage + ($paginatorConfig->getVisiblePageCountInPaginator() - 1));

        $paginator->setMinPage($minPage);
        $paginator->setMaxPage($maxPage);

        // calculate previousButton
        if ($paginator->getCurrentPage() == 1) {
            $paginator->setPreviousButtonPage(null);
        } else {
            $paginator->setPreviousButtonPage( $paginator->getCurrentPage() - 1 );
        }
        // calculate nextButton
        if ($paginator->getCurrentPage() == $paginator->getTotalPageCount()) {
            $paginator->setNextButtonPage(null);
        } else {
            $paginator->setNextButtonPage( $paginator->getCurrentPage() + 1);
        }

        return $paginator;
    }
1054969
public function setPaginator(PaginatorInterface $paginator) {
		$this->_paginator = $paginator;
		$this->_pageParam = $paginator->getPageParam();
		
		return $this;
	}
918687
public function getRouter(RequestContext $requestContext)
    {
        if (!$this->router) {
            if (!$this->getConfigDataProvider()) {
                throw new \LogicException(
                    "Cannot use CacheableRouterProvider because 'routing.config' not configured."
                );
            }
            
            $routerFile = 'routes.yml';
            $routerPath = $this->getConfigDataProvider()->getMandatory('path');
            if (!is_dir($routerPath)) {
                $routerFile = basename($routerPath);
                $routerPath = dirname($routerPath);
            }
            
            $cacheDir                = strcasecmp($this->kernel['routing.config.cache_dir'], "false") == 0 ? null :
                ($this->kernel['routing.config.cache_dir'] ? : $routerPath . "/cache");
            $hash                    = md5(
                realpath($cacheDir) . "/" . realpath($routerPath) . "/" . $routerFile
            );
            $matcherCacheClassname   = "ProjectUrlMatcher_$hash";
            $generatorCacheClassname = "ProjectUrlGenerator_$hash";
            $locator                 = new FileLocator([$routerPath]);
            $this->router            = new CacheableRouter(
                $this->kernel,
                //new YamlFileLoader($locator),
                new InheritableYamlFileLoader($locator),
                $routerFile,
                [
                    'cache_dir'             => $cacheDir,
                    'matcher_cache_class'   => $matcherCacheClassname,
                    'generator_cache_class' => $generatorCacheClassname,
                    'matcher_base_class'    => RedirectableUrlMatcher::class,
                    "debug"                 => $this->kernel['debug'],
                ],
                $requestContext
            );
        }
        
        return $this->router;
    }
624031
public function paginate(
        \Twig_Environment $twig,
        PaginatorInterface $paginator,
        string $template = '@Core/pagination/default.html.twig'
    ) {
        return $twig->render($template, array(
            'available_pages' => $paginator->getAvailablePages(),
            'current_page' => $paginator->getCurrentPage(),
            'next_url' => $this->getNextUrl($paginator),
            'previous_url' => $this->getPreviousUrl($paginator),
            'route' => $this->getRoute(),
            'params' => $this->getMergedParams(),
        ));
    }
1076907
public function paginator()
    {
        $paginator = $this->paginate();

        if (!is_null($this->presenter)) {
            return (new $this->presenter($paginator))->render();
        }

        return $paginator->render();
    }
812748
public function get(Pagination $pagination = null, Filters $filters = null, $qParam = '')
    {
        return $this->getByPath($this->generateListPath($pagination, $filters, ['q' => $qParam]));
    }
547651
private static function getRequest($request, array $config = null)
    {
        if (is_string($request)) {
            return new Request(
                $request,
                isset($config['class']) ? $config['class'] : null,
                isset($config['config']) ? $config['config'] : []
            );
        }

        if (!($request instanceof Request)) {
            throw new \InvalidArgumentException("Embed::create only accepts instances of Embed\\Request or strings");
        }

        return $request;
    }
480335
public function toResponse($request)
    {
        return (
            $this->resource instanceof AbstractPaginator
                ? new PaginatedResourceResponse($this)
                : new ResourceResponse($this)
        )->toResponse($request);
    }
317290
public function getScalarPaginator(\Doctrine\ORM\QueryBuilder $queryBuilder)
    {
        $request = $this->container->get('request_stack')->getCurrentRequest();
        
        $pagerfanta = new Paginator(new ArrayAdapter($queryBuilder->getQuery()->getScalarResult()));
        $pagerfanta->setDefaultFormat($this->getFormatPaginator());
        $pagerfanta->setContainer($this->container);
        if($request){
            $pagerfanta->setRequest($request);
        }
        return $pagerfanta;
    }
118300
public function paginate($listRows = null, $simple = false, $config = [])
    {
        if (is_int($simple)) {
            $total  = $simple;
            $simple = false;
        }

        $paginate = Db::getConfig('paginate');

        if (is_array($listRows)) {
            $config   = array_merge($paginate, $listRows);
            $listRows = $config['list_rows'];
        } else {
            $config   = array_merge($paginate, $config);
            $listRows = $listRows ?: $config['list_rows'];
        }

        /** @var Paginator $class */
        $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']);
        $page  = isset($config['page']) ? (int) $config['page'] : call_user_func([
            $class,
            'getCurrentPage',
        ], $config['var_page']);

        $page = $page < 1 ? 1 : $page;

        $config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']);

        if (!isset($total) && !$simple) {
            $options = $this->getOptions();

            unset($this->options['order'], $this->options['limit'], $this->options['page'], $this->options['field']);

            $bind    = $this->bind;
            $total   = $this->count();
            $results = $this->options($options)->bind($bind)->page($page, $listRows)->select();
        } elseif ($simple) {
            $results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select();
            $total   = null;
        } else {
            $results = $this->page($page, $listRows)->select();
        }

        $this->removeOption('limit');
        $this->removeOption('page');

        return $class::make($results, $listRows, $page, $total, $simple, $config);
    }
833875
public function getPaginationControl(PaginatorInterface $paginator) {
		$currentPage = $paginator->getCurrentPage();
		$pagesNumber = $paginator->getPagesNumber();
		
		if ($currentPage > $pagesNumber) {
			$currentPage = $pagesNumber;
		}
		
		if ($pagesNumber > $this->_rangeSize) {
			$rangeMiddle = (int) ceil($this->_rangeSize / 2);
			
			if ($currentPage - $rangeMiddle > $pagesNumber - $this->_rangeSize) {
				$lower = $pagesNumber - $this->_rangeSize + 1;
				$upper = $pagesNumber;
			} else {
				if ($currentPage - $rangeMiddle < 0) {
					$rangeMiddle = $currentPage;
				}

				$offset = $currentPage - $rangeMiddle;
				$lower  = $offset + 1;
				$upper  = $offset + $this->_rangeSize;
			}
		} else {
			$lower = 1;
			$upper = $pagesNumber;
		}
		
		$range = [];
		
		for ($i = $lower; $i <= $upper; ++ $i) {
			$range[] = $i;
		}
		
		$data = [
			PaginatorInterface::CONTROL_CURRENT => $currentPage,
			PaginatorInterface::CONTROL_RANGE   => $range
		];
		
		if ($currentPage > 2) {
			$data[PaginatorInterface::CONTROL_FIRST] = 1;
		}
		
		if ($pagesNumber > $currentPage + 1) {
			$data[PaginatorInterface::CONTROL_LAST] = $pagesNumber;
		}
		
		if ($currentPage > 1) {
			$data[PaginatorInterface::CONTROL_PREVIOUS] = $currentPage - 1;
		}
		
		if ($currentPage < $pagesNumber) {
			$data[PaginatorInterface::CONTROL_NEXT] = $currentPage + 1;
		}
		
		return $data;
	}
404643
public function getPublicPage( $config = [] ) {

		$modelTable	= $this->getModelTable();

		$config[ 'route' ] = isset( $config[ 'route' ] ) ? $config[ 'route' ] : 'blog';

		$config[ 'conditions' ][ "$modelTable.type" ] = static::$parentType;

		return parent::getPublicPage( $config );
	}
369255
public function paginator(Paginator $paginator, PresentableInterface $presenter)
    {
        $items = [];

        foreach ($paginator->getItems() as $item) {
            $items[] = $this->model($item, $presenter);
        }

        $paginator->setItems($items);

        return $paginator;
    }
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);
    }
396190
public function findMessageAndPaginate(Request $request)
    {
        return $this->getModel()
                    ->datefrom($request->get('from'))
                    ->dateto($request->get('to'))
                    ->leido($request->get('leido'))
                    ->orderBy('created_at', 'desc')
                    ->paginate();
    }
1181438
public function getController($router, $request)
    {
        $xml = new \DOMDocument;
        $routes = Config::getInstance()->get('routes');
        
        foreach ($routes as $route) {
            $router->addRoute($route);
            unset($route);
        }

        try {
            $matchedRoute = $router->getRoute($request->getUri()->getPath());
        } catch (\RuntimeException $e) {
            if ($e->getCode() == \phpGone\Router\Routeur::NO_ROUTE) {
                return null; //Permet de passer au middleware suivant
            }
        }

        $_GET = array_merge($_GET, $matchedRoute->getMatches());

        $controllerClass = $matchedRoute->getController();
                            
        return new $controllerClass($matchedRoute, $request);
    }
769156
public function getPaginatorHtml(Pagination $pagination, $routeName = null, $routeParameters = array())
    {
        return $this->templating->render(
            'TadckaPaginatorBundle::pagination.html.twig',
            array(
                'pagination' => $pagination,
                'route_name' => $routeName,
                'route_parameters' => $routeParameters,
                'pagination_class' => $this->paginationClass,
                'pagination_links_class' => $this->paginationLinksClass,
                'pagination_link_class' => $this->paginationLinkClass,
                'max_near_pages' => $this->maxNearPages,
            )
        );
    }