src/Entity/Provider/Provider.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Provider;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use App\Repository\Provider\ProviderRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Ramsey\Uuid\Doctrine\UuidGenerator;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Ramsey\Uuid\Lazy\LazyUuidFromString;
  12. /**
  13.  * @ApiResource(
  14.  *      attributes={
  15.  *          "normalization_context"={"groups"={"Provider:io","Provider:o"}},
  16.  *          "denormalization_context"={"groups"={"Provider:io","Provider:i"}}
  17.  *      },
  18.  *     collectionOperations={
  19.  *          "post"={
  20.  *              "method"="POST",
  21.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  22.  *          },
  23.  *          "get"={
  24.  *              "method"="GET",
  25.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  26.  *          },
  27.  *     },
  28.  *     itemOperations={
  29.  *          "put"={
  30.  *              "method"="PUT",
  31.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  32.  *          },
  33.  *          "get"={
  34.  *              "method"="GET",
  35.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  36.  *          },
  37.  *      }
  38.  * )
  39.  * @ORM\Entity(repositoryClass=ProviderRepository::class)
  40.  */
  41. class Provider
  42. {
  43.     /**
  44.      * Hook timestampable behavior
  45.      * updates createdAt, updatedAt fields
  46.      */
  47.     use TimestampableEntity;
  48.     /**
  49.      * @ORM\Id
  50.      * @ORM\Column(type="uuid", unique=true)
  51.      * @ORM\GeneratedValue(strategy="CUSTOM")
  52.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  53.      * @ApiProperty(identifier=true)
  54.      * @Groups({"Provider:o", "Operation:o", "Coupon:o"})
  55.      */
  56.     private $id;
  57.     /**
  58.      * @ORM\Column(type="string", length=50)
  59.      * @Assert\NotBlank()
  60.      * @Groups({"Provider:io", "Operation:io", "Coupon:io"})
  61.      */
  62.     private $label;
  63.     /**
  64.      * @ORM\Column(type="string", length=255)
  65.      * @Assert\NotBlank()
  66.      * @Groups({"Provider:io", "Operation:io", "Coupon:io"})
  67.      */
  68.     private $description;
  69.     /**
  70.      * @ORM\Column(type="string", length=20, unique=true)
  71.      * @Assert\NotBlank()
  72.      * @Groups({"Provider:io", "Operation:io", "Coupon:io"})
  73.      */
  74.     private $code;
  75.     /**
  76.      * @ORM\Column(type="string", length=255)
  77.      * @Assert\NotBlank()
  78.      * @Assert\Url()
  79.      * @Groups({"Provider:io", "Operation:io", "Coupon:io"})
  80.      */
  81.     private $url;
  82.     /**
  83.      * @ORM\Column(type="json", nullable=true)
  84.      * @Assert\Json()
  85.      * @Groups({"Provider:io", "Operation:io", "Coupon:io"})
  86.      */
  87.     private $config = [];
  88.     public function getId(): ?LazyUuidFromString
  89.     {
  90.         return $this->id;
  91.     }
  92.     /**
  93.      * @return mixed
  94.      */
  95.     public function getLabel()
  96.     {
  97.         return $this->label;
  98.     }
  99.     /**
  100.      * @param mixed $label
  101.      * @return Provider
  102.      */
  103.     public function setLabel($label)
  104.     {
  105.         $this->label $label;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return mixed
  110.      */
  111.     public function getDescription()
  112.     {
  113.         return $this->description;
  114.     }
  115.     /**
  116.      * @param mixed $description
  117.      * @return Provider
  118.      */
  119.     public function setDescription($description)
  120.     {
  121.         $this->description $description;
  122.         return $this;
  123.     }
  124.     public function getCode(): ?string
  125.     {
  126.         return $this->code;
  127.     }
  128.     public function setCode(string $code): self
  129.     {
  130.         $this->code $code;
  131.         return $this;
  132.     }
  133.     public function getUrl(): ?string
  134.     {
  135.         return $this->url;
  136.     }
  137.     public function setUrl(string $url): self
  138.     {
  139.         $this->url $url;
  140.         return $this;
  141.     }
  142.     public function addConfig($key$value)
  143.     {
  144.         if(!isset($this->config[$key])) {
  145.             $this->config[$key] = $value;
  146.             return $this;
  147.         }
  148.         $this->config[$key] = $value;
  149.         return $this;
  150.     }
  151.     public function getConfig(): ?array
  152.     {
  153.         return $this->config;
  154.     }
  155.     public function setConfig(?array $config): self
  156.     {
  157.         $this->config $config;
  158.         return $this;
  159.     }
  160.     public function getConfigItem($key)
  161.     {
  162.         return $this->config[$key] ?? false;
  163.     }
  164. }