Created
December 24, 2017 17:39
-
-
Save alpha1125/b333314d7eb6496c057585f7788d80d6 to your computer and use it in GitHub Desktop.
Cannot get the User, from TokenStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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