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: Replaced TokenStorage with TokenStorageInterface --- src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php | 10 ++++++++-- .../CoreBundle/Helper/PreparePagerForEntries.php | 16 +++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index 3c597b5d..f7fbd2ec 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 f9066bee..7d3798b9 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; } -- cgit v1.2.3 From 94766a89627df74449b9e34d31a06db386a1b07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 7 Nov 2016 10:41:11 +0100 Subject: PHP CS --- src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index f7fbd2ec..a3e36fdd 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -12,7 +12,6 @@ use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType; 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 @@ -23,8 +22,8 @@ class EntryFilterType extends AbstractType /** * Repository & user are used to get a list of language entries for this user. * - * @param EntityRepository $entryRepository - * @param TokenStorage $token + * @param EntityRepository $entryRepository + * @param TokenStorageInterface $tokenStorage */ public function __construct(EntityRepository $entryRepository, TokenStorageInterface $tokenStorage) { -- cgit v1.2.3