feat: add Connector entity

This commit is contained in:
Maël Gangloff
2024-07-28 21:14:41 +02:00
parent d3560579a8
commit c3fe822f41
5 changed files with 186 additions and 0 deletions

62
src/Entity/Connector.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
namespace App\Entity;
use App\Config\ConnectorProvider;
use App\Repository\ConnectorRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ConnectorRepository::class)]
class Connector
{
#[ORM\Id]
#[ORM\Column(enumType: ConnectorProvider::class)]
private ?ConnectorProvider $provider = null;
#[ORM\Id]
#[ORM\ManyToOne(inversedBy: 'connectors')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;
#[ORM\Column]
private array $authData = [];
public function getProvider(): ?ConnectorProvider
{
return $this->provider;
}
public function setProvider(ConnectorProvider $provider): static
{
$this->provider = $provider;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
return $this;
}
public function getAuthData(): array
{
return $this->authData;
}
public function setAuthData(array $authData): static
{
$this->authData = $authData;
return $this;
}
}

View File

@@ -58,9 +58,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\OneToMany(targetEntity: WatchList::class, mappedBy: 'user', orphanRemoval: true)]
private Collection $watchLists;
/**
* @var Collection<int, Connector>
*/
#[ORM\OneToMany(targetEntity: Connector::class, mappedBy: 'userr', orphanRemoval: true)]
private Collection $connectors;
public function __construct()
{
$this->watchLists = new ArrayCollection();
$this->connectors = new ArrayCollection();
}
public function getId(): ?int
@@ -168,4 +175,34 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
/**
* @return Collection<int, Connector>
*/
public function getConnectors(): Collection
{
return $this->connectors;
}
public function addConnector(Connector $connector): static
{
if (!$this->connectors->contains($connector)) {
$this->connectors->add($connector);
$connector->setUserr($this);
}
return $this;
}
public function removeConnector(Connector $connector): static
{
if ($this->connectors->removeElement($connector)) {
// set the owning side to null (unless already changed)
if ($connector->getUserr() === $this) {
$connector->setUserr(null);
}
}
return $this;
}
}