<?php
namespace App\Entity\Provider;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
use App\Repository\Provider\ProviderRepository;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Ramsey\Uuid\Lazy\LazyUuidFromString;
/**
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={"Provider:io","Provider:o"}},
* "denormalization_context"={"groups"={"Provider:io","Provider:i"}}
* },
* collectionOperations={
* "post"={
* "method"="POST",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* },
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* },
* },
* itemOperations={
* "put"={
* "method"="PUT",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* },
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* },
* }
* )
* @ORM\Entity(repositoryClass=ProviderRepository::class)
*/
class Provider
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @ApiProperty(identifier=true)
* @Groups({"Provider:o", "Operation:o", "Coupon:o"})
*/
private $id;
/**
* @ORM\Column(type="string", length=50)
* @Assert\NotBlank()
* @Groups({"Provider:io", "Operation:io", "Coupon:io"})
*/
private $label;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
* @Groups({"Provider:io", "Operation:io", "Coupon:io"})
*/
private $description;
/**
* @ORM\Column(type="string", length=20, unique=true)
* @Assert\NotBlank()
* @Groups({"Provider:io", "Operation:io", "Coupon:io"})
*/
private $code;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
* @Assert\Url()
* @Groups({"Provider:io", "Operation:io", "Coupon:io"})
*/
private $url;
/**
* @ORM\Column(type="json", nullable=true)
* @Assert\Json()
* @Groups({"Provider:io", "Operation:io", "Coupon:io"})
*/
private $config = [];
public function getId(): ?LazyUuidFromString
{
return $this->id;
}
/**
* @return mixed
*/
public function getLabel()
{
return $this->label;
}
/**
* @param mixed $label
* @return Provider
*/
public function setLabel($label)
{
$this->label = $label;
return $this;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $description
* @return Provider
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(string $url): self
{
$this->url = $url;
return $this;
}
public function addConfig($key, $value)
{
if(!isset($this->config[$key])) {
$this->config[$key] = $value;
return $this;
}
$this->config[$key] = $value;
return $this;
}
public function getConfig(): ?array
{
return $this->config;
}
public function setConfig(?array $config): self
{
$this->config = $config;
return $this;
}
public function getConfigItem($key)
{
return $this->config[$key] ?? false;
}
}