Skip to content

Commit 372ddc1

Browse files
authored
Merge pull request #1765 from nnmer/v2.4.x-fix-doc-for-blameable
fix missing blameable service definition and it’s usage in DoctrineEx…
2 parents e6aef11 + 62ec638 commit 372ddc1

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

doc/symfony2.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ services:
218218
- { name: doctrine.event_subscriber, connection: default }
219219
calls:
220220
- [ setAnnotationReader, [ "@annotation_reader" ] ]
221+
222+
gedmo.listener.blameable:
223+
class: Gedmo\Blameable\BlameableListener
224+
tags:
225+
- { name: doctrine.event_subscriber, connection: default }
226+
calls:
227+
- [ setAnnotationReader, [ "@annotation_reader" ] ]
228+
221229
```
222230
223231
So what does it include in general? Well, it creates services for all extension listeners.
@@ -239,6 +247,7 @@ namespace Acme\DemoBundle\Listener;
239247
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
240248
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
241249
use Symfony\Component\DependencyInjection\ContainerInterface;
250+
use Symfony\Component\HttpKernel\Kernel;
242251
243252
class DoctrineExtensionListener implements ContainerAwareInterface
244253
{
@@ -266,10 +275,30 @@ class DoctrineExtensionListener implements ContainerAwareInterface
266275
267276
public function onKernelRequest(GetResponseEvent $event)
268277
{
269-
$securityContext = $this->container->get('security.context', ContainerInterface::NULL_ON_INVALID_REFERENCE);
270-
if (null !== $securityContext && null !== $securityContext->getToken() && $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
271-
$loggable = $this->container->get('gedmo.listener.loggable');
272-
$loggable->setUsername($securityContext->getToken()->getUsername());
278+
if (Kernel::MAJOR_VERSION == 2 && Kernel::MINOR_VERSION < 6) {
279+
$securityContext = $this->container->get('security.context', ContainerInterface::NULL_ON_INVALID_REFERENCE);
280+
if (null !== $securityContext && null !== $securityContext->getToken() && $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
281+
# for loggable behavior
282+
$loggable = $this->container->get('gedmo.listener.loggable');
283+
$loggable->setUsername($securityContext->getToken()->getUsername());
284+
285+
# for blameable behavior
286+
$blameable = $this->container->get('gedmo.listener.blameable');
287+
$blameable->setUserValue($securityContext->getToken()->getUser());
288+
}
289+
}
290+
else {
291+
$tokenStorage = $this->container->get('security.token_storage')->getToken();
292+
$authorizationChecker = $this->container->get('security.authorization_checker');
293+
if (null !== $tokenStorage && $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
294+
# for loggable behavior
295+
$loggable = $this->container->get('gedmo.listener.loggable');
296+
$loggable->setUsername($tokenStorage->getUser());
297+
298+
# for blameable behavior
299+
$blameable = $this->container->get('gedmo.listener.blameable');
300+
$blameable->setUserValue($tokenStorage->getUser());
301+
}
273302
}
274303
}
275304
}

0 commit comments

Comments
 (0)