src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\Collection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use App\Validator\Constraints as AcmeAssert;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use App\Entity\UserRole;
  10. use JMS\Serializer\Annotation\Exclude;
  11. /**
  12.  * @ORM\Entity
  13.  * @ORM\Table(name="users")
  14.  */
  15. class User implements UserInterface\Serializable{
  16.     /**
  17.      * @ORM\Column(name="id", type="integer", length=11, options={"unsigned"=true})
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(name="username", type="string", length=255, unique=true)
  24.      * @Assert\NotBlank(
  25.      *     message = "Enter a valid username."
  26.      * )
  27.      */
  28.     private $username;
  29.     /**
  30.      * @ORM\Column(name="email", type="string", length=255, unique=true)
  31.      * @Assert\Email(
  32.      *     message = "The email '{{ value }}' is not a valid email.",
  33.      * )
  34.      */
  35.     private $email;
  36.     /**
  37.      * @ORM\Column(name="password", type="string", length=255)
  38.      * @Exclude
  39.      * @Assert\NotBlank(
  40.      *     message = "Enter a valid password."
  41.      * )
  42.      */
  43.     private $password;
  44.     /**
  45.      * @ORM\Column(name="is_active", type="boolean")
  46.      */
  47.     private $is_active;
  48.     /**
  49.      * @ORM\Column(type="json")
  50.      * @Exclude
  51.      */
  52.     private $roles = [];
  53.     /**
  54.      * @ORM\OneToOne(targetEntity="App\Entity\Staff", mappedBy="user", cascade={"persist", "remove"})
  55.      */
  56.     private $staff;
  57.     public function getID() { return $this->id; }
  58.     public function getUsername() { return $this->username; }
  59.     public function setUsername($username) { $this->username $username; }
  60.     public function getEmail() { return $this->email; }
  61.     public function setEmail($email) { $this->email $email; }
  62.     public function getPassword() { return $this->password; }
  63.     public function setPassword($password) { $this->password $password; }
  64.     public function getIsActive(): ?bool { return $this->is_active; }
  65.     public function setIsActive(bool $is_active): self $this->is_active $is_active; return $this; }
  66.     public function serialize() {
  67.         return serialize([
  68.             $this->id,
  69.             $this->username,
  70.             $this->password,
  71.         ]);
  72.     }
  73.     public function unserialize($serialized) {
  74.         list (
  75.             $this->id,
  76.             $this->username,
  77.             $this->password
  78.         ) = unserialize($serialized);
  79.     }
  80.     public function getSalt() {}
  81.     public function eraseCredentials() {}
  82.     public function getStaff(): ?Staff { return $this->staff; }
  83.     public function setStaff(Staff $staff): self
  84.     {
  85.         $this->staff $staff;
  86.         // set the owning side of the relation if necessary
  87.         if ($this !== $staff->getUser()) {
  88.             $staff->setUser($this);
  89.         }
  90.         return $this;
  91.     }
  92.     /**
  93.     * @see UserInterface
  94.     */
  95.     public function getRoles(): array { $roles $this->roles$roles[] = 'ROLE_USER'; return array_unique($roles); }
  96.     public function setRoles(array $roles): self $this->roles $roles; return $this; }
  97. }