src/Entity/Application.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\ApplicationRepository;
  5. use App\Service\JwtServerService;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Ramsey\Uuid\Uuid;
  8. use Doctrine\ORM\Event\LifecycleEventArgs;
  9. /**
  10.  *
  11.  * @ApiResource()
  12.  * @ORM\Entity(repositoryClass=ApplicationRepository::class)
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class Application
  16. {
  17.     /**
  18.      *
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      *
  26.      * @ORM\Column(type="guid")
  27.      */
  28.     private $guid;
  29.     /**
  30.      *
  31.      * @ORM\Column(type="string", length=255)
  32.      */
  33.     private $name;
  34.     /**
  35.      *
  36.      */
  37.     private $key;
  38.     /**
  39.      * Application constructor.
  40.      * @param string|null $name
  41.      * @param string|null $guid
  42.      */
  43.     public function __construct(string $name NULLstring $guid NULL)
  44.     {
  45.         $this->id NULL;
  46.         $this->name $name;
  47.         if (NULL === $guid) {
  48.             $guid Uuid::uuid4()->toString();
  49.         }
  50.         $this->guid $guid;
  51.     }
  52.     /**
  53.      *
  54.      */
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     /**
  60.      *
  61.      */
  62.     public function getGuid(): ?string
  63.     {
  64.         return $this->guid;
  65.     }
  66.     /**
  67.      * @param string $guid
  68.      * @return $this
  69.      */
  70.     public function setGuid(string $guid): self
  71.     {
  72.         $this->guid $guid;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return string|null
  77.      */
  78.     public function getName(): ?string
  79.     {
  80.         return $this->name;
  81.     }
  82.     /**
  83.      *
  84.      */
  85.     public function setName(string $name): self
  86.     {
  87.         $this->name $name;
  88.         return $this;
  89.     }
  90.     /**
  91.      *
  92.      */
  93.     public function getKey(): ?string
  94.     {
  95.         return $this->key;
  96.     }
  97.     /**
  98.      * @ORM\PostLoad
  99.      */
  100.     public function postLoadSetKey(LifecycleEventArgs $event) {
  101.         $entityManager $event->getEntityManager();
  102.         $repository $entityManager->getRepository(get_class($this));
  103.         $iss $repository->service()->iss();
  104.         $guid UUID::fromString($this->guid)->getBytes();
  105.         $salt $iss $guid;
  106.         $hash $repository->service()->hash($salt);
  107.         $this->key .= base64_encode($guid $hash);
  108.     }
  109. }