Symfony Twig Extension breaks other service - Is templating done before security?
don't interact with the tokenStorage in the constructor but only in the userHasPurchases
method.
namespace AppShopBundle\Service;use AppBundle\Entity\User;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;...class AppShopService { protected $tokenStorage; public function __construct(TokenStorageInterface $tokenStorage, ...) { $this->tokenStorage = $tokenStorage; } public function userHasPurchases(User $user) { $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; $result = $user... return result; }}
Hope this help