<?php
namespace App\Entity;
use App\Security\RoleInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\App\AdminUserRepository")
* @UniqueEntity(fields={"login"}, message="admin_user.form.already_exist")
*/
class AdminUser implements UserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string", length=12)
* @Assert\Length(min=4, max=12)
*/
protected $login;
/**
* @var string
*/
protected $plainPassword;
/**
* @ORM\Column(type="string")
*/
protected $password;
/**
* @ORM\Column(type="string", length=255)
*/
protected $name;
/**
* @ORM\Column(type="string", length=255)
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Email
*/
protected $email;
protected $rolesAllowed = [RoleInterface::ROLE_ADMIN, RoleInterface::ROLE_ADVISOR, RoleInterface::ROLE_COMMERCIAL];
/**
* @ORM\Column(type="string", length=16)
*/
protected $profile;
public function getId(): ?int
{
return $this->id;
}
public function getLogin(): ?string
{
return $this->login;
}
/**
* @return AdminUser
*/
public function setLogin(string $login): self
{
$this->login = $login;
return $this;
}
/**
* @return string
*/
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(string $plainPassword): self
{
$this->plainPassword = $plainPassword;
$this->password = null;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
/**
* @return AdminUser
*/
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @param $role
*
* @return AdminUser
*/
public function setProfile($role): self
{
if (!in_array($role, $this->rolesAllowed)) {
throw new \InvalidArgumentException(sprintf('Invalid value for profile : %s.', $role));
}
$this->profile = $role;
return $this;
}
public function getProfile(): ?string
{
return $this->profile;
}
public function getRoles(): array
{
return [$this->profile];
}
/**
* @return null|string The salt
*/
public function getSalt(): string
{
return '';
}
/**
* @return string The user name
*/
public function getUserName(): ?string
{
return $this->getName();
}
/**
* @return string The name
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @return AdminUser
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string The firstName
*/
public function getFirstName(): ?string
{
return $this->firstName;
}
/**
* @return AdminUser
*/
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
/**
* @return string The email
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @return AdminUser
*/
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function eraseCredentials()
{
}
}