Skip to content

Commit

Permalink
Merge pull request doctrine-extensions#1626 from stefano-93/patch-1
Browse files Browse the repository at this point in the history
Support for Symfony 2.6 and above
  • Loading branch information
l3pp4rd authored Jul 8, 2016
2 parents e7f3a2c + e449512 commit aabed7f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions doc/symfony2.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ namespace Acme\DemoBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Kernel;
class DoctrineExtensionListener implements ContainerAwareInterface
{
Expand Down Expand Up @@ -266,10 +267,22 @@ class DoctrineExtensionListener implements ContainerAwareInterface
public function onKernelRequest(GetResponseEvent $event)
{
$securityContext = $this->container->get('security.context', ContainerInterface::NULL_ON_INVALID_REFERENCE);
if (null !== $securityContext && null !== $securityContext->getToken() && $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$loggable = $this->container->get('gedmo.listener.loggable');
$loggable->setUsername($securityContext->getToken()->getUsername());
if (Kernel::MAJOR_VERSION == 2 && Kernel::MINOR_VERSION < 6) {
$securityContext = $this->container->get('security.context', ContainerInterface::NULL_ON_INVALID_REFERENCE);
if (null !== $securityContext && null !== $securityContext->getToken() && $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$loggable = $this->container->get('gedmo.listener.loggable');
$loggable->setUsername($securityContext->getToken()->getUsername());
}
}
else {
$tokenStorage = $this->container->get('security.token_storage')->getToken();
$authorizationChecker = $this->container->get('security.authorization_checker');
if (null !== $tokenStorage && $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$loggable = $this->container->get('gedmo.listener.loggable');
$loggable->setUsername($tokenStorage->getUser());
$blameable = $this->container->get('gedmo.listener.blameable');
$blameable->setUserValue($tokenStorage->getUser());
}
}
}
}
Expand Down

0 comments on commit aabed7f

Please sign in to comment.