]> git.immae.eu Git - github/wallabag/wallabag.git/blame_incremental - src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
Merge pull request #3172 from wallabag/more-scruti
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / PreparePagerForEntries.php
... / ...
CommitLineData
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Pagerfanta\Adapter\AdapterInterface;
6use Pagerfanta\Pagerfanta;
7use Symfony\Component\Routing\Router;
8use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
9
10class PreparePagerForEntries
11{
12 private $router;
13 private $tokenStorage;
14
15 public function __construct(TokenStorageInterface $tokenStorage, Router $router)
16 {
17 $this->tokenStorage = $tokenStorage;
18 $this->router = $router;
19 }
20
21 /**
22 * @param AdapterInterface $adapter
23 *
24 * @return null|Pagerfanta
25 */
26 public function prepare(AdapterInterface $adapter)
27 {
28 $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
29
30 if (null === $user || !is_object($user)) {
31 return;
32 }
33
34 $entries = new Pagerfanta($adapter);
35 $entries->setMaxPerPage($user->getConfig()->getItemsPerPage());
36
37 return $entries;
38 }
39}