src/Entity/AdminUser.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Security\RoleInterface;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\App\AdminUserRepository")
  10.  * @UniqueEntity(fields={"login"}, message="admin_user.form.already_exist")
  11.  */
  12. class AdminUser implements UserInterface
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     protected $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=12)
  22.      * @Assert\Length(min=4, max=12)
  23.      */
  24.     protected $login;
  25.     /**
  26.      * @var string
  27.      */
  28.     protected $plainPassword;
  29.     /**
  30.      * @ORM\Column(type="string")
  31.      */
  32.     protected $password;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      */
  36.     protected $name;
  37.     /**
  38.      * @ORM\Column(type="string", length=255)
  39.      */
  40.     protected $firstName;
  41.     /**
  42.      * @ORM\Column(type="string", length=255)
  43.      * @Assert\Email
  44.      */
  45.     protected $email;
  46.     protected $rolesAllowed = [RoleInterface::ROLE_ADMINRoleInterface::ROLE_ADVISORRoleInterface::ROLE_COMMERCIAL];
  47.     /**
  48.      * @ORM\Column(type="string", length=16)
  49.      */
  50.     protected $profile;
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getLogin(): ?string
  56.     {
  57.         return $this->login;
  58.     }
  59.     /**
  60.      * @return AdminUser
  61.      */
  62.     public function setLogin(string $login): self
  63.     {
  64.         $this->login $login;
  65.         return $this;
  66.     }
  67.     /**
  68.      * @return string
  69.      */
  70.     public function getPlainPassword(): ?string
  71.     {
  72.         return $this->plainPassword;
  73.     }
  74.     public function setPlainPassword(string $plainPassword): self
  75.     {
  76.         $this->plainPassword $plainPassword;
  77.         $this->password null;
  78.         return $this;
  79.     }
  80.     public function getPassword(): ?string
  81.     {
  82.         return $this->password;
  83.     }
  84.     /**
  85.      * @return AdminUser
  86.      */
  87.     public function setPassword(string $password): self
  88.     {
  89.         $this->password $password;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @param $role
  94.      *
  95.      * @return AdminUser
  96.      */
  97.     public function setProfile($role): self
  98.     {
  99.         if (!in_array($role$this->rolesAllowed)) {
  100.             throw new \InvalidArgumentException(sprintf('Invalid value for profile : %s.'$role));
  101.         }
  102.         $this->profile $role;
  103.         return $this;
  104.     }
  105.     public function getProfile(): ?string
  106.     {
  107.         return $this->profile;
  108.     }
  109.     public function getRoles(): array
  110.     {
  111.         return [$this->profile];
  112.     }
  113.     /**
  114.      * @return null|string The salt
  115.      */
  116.     public function getSalt(): string
  117.     {
  118.         return '';
  119.     }
  120.     /**
  121.      * @return string The user name
  122.      */
  123.     public function getUserName(): ?string
  124.     {
  125.         return $this->getName();
  126.     }
  127.     /**
  128.      * @return string The name
  129.      */
  130.     public function getName(): ?string
  131.     {
  132.         return $this->name;
  133.     }
  134.     /**
  135.      * @return AdminUser
  136.      */
  137.     public function setName(string $name): self
  138.     {
  139.         $this->name $name;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return string The firstName
  144.      */
  145.     public function getFirstName(): ?string
  146.     {
  147.         return $this->firstName;
  148.     }
  149.     /**
  150.      * @return AdminUser
  151.      */
  152.     public function setFirstName(string $firstName): self
  153.     {
  154.         $this->firstName $firstName;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return string The email
  159.      */
  160.     public function getEmail(): ?string
  161.     {
  162.         return $this->email;
  163.     }
  164.     /**
  165.      * @return AdminUser
  166.      */
  167.     public function setEmail(string $email): self
  168.     {
  169.         $this->email $email;
  170.         return $this;
  171.     }
  172.     public function eraseCredentials()
  173.     {
  174.     }
  175. }