<?phpnamespace App\Entity;use ApiPlatform\Core\Annotation\ApiResource;use App\Repository\ApplicationRepository;use App\Service\JwtServerService;use Doctrine\ORM\Mapping as ORM;use Ramsey\Uuid\Uuid;use Doctrine\ORM\Event\LifecycleEventArgs;/** * * @ApiResource() * @ORM\Entity(repositoryClass=ApplicationRepository::class) * @ORM\HasLifecycleCallbacks() */class Application{ /** * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * * @ORM\Column(type="guid") */ private $guid; /** * * @ORM\Column(type="string", length=255) */ private $name; /** * */ private $key; /** * Application constructor. * @param string|null $name * @param string|null $guid */ public function __construct(string $name = NULL, string $guid = NULL) { $this->id = NULL; $this->name = $name; if (NULL === $guid) { $guid = Uuid::uuid4()->toString(); } $this->guid = $guid; } /** * */ public function getId(): ?int { return $this->id; } /** * */ public function getGuid(): ?string { return $this->guid; } /** * @param string $guid * @return $this */ public function setGuid(string $guid): self { $this->guid = $guid; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * */ public function setName(string $name): self { $this->name = $name; return $this; } /** * */ public function getKey(): ?string { return $this->key; } /** * @ORM\PostLoad */ public function postLoadSetKey(LifecycleEventArgs $event) { $entityManager = $event->getEntityManager(); $repository = $entityManager->getRepository(get_class($this)); $iss = $repository->service()->iss(); $guid = UUID::fromString($this->guid)->getBytes(); $salt = $iss . $guid; $hash = $repository->service()->hash($salt); $this->key .= base64_encode($guid . $hash); }}