Replaced TokenStorage with TokenStorageInterface

This commit is contained in:
Nicolas Lœuillet 2016-11-07 10:34:49 +01:00
parent 24692715de
commit 2fe2e411a7
No known key found for this signature in database
GPG Key ID: BDC1EFB5CA0145F2
2 changed files with 19 additions and 7 deletions

View File

@ -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)

View File

@ -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;
}