src/Entity/Certificate.php line 22

  1. <?php
  2. /*
  3.  *  @author Guerby Duval <info@tranzaksyon.com>
  4.  *  @link https://tranzaksyon.com
  5.  *  @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.
  6.  */
  7. namespace App\Entity;
  8. use App\Repository\CertificateRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\DBAL\Types\Types;
  12. use Doctrine\ORM\Event\LifecycleEventArgs;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\Validator\Constraints\File;
  15. use Symfony\Component\Validator\Constraints\NotBlank;
  16. use Symfony\Component\Validator\Constraints\NotNull;
  17. #[ORM\Entity(repositoryClassCertificateRepository::class)]
  18. #[ORM\HasLifecycleCallbacks]
  19. class Certificate
  20. {
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column]
  24.     private ?int $id null;
  25.     #[ORM\Column(length255)]
  26.     #[NotNull]
  27.     #[File(mimeTypes: ['application/x-pkcs12''application/octet-stream'], mimeTypesMessage'Tiene que ser un certificado .p12. No {{ type }}')]
  28.     private ?string $file null;
  29.     #[ORM\Column(length50)]
  30.     #[NotBlank]
  31.     private ?string $password null;
  32.     #[ORM\OneToMany(mappedBy'certificate'targetEntitySriInfo::class)]
  33.     private Collection $sriInfos;
  34.     #[ORM\Column(length255)]
  35.     private ?string $name null;
  36.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  37.     private ?\DateTimeInterface $expiredDate null;
  38.     public function __construct()
  39.     {
  40.         $this->sriInfos = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getFile(): ?string
  47.     {
  48.         return $this->file;
  49.     }
  50.     public function setFile(?string $file): self
  51.     {
  52.         $this->file $file;
  53.         return $this;
  54.     }
  55.     public function getPassword(): ?string
  56.     {
  57.         return $this->password;
  58.     }
  59.     public function setPassword(string $password): self
  60.     {
  61.         $this->password $password;
  62.         return $this;
  63.     }
  64.     /**
  65.      * @return Collection<int, SriInfo>
  66.      */
  67.     public function getSriInfos(): Collection
  68.     {
  69.         return $this->sriInfos;
  70.     }
  71.     public function addSriInfo(SriInfo $sriInfo): self
  72.     {
  73.         if (!$this->sriInfos->contains($sriInfo)) {
  74.             $this->sriInfos->add($sriInfo);
  75.             $sriInfo->setCertificate($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removeSriInfo(SriInfo $sriInfo): self
  80.     {
  81.         if ($this->sriInfos->removeElement($sriInfo)) {
  82.             // set the owning side to null (unless already changed)
  83.             if ($sriInfo->getCertificate() === $this) {
  84.                 $sriInfo->setCertificate(null);
  85.             }
  86.         }
  87.         return $this;
  88.     }
  89.     public function getName(): ?string
  90.     {
  91.         return $this->name;
  92.     }
  93.     public function setName(string $name): self
  94.     {
  95.         $this->name $name;
  96.         return $this;
  97.     }
  98.     #[ORM\PreRemove]
  99.     public function deleteCertificateFile(LifecycleEventArgs $eventArgs)
  100.     {
  101.         /** @var Certificate $cert */
  102.         $cert $eventArgs->getObject();
  103.         try {
  104.             if (!empty($cert->getFile()))
  105.                 unlink(__DIR__ '/../../storage/certificates/' $cert->getFile());
  106.         } catch (\Error|\Exception $ex) {
  107.         }
  108.     }
  109.     public function getExpiredDate(): ?\DateTimeInterface
  110.     {
  111.         return $this->expiredDate;
  112.     }
  113.     public function setExpiredDate(?\DateTimeInterface $expiredDate): self
  114.     {
  115.         $this->expiredDate $expiredDate;
  116.         return $this;
  117.     }
  118. }