vendor/avenue/avenue-admin/src/Authentication/Storage/Session.php line 63

Open in your IDE?
  1. <?php
  2. namespace AvenueAdminBundle\Authentication\Storage;
  3. use AvenueAdminBundle\Document\AbstractDocument;
  4. use Doctrine\ODM\MongoDB\DocumentManager;
  5. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  6. class Session
  7. {
  8.     /**
  9.      * Default session object member name
  10.      */
  11.     const MEMBER_DEFAULT 'AvenueAdminSession';
  12.     /**
  13.      * @var SessionInterface
  14.      */
  15.     private $session;
  16.     /**
  17.      * Session object member
  18.      *
  19.      */
  20.     private $member self::MEMBER_DEFAULT;
  21.     /** @var DocumentManager */
  22.     private $documentManager;
  23.     private $identityClass;
  24.     /**
  25.      * Sets session storage options and initializes session namespace object
  26.      *
  27.      * @param SessionInterface $session
  28.      * @param string $member
  29.      */
  30.     public function __construct(SessionInterface $sessionDocumentManager $documentManager$identityClass$member null)
  31.     {
  32.         $this->session $session;
  33.         $this->documentManager $documentManager;
  34.         $this->identityClass $identityClass;
  35.         if ($member) {
  36.             $this->member $member;
  37.         }
  38.     }
  39.     /**
  40.      * Defined by Zend\Authentication\Storage\StorageInterface
  41.      *
  42.      * @return bool
  43.      */
  44.     public function isEmpty()
  45.     {
  46.         return !$this->read();
  47.     }
  48.     public function read(): ?AbstractDocument
  49.     {
  50.         if (!$this->identityClass) {
  51.             throw new \Exception('parameter admin_identity_class is empty');
  52.         }
  53.         $id $this->session->get($this->member);
  54.         if ($id) {
  55.             return $this->documentManager->getRepository($this->identityClass)->find($id);
  56.         }
  57.         return null;
  58.     }
  59.     public function write(AbstractDocument $obj)
  60.     {
  61.         $this->session->set($this->member$obj->getId());
  62.     }
  63.     /**
  64.      * Defined by Zend\Authentication\Storage\StorageInterface
  65.      *
  66.      * @return void
  67.      */
  68.     public function clear()
  69.     {
  70.         $this->session->remove($this->member);
  71.     }
  72. }