src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  * @ORM\Table(name="`user`")
  13.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  14.  *  @UniqueEntity(fields={"username"}, message="There is already an account with this username")
  15.  */
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string", length=180, unique=true)
  26.      */
  27.     private $email;
  28.     /**
  29.      * @ORM\Column(type="json")
  30.      */
  31.     private $roles = [];
  32.     /**
  33.      * @var string The hashed password
  34.      * @ORM\Column(type="string")
  35.      */
  36.     private $password;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, unique=true)
  39.      */
  40.     private $username;
  41.     /**
  42.      * @ORM\OneToMany(targetEntity=DeployPackages::class, mappedBy="executedBy")
  43.      */
  44.     private $executedBy;
  45.     /**
  46.      * @ORM\OneToMany(targetEntity=DeployPackages::class, mappedBy="createdBy")
  47.      */
  48.     private $createdBy;
  49.     /**
  50.      * @ORM\Column(type="boolean", nullable=true)
  51.      */
  52.     private $deleted;
  53.     /**
  54.      * @ORM\Column(type="datetime", nullable=true)
  55.      */
  56.     private $deletedAt;
  57.     /**
  58.      * @ORM\Column(type="string", length=255, nullable=true)
  59.      */
  60.     private $name;
  61.     /**
  62.      * @ORM\Column(type="boolean", nullable=true)
  63.      */
  64.     private $locked;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity=DeployPackages::class, mappedBy="deletedBy")
  67.      */
  68.     private $deployPackages;
  69.     public function __construct()
  70.     {
  71.         $this->executedBy = new ArrayCollection();
  72.         $this->createdBy = new ArrayCollection();
  73.         $this->deployPackages = new ArrayCollection();
  74.     }
  75.     public function getId(): ?int
  76.     {
  77.         return $this->id;
  78.     }
  79.     public function getEmail(): ?string
  80.     {
  81.         return $this->email;
  82.     }
  83.     public function setEmail(string $email): self
  84.     {
  85.         $this->email $email;
  86.         return $this;
  87.     }
  88.   
  89.     /**
  90.      * A visual identifier that represents this user.
  91.      *
  92.      * @see UserInterface
  93.      */
  94.     public function getUsername(): string
  95.     {
  96.         return (string) $this->username;
  97.     }
  98.     public function setUsername(string $username): self
  99.     {
  100.         $this->username $username;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @see UserInterface
  105.      */
  106.     public function getRoles(): array
  107.     {
  108.         $roles $this->roles;
  109.         // guarantee every user at least has ROLE_USER
  110.         //$roles[] = 'ROLE_USER';
  111.         return array_unique($roles);
  112.     }
  113.     public function setRoles(string $roles): self
  114.     {
  115.         $this->roles[] = $roles;
  116.         return $this;
  117.     }
  118.     public function hasRole($role)
  119.     {
  120.         return in_array($role$this->getRoles(), true);
  121.     }
  122.     public function addRole($role)
  123.     {
  124.     
  125.         if (!in_array($role$this->rolestrue)) {
  126.             $this->roles[] = $role;
  127.         }
  128.     
  129.         return $this;
  130.     }
  131.     public function removeRole($role)
  132.     {
  133.         if (false !== $key array_search($role$this->rolestrue)) {
  134.             unset($this->roles[$key]);
  135.             $this->roles array_values($this->roles);
  136.         }
  137.     
  138.         return $this;
  139.     }
  140.     /**
  141.      * @see PasswordAuthenticatedUserInterface
  142.      */
  143.     public function getPassword(): string
  144.     {
  145.         return $this->password;
  146.     }
  147.     public function setPassword(string $password): self
  148.     {
  149.         $this->password $password;
  150.         return $this;
  151.     }
  152.     /**
  153.      * Returning a salt is only needed, if you are not using a modern
  154.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  155.      *
  156.      * @see UserInterface
  157.      */
  158.     public function getSalt(): ?string
  159.     {
  160.         return null;
  161.     }
  162.     /**
  163.      * @see UserInterface
  164.      */
  165.     public function eraseCredentials()
  166.     {
  167.         // If you store any temporary, sensitive data on the user, clear it here
  168.         // $this->plainPassword = null;
  169.     }
  170.     /**
  171.      * @return Collection<int, DeployPackages>
  172.      */
  173.     public function getExecutedBy(): Collection
  174.     {
  175.         return $this->executedBy;
  176.     }
  177.     public function addExecutedBy(DeployPackages $executedBy): self
  178.     {
  179.         if (!$this->executedBy->contains($executedBy)) {
  180.             $this->executedBy[] = $executedBy;
  181.             $executedBy->setExecutedBy($this);
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeExecutedBy(DeployPackages $executedBy): self
  186.     {
  187.         if ($this->executedBy->removeElement($executedBy)) {
  188.             // set the owning side to null (unless already changed)
  189.             if ($executedBy->getExecutedBy() === $this) {
  190.                 $executedBy->setExecutedBy(null);
  191.             }
  192.         }
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return Collection<int, DeployPackages>
  197.      */
  198.     public function getCreatedBy(): Collection
  199.     {
  200.         return $this->createdBy;
  201.     }
  202.     public function addCreatedBy(DeployPackages $createdBy): self
  203.     {
  204.         if (!$this->createdBy->contains($createdBy)) {
  205.             $this->createdBy[] = $createdBy;
  206.             $createdBy->setCreatedBy($this);
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeCreatedBy(DeployPackages $createdBy): self
  211.     {
  212.         if ($this->createdBy->removeElement($createdBy)) {
  213.             // set the owning side to null (unless already changed)
  214.             if ($createdBy->getCreatedBy() === $this) {
  215.                 $createdBy->setCreatedBy(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220.     public function isDeleted(): ?bool
  221.     {
  222.         return $this->deleted;
  223.     }
  224.     public function setDeleted(?bool $deleted): self
  225.     {
  226.         $this->deleted $deleted;
  227.         return $this;
  228.     }
  229.     public function getDeletedAt(): ?\DateTimeInterface
  230.     {
  231.         return $this->deletedAt;
  232.     }
  233.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  234.     {
  235.         $this->deletedAt $deletedAt;
  236.         return $this;
  237.     }
  238.     public function getName(): ?string
  239.     {
  240.         return $this->name;
  241.     }
  242.     public function setName(?string $name): self
  243.     {
  244.         $this->name $name;
  245.         return $this;
  246.     }
  247.     public function isLocked(): ?bool
  248.     {
  249.         return $this->locked;
  250.     }
  251.     public function setLocked(?bool $locked): self
  252.     {
  253.         $this->locked $locked;
  254.         return $this;
  255.     }
  256.     /**
  257.      * @return Collection<int, DeployPackages>
  258.      */
  259.     public function getDeployPackages(): Collection
  260.     {
  261.         return $this->deployPackages;
  262.     }
  263.     public function addDeployPackage(DeployPackages $deployPackage): self
  264.     {
  265.         if (!$this->deployPackages->contains($deployPackage)) {
  266.             $this->deployPackages[] = $deployPackage;
  267.             $deployPackage->setDeletedBy($this);
  268.         }
  269.         return $this;
  270.     }
  271.     public function removeDeployPackage(DeployPackages $deployPackage): self
  272.     {
  273.         if ($this->deployPackages->removeElement($deployPackage)) {
  274.             // set the owning side to null (unless already changed)
  275.             if ($deployPackage->getDeletedBy() === $this) {
  276.                 $deployPackage->setDeletedBy(null);
  277.             }
  278.         }
  279.         return $this;
  280.     }
  281.  
  282.  
  283.    
  284. }