Skip to content

Instantly share code, notes, and snippets.

@alpha1125
Created December 24, 2017 17:39
Show Gist options
  • Save alpha1125/b333314d7eb6496c057585f7788d80d6 to your computer and use it in GitHub Desktop.
Save alpha1125/b333314d7eb6496c057585f7788d80d6 to your computer and use it in GitHub Desktop.
Cannot get the User, from TokenStorage
<?php
namespace ContestEngineBundle\Service\EventSubscriber;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class SquareCropApprovalRequiredSubscriber implements EventSubscriber
{
private $token_storage;
private $user;
private $reader;
public function getSubscribedEvents()
{
return array(
'postLoad',
);
}
public function __construct(TokenStorageInterface $token_storage, Reader $reader)
{
$this->token_storage = $token_storage;
$this->reader = $reader;
}
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getObject();
// Issue,
// $this->token_storage->getToken == null.
$user = $this->token_storage->getToken()->getUser();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment