From 2fe2e411a74d541ddd7eee2aca1b80ac58de49eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 7 Nov 2016 10:34:49 +0100 Subject: [PATCH] Replaced TokenStorage with TokenStorageInterface --- .../CoreBundle/Form/Type/EntryFilterType.php | 10 ++++++++-- .../CoreBundle/Helper/PreparePagerForEntries.php | 16 +++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index 3c597b5db..f7fbd2ecf 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -13,6 +13,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; class EntryFilterType extends AbstractType { @@ -25,10 +26,15 @@ class EntryFilterType extends AbstractType * @param EntityRepository $entryRepository * @param TokenStorage $token */ - public function __construct(EntityRepository $entryRepository, TokenStorage $token) + public function __construct(EntityRepository $entryRepository, TokenStorageInterface $tokenStorage) { $this->repository = $entryRepository; - $this->user = $token->getToken()->getUser(); + + $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null; + + if (null === $this->user || !is_object($this->user)) { + return null; + } } public function buildForm(FormBuilderInterface $builder, array $options) diff --git a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php index f9066bee7..7d3798b95 100644 --- a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php +++ b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php @@ -5,16 +5,16 @@ namespace Wallabag\CoreBundle\Helper; use Pagerfanta\Adapter\AdapterInterface; use Pagerfanta\Pagerfanta; use Symfony\Component\Routing\Router; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; class PreparePagerForEntries { - private $user; private $router; + private $tokenStorage; - public function __construct(TokenStorage $token, Router $router) + public function __construct(TokenStorageInterface $tokenStorage, Router $router) { - $this->user = $token->getToken()->getUser(); + $this->tokenStorage = $tokenStorage; $this->router = $router; } @@ -26,8 +26,14 @@ class PreparePagerForEntries */ public function prepare(AdapterInterface $adapter, $page = 1) { + $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; + + if (null === $user || !is_object($user)) { + return null; + } + $entries = new Pagerfanta($adapter); - $entries->setMaxPerPage($this->user->getConfig()->getItemsPerPage()); + $entries->setMaxPerPage($user->getConfig()->getItemsPerPage()); return $entries; }