janus/src/Entity/Consumer.php

120 lines
2.5 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\ConsumerRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ConsumerRepository::class)
*/
class Consumer
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity=APIKey::class, mappedBy="consumer", orphanRemoval=true)
*/
private $apiKeys;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=Resource::class, mappedBy="owner", orphanRemoval=true)
*/
private $resources;
public function __construct()
{
$this->apiKeys = new ArrayCollection();
$this->resources = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|APIKey[]
*/
public function getApiKeys(): Collection
{
return $this->apiKeys;
}
public function addApiKey(APIKey $apiKey): self
{
if (!$this->apiKeys->contains($apiKey)) {
$this->apiKeys[] = $apiKey;
$apiKey->setConsumer($this);
}
return $this;
}
public function removeApiKey(APIKey $apiKey): self
{
if ($this->apiKeys->removeElement($apiKey)) {
// set the owning side to null (unless already changed)
if ($apiKey->getConsumer() === $this) {
$apiKey->setConsumer(null);
}
}
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|Resource[]
*/
public function getResources(): Collection
{
return $this->resources;
}
public function addResource(Resource $resource): self
{
if (!$this->resources->contains($resource)) {
$this->resources[] = $resource;
$resource->setOwner($this);
}
return $this;
}
public function removeResource(Resource $resource): self
{
if ($this->resources->removeElement($resource)) {
// set the owning side to null (unless already changed)
if ($resource->getOwner() === $this) {
$resource->setOwner(null);
}
}
return $this;
}
}