<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="fos_user")
* @UniqueEntity(fields={"username"}, message="user.usernameDuplicated")
* @UniqueEntity(fields={"email"}, message="user.emailDuplicated")
*/
class User extends BaseUser
{
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Group", inversedBy="users")
* @ORM\JoinTable(name="fos_user_group")
*/
protected $groups;
/**
* @ORM\Id()
* @ORM\GeneratedValue(strategy="UUID")
* @ORM\Column(type="guid")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AccessToken", mappedBy="user", orphanRemoval=true, cascade={"all"})
*/
private $accessTokens;
/**
* @ORM\OneToMany(
* targetEntity="App\Entity\AuthCode",
* mappedBy="user",
* cascade={"ALL"},
* orphanRemoval=true
* )
*/
private $authCodes;
/**
* @ORM\OneToMany(
* targetEntity="App\Entity\RefreshToken",
* mappedBy="user",
* cascade={"ALL"},
* orphanRemoval=true
* )
*/
private $refreshTokens;
public function __construct()
{
parent::__construct();
$this->accessTokens = new ArrayCollection();
$this->refreshTokens = new ArrayCollection();
$this->authCodes = new ArrayCollection();
}
/**
* @param AccessToken $accessToken
* @return User
*/
public function addAccessToken(AccessToken $accessToken): self
{
if (!$this->accessTokens->contains($accessToken)) {
$this->accessTokens[] = $accessToken;
$accessToken->setUser($this);
}
return $this;
}
/**
* @param AuthCode $authCode
* @return User
*/
public function addAuthCode(AuthCode $authCode): self
{
if (!$this->authCodes->contains($authCode)) {
$this->authCodes[] = $authCode;
$authCode->setUser($this);
}
return $this;
}
/**
* @param RefreshToken $refreshToken
* @return User
*/
public function addRefreshToken(RefreshToken $refreshToken): self
{
if (!$this->refreshTokens->contains($refreshToken)) {
$this->refreshTokens[] = $refreshToken;
$refreshToken->setUser($this);
}
return $this;
}
/**
* @return User
*/
public function clearGroups(): self
{
$this->groups->clear();
return $this;
}
/**
* @return User
*/
public function clearRoles(): self
{
$this->roles = array();
return $this;
}
/**
* @return Collection|AccessToken[]
*/
public function getAccessTokens(): Collection
{
return $this->accessTokens;
}
/**
* @return Collection|AuthCode[]
*/
public function getAuthCodes(): Collection
{
return $this->authCodes;
}
/**
* @return Collection|RefreshToken[]
*/
public function getRefreshTokens(): Collection
{
return $this->refreshTokens;
}
/**
* @param AccessToken $accessToken
* @return User
*/
public function removeAccessToken(AccessToken $accessToken): self
{
if ($this->accessTokens->contains($accessToken)) {
$this->accessTokens->removeElement($accessToken);
// set the owning side to null (unless already changed)
if ($accessToken->getUser() === $this) {
$accessToken->setUser(null);
}
}
return $this;
}
/**
* @param AuthCode $authCode
* @return User
*/
public function removeAuthCode(AuthCode $authCode): self
{
if ($this->authCodes->contains($authCode)) {
$this->authCodes->removeElement($authCode);
// set the owning side to null (unless already changed)
if ($authCode->getUser() === $this) {
$authCode->setUser(null);
}
}
return $this;
}
/**
* @param RefreshToken $refreshToken
* @return User
*/
public function removeRefreshToken(RefreshToken $refreshToken): self
{
if ($this->refreshTokens->contains($refreshToken)) {
$this->refreshTokens->removeElement($refreshToken);
// set the owning side to null (unless already changed)
if ($refreshToken->getUser() === $this) {
$refreshToken->setUser(null);
}
}
return $this;
}
}