src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use FOS\UserBundle\Model\User as BaseUser;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  10.  * @ORM\Table(name="fos_user")
  11.  * @UniqueEntity(fields={"username"}, message="user.usernameDuplicated")
  12.  * @UniqueEntity(fields={"email"}, message="user.emailDuplicated")
  13.  */
  14. class User extends BaseUser
  15. {
  16.     /**
  17.      * @ORM\ManyToMany(targetEntity="App\Entity\Group", inversedBy="users")
  18.      * @ORM\JoinTable(name="fos_user_group")
  19.      */
  20.     protected $groups;
  21.     /**
  22.      * @ORM\Id()
  23.      * @ORM\GeneratedValue(strategy="UUID")
  24.      * @ORM\Column(type="guid")
  25.      */
  26.     protected $id;
  27.     /**
  28.      * @ORM\OneToMany(targetEntity="App\Entity\AccessToken", mappedBy="user", orphanRemoval=true, cascade={"all"})
  29.      */
  30.     private $accessTokens;
  31.     /**
  32.      * @ORM\OneToMany(
  33.      *     targetEntity="App\Entity\AuthCode",
  34.      *     mappedBy="user",
  35.      *     cascade={"ALL"},
  36.      *     orphanRemoval=true
  37.      * )
  38.      */
  39.     private $authCodes;
  40.     /**
  41.      * @ORM\OneToMany(
  42.      *     targetEntity="App\Entity\RefreshToken",
  43.      *     mappedBy="user",
  44.      *     cascade={"ALL"},
  45.      *     orphanRemoval=true
  46.      * )
  47.      */
  48.     private $refreshTokens;
  49.     public function __construct()
  50.     {
  51.         parent::__construct();
  52.         $this->accessTokens  = new ArrayCollection();
  53.         $this->refreshTokens = new ArrayCollection();
  54.         $this->authCodes     = new ArrayCollection();
  55.     }
  56.     /**
  57.      * @param AccessToken $accessToken
  58.      * @return User
  59.      */
  60.     public function addAccessToken(AccessToken $accessToken): self
  61.     {
  62.         if (!$this->accessTokens->contains($accessToken)) {
  63.             $this->accessTokens[] = $accessToken;
  64.             $accessToken->setUser($this);
  65.         }
  66.         return $this;
  67.     }
  68.     /**
  69.      * @param AuthCode $authCode
  70.      * @return User
  71.      */
  72.     public function addAuthCode(AuthCode $authCode): self
  73.     {
  74.         if (!$this->authCodes->contains($authCode)) {
  75.             $this->authCodes[] = $authCode;
  76.             $authCode->setUser($this);
  77.         }
  78.         return $this;
  79.     }
  80.     /**
  81.      * @param RefreshToken $refreshToken
  82.      * @return User
  83.      */
  84.     public function addRefreshToken(RefreshToken $refreshToken): self
  85.     {
  86.         if (!$this->refreshTokens->contains($refreshToken)) {
  87.             $this->refreshTokens[] = $refreshToken;
  88.             $refreshToken->setUser($this);
  89.         }
  90.         return $this;
  91.     }
  92.     /**
  93.      * @return User
  94.      */
  95.     public function clearGroups(): self
  96.     {
  97.         $this->groups->clear();
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return User
  102.      */
  103.     public function clearRoles(): self
  104.     {
  105.         $this->roles = array();
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return Collection|AccessToken[]
  110.      */
  111.     public function getAccessTokens(): Collection
  112.     {
  113.         return $this->accessTokens;
  114.     }
  115.     /**
  116.      * @return Collection|AuthCode[]
  117.      */
  118.     public function getAuthCodes(): Collection
  119.     {
  120.         return $this->authCodes;
  121.     }
  122.     /**
  123.      * @return Collection|RefreshToken[]
  124.      */
  125.     public function getRefreshTokens(): Collection
  126.     {
  127.         return $this->refreshTokens;
  128.     }
  129.     /**
  130.      * @param AccessToken $accessToken
  131.      * @return User
  132.      */
  133.     public function removeAccessToken(AccessToken $accessToken): self
  134.     {
  135.         if ($this->accessTokens->contains($accessToken)) {
  136.             $this->accessTokens->removeElement($accessToken);
  137.             // set the owning side to null (unless already changed)
  138.             if ($accessToken->getUser() === $this) {
  139.                 $accessToken->setUser(null);
  140.             }
  141.         }
  142.         return $this;
  143.     }
  144.     /**
  145.      * @param AuthCode $authCode
  146.      * @return User
  147.      */
  148.     public function removeAuthCode(AuthCode $authCode): self
  149.     {
  150.         if ($this->authCodes->contains($authCode)) {
  151.             $this->authCodes->removeElement($authCode);
  152.             // set the owning side to null (unless already changed)
  153.             if ($authCode->getUser() === $this) {
  154.                 $authCode->setUser(null);
  155.             }
  156.         }
  157.         return $this;
  158.     }
  159.     /**
  160.      * @param RefreshToken $refreshToken
  161.      * @return User
  162.      */
  163.     public function removeRefreshToken(RefreshToken $refreshToken): self
  164.     {
  165.         if ($this->refreshTokens->contains($refreshToken)) {
  166.             $this->refreshTokens->removeElement($refreshToken);
  167.             // set the owning side to null (unless already changed)
  168.             if ($refreshToken->getUser() === $this) {
  169.                 $refreshToken->setUser(null);
  170.             }
  171.         }
  172.         return $this;
  173.     }
  174. }