src/Entity/Domain.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\DomainRepository")
  8.  */
  9. #[ApiResource(
  10.     attributes: ['security' => "is_granted('ROLE_USER')"],
  11.     normalizationContext: ['groups' => ['domain:read']],
  12.     denormalizationContext: ['groups' => ['domain:write']],
  13.     collectionOperations: [
  14.         'get',
  15.         'post' => [
  16.             'security' => "is_granted('ROLE_ADMIN')",
  17.         ],
  18.     ],
  19.     itemOperations: [
  20.         'get',
  21.         'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
  22.     ],
  23. )]
  24. class Domain
  25. {
  26.     /**
  27.      * @ORM\Id()
  28.      * @ORM\GeneratedValue()
  29.      * @ORM\Column(type="integer")
  30.      */
  31.     private $id;
  32.     /**
  33.      * @ORM\Column(type="string", length=255)
  34.      * @Groups({"domain:read", "domain:write"})
  35.      */
  36.     private $value;
  37.     /**
  38.      * @var Company
  39.      *
  40.      * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="domains")
  41.      * @ORM\JoinColumn(nullable=false)
  42.      * Ignore()
  43.      */
  44.     private $company;
  45.     public function __toString()
  46.     {
  47.         return $this->value;
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getValue(): ?string
  54.     {
  55.         return $this->value;
  56.     }
  57.     public function setValue(string $value): self
  58.     {
  59.         $this->value $value;
  60.         return $this;
  61.     }
  62.     public function getCompany(): ?Company
  63.     {
  64.         return $this->company;
  65.     }
  66.     public function setCompany(?Company $company): self
  67.     {
  68.         $this->company $company;
  69.         return $this;
  70.     }
  71. }