src/Entity/Session.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SessionRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Exception;
  6. use Throwable;
  7. /**
  8.  * @ORM\Entity(repositoryClass=SessionRepository::class)
  9.  * @ORM\Table(name="sessions")
  10.  */
  11. class Session
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\Column(type="string")
  16.      */
  17.     private string $sess_id;
  18.     /**
  19.      * @ORM\Column(type="text", nullable=true)
  20.      */
  21.     private ?string $sess_data null;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private string $sess_lifetime;
  26.     /**
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     private int $sess_time;
  30.     /**
  31.      * @return string
  32.      */
  33.     public function getSessId(): string
  34.     {
  35.         return $this->sess_id;
  36.     }
  37.     /**
  38.      * @return array|null
  39.      * @throws Exception
  40.      */
  41.     public function getSessData(): ?array
  42.     {
  43.         $result null;
  44.         if (!empty($this->sess_data)) {
  45.             try {
  46.                 if (!session_id()) {
  47.                     session_start();
  48.                 }
  49.                 if (session_decode($this->sess_data)) {
  50.                     $result $_SESSION;
  51.                     session_destroy();
  52.                 }
  53.             } catch (Throwable $t) {
  54.             }
  55.         }
  56.         return $result;
  57.     }
  58.     /**
  59.      * @return string
  60.      */
  61.     public function getSessLifetime(): string
  62.     {
  63.         return $this->sess_lifetime;
  64.     }
  65.     /**
  66.      * @return int
  67.      */
  68.     public function getSessTime(): int
  69.     {
  70.         return $this->sess_time;
  71.     }
  72. }