vendor/kunstmaan/admin-bundle/Helper/UserProcessor.php line 12

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\AdminBundle\Helper;
  3. use Symfony\Component\DependencyInjection\ContainerInterface;
  4. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. /**
  7.  * Adds the user information to the context of the record which will be logged
  8.  */
  9. class UserProcessor
  10. {
  11.     /**
  12.      * Use container else we have a continous loop in our dependency
  13.      *
  14.      * @var ContainerInterface
  15.      */
  16.     private $container;
  17.     /**
  18.      * @var UserInterface
  19.      */
  20.     private $user;
  21.     /**
  22.      * @var array
  23.      */
  24.     private $record = array();
  25.     private $tokenStorage;
  26.     /**
  27.      * @param ContainerInterface|TokenStorageInterface $tokenStorage
  28.      */
  29.     public function __construct(/*TokenStorageInterface */ $tokenStorage)
  30.     {
  31.         if ($tokenStorage instanceof ContainerInterface) {
  32.             @trigger_error(sprintf('Passing the container as the first argument of "%s" is deprecated in KunstmaanAdminBundle 5.4 and will be removed in KunstmaanAdminBundle 6.0. Inject the "security.token_storage" service instead.'__CLASS__), E_USER_DEPRECATED);
  33.             $this->container $tokenStorage;
  34.             $this->tokenStorage $this->container->get('security.token_storage');
  35.             return;
  36.         }
  37.         $this->tokenStorage $tokenStorage;
  38.     }
  39.     /**
  40.      * @param array $record
  41.      *
  42.      * @return array
  43.      */
  44.     public function processRecord(array $record)
  45.     {
  46.         if (\is_null($this->user)) {
  47.             if (($this->tokenStorage !== null) && ($this->tokenStorage->getToken() !== null) && ($this->tokenStorage->getToken()->getUser() instanceof \Symfony\Component\Security\Core\User\AdvancedUserInterface)) {
  48.                 $this->user $this->tokenStorage->getToken()->getUser();
  49.                 $this->record['extra']['user']['username'] = $this->user->getUsername();
  50.                 $this->record['extra']['user']['roles'] = $this->user->getRoles();
  51.                 $this->record['extra']['user']['is_account_non_expired'] = $this->user->isAccountNonExpired();
  52.                 $this->record['extra']['user']['is_account_non_locked'] = $this->user->isAccountNonLocked();
  53.                 $this->record['extra']['user']['is_credentials_non_expired'] = $this->user->isCredentialsNonExpired();
  54.                 $this->record['extra']['user']['is_enabled'] = $this->user->isEnabled();
  55.             }
  56.         }
  57.         return array_merge($record$this->record);
  58.     }
  59. }