src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Util\SecurityUtil;
  8. use App\Entity\Traits\UserPropertyTrait;
  9. /**
  10.  *
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  * @ORM\Table(name="users")
  13.  * @UniqueEntity("username")
  14.  */
  15. class User implements UserInterface
  16. {
  17.     use UserPropertyTrait;
  18.     const NAME '用户';
  19.     /**
  20.      *
  21.      * @ORM\ManyToOne(targetEntity="College")
  22.      */
  23.     protected $adminCollege;
  24.     /**
  25.      *
  26.      * @ORM\Column(length=25)
  27.      * @Assert\Choice(callback={"App\Util\SecurityUtil", "roleOptions"})
  28.      */
  29.     protected $role SecurityUtil::ROLE_APPLICANT;
  30.     /**
  31.      *
  32.      * @ORM\OneToOne(targetEntity="UserInfo")
  33.      */
  34.     protected $userInfo;
  35.     /**
  36.      *
  37.      * @see UserInterface
  38.      */
  39.     public function getRoles(): array
  40.     {
  41.         return [
  42.             $this->role
  43.         ];
  44.     }
  45.     public function setRoles(array $roles)
  46.     {
  47.         $this->roles $roles;
  48.     }
  49.     public function getPassword(): ?string
  50.     {
  51.         return null;
  52.     }
  53.     public function getAdminCollege(): ?College
  54.     {
  55.         return $this->adminCollege;
  56.     }
  57.     public function setAdminCollege(?College $adminCollege)
  58.     {
  59.         $this->adminCollege $adminCollege;
  60.     }
  61.     public function getRole(): string
  62.     {
  63.         return $this->role;
  64.     }
  65.     public function setRole(string $role)
  66.     {
  67.         $this->role $role;
  68.     }
  69.     public function setUserInfo(?UserInfo $userInfo)
  70.     {
  71.         $this->userInfo $userInfo;
  72.     }
  73.     public function getUserInfo(): ?UserInfo
  74.     {
  75.         return $this->userInfo;
  76.     }
  77.     public function getRoleName(): string
  78.     {
  79.         return SecurityUtil::ROLE_NAMES[$this->role];
  80.     }
  81.     public function __toString(): string
  82.     {
  83.         return $this->name ?: $this->username;
  84.     }
  85. }