2024-07-11 02:29:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
|
|
|
|
use App\Repository\UserRepository;
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
|
|
|
|
|
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
|
|
|
|
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
|
|
|
|
|
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|
|
|
|
{
|
|
|
|
|
#[ORM\Id]
|
|
|
|
|
#[ORM\GeneratedValue]
|
|
|
|
|
#[ORM\Column]
|
|
|
|
|
private ?int $id = null;
|
|
|
|
|
|
|
|
|
|
#[ORM\Column(length: 180)]
|
|
|
|
|
private ?string $email = null;
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-11 17:01:16 +02:00
|
|
|
* @var array The user roles
|
2024-07-11 02:29:08 +02:00
|
|
|
*/
|
|
|
|
|
#[ORM\Column]
|
|
|
|
|
private array $roles = [];
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-11 17:01:16 +02:00
|
|
|
* @var string|null The hashed password
|
2024-07-11 02:29:08 +02:00
|
|
|
*/
|
|
|
|
|
#[ORM\Column]
|
|
|
|
|
private ?string $password = null;
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-12 15:20:24 +02:00
|
|
|
* @var Collection<int, WatchList>
|
2024-07-11 02:29:08 +02:00
|
|
|
*/
|
2024-07-12 15:20:24 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: WatchList::class, mappedBy: 'user', orphanRemoval: true)]
|
|
|
|
|
private Collection $watchLists;
|
2024-07-11 02:29:08 +02:00
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2024-07-12 15:20:24 +02:00
|
|
|
$this->watchLists = new ArrayCollection();
|
2024-07-11 02:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getId(): ?int
|
|
|
|
|
{
|
|
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getEmail(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->email;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setEmail(string $email): static
|
|
|
|
|
{
|
|
|
|
|
$this->email = $email;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A visual identifier that represents this user.
|
|
|
|
|
*
|
|
|
|
|
* @see UserInterface
|
|
|
|
|
*/
|
|
|
|
|
public function getUserIdentifier(): string
|
|
|
|
|
{
|
2024-07-11 22:22:59 +02:00
|
|
|
return (string)$this->email;
|
2024-07-11 02:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-11 22:22:59 +02:00
|
|
|
* @return list<string>
|
2024-07-11 02:29:08 +02:00
|
|
|
* @see UserInterface
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function getRoles(): array
|
|
|
|
|
{
|
|
|
|
|
$roles = $this->roles;
|
|
|
|
|
// guarantee every user at least has ROLE_USER
|
|
|
|
|
$roles[] = 'ROLE_USER';
|
|
|
|
|
|
|
|
|
|
return array_unique($roles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-11 17:01:16 +02:00
|
|
|
* @param array $roles
|
|
|
|
|
* @return User
|
2024-07-11 02:29:08 +02:00
|
|
|
*/
|
|
|
|
|
public function setRoles(array $roles): static
|
|
|
|
|
{
|
|
|
|
|
$this->roles = $roles;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see PasswordAuthenticatedUserInterface
|
|
|
|
|
*/
|
|
|
|
|
public function getPassword(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->password;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setPassword(string $password): static
|
|
|
|
|
{
|
|
|
|
|
$this->password = $password;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see UserInterface
|
|
|
|
|
*/
|
|
|
|
|
public function eraseCredentials(): void
|
|
|
|
|
{
|
|
|
|
|
// If you store any temporary, sensitive data on the user, clear it here
|
|
|
|
|
// $this->plainPassword = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-12 15:20:24 +02:00
|
|
|
* @return Collection<int, WatchList>
|
2024-07-11 02:29:08 +02:00
|
|
|
*/
|
2024-07-12 15:20:24 +02:00
|
|
|
public function getWatchLists(): Collection
|
2024-07-11 02:29:08 +02:00
|
|
|
{
|
2024-07-12 15:20:24 +02:00
|
|
|
return $this->watchLists;
|
2024-07-11 02:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-12 15:20:24 +02:00
|
|
|
public function addWatchList(WatchList $watchList): static
|
2024-07-11 02:29:08 +02:00
|
|
|
{
|
2024-07-12 15:20:24 +02:00
|
|
|
if (!$this->watchLists->contains($watchList)) {
|
|
|
|
|
$this->watchLists->add($watchList);
|
|
|
|
|
$watchList->setUser($this);
|
2024-07-11 02:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-12 15:20:24 +02:00
|
|
|
public function removeWatchList(WatchList $watchList): static
|
2024-07-11 02:29:08 +02:00
|
|
|
{
|
2024-07-12 15:20:24 +02:00
|
|
|
if ($this->watchLists->removeElement($watchList)) {
|
2024-07-11 02:29:08 +02:00
|
|
|
// set the owning side to null (unless already changed)
|
2024-07-12 15:20:24 +02:00
|
|
|
if ($watchList->getUser() === $this) {
|
|
|
|
|
$watchList->setUser(null);
|
2024-07-11 02:29:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
}
|