src/Entity/ConfigurationItem.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\Post;
  7. use ApiPlatform\Metadata\Put;
  8. use App\Model\Api\ConfigurationItemInput;
  9. use App\Model\EntityTime;
  10. use App\Repository\ConfigurationItemRepository;
  11. use App\State\ConfigurationItemProcessor;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. #[ApiResource(
  15.     operations: [
  16.         new Get(),
  17.         new Post(processorConfigurationItemProcessor::class),
  18.         new Put(processorConfigurationItemProcessor::class),
  19.         new Delete(),
  20.     ],
  21.     normalizationContext: ['groups' => ['identifier:read''configuration-item:read']],
  22.     denormalizationContext: ['groups' => ['configuration-item:write']],
  23.     inputConfigurationItemInput::class,
  24. )]
  25. #[ORM\Entity(repositoryClassConfigurationItemRepository::class)]
  26. #[ORM\InheritanceType('JOINED')]
  27. #[ORM\MappedSuperclass()]
  28. #[ORM\DiscriminatorColumn(name'discr'type'string')]
  29. #[ORM\DiscriminatorMap([
  30.     ConfigurationItem::DISCRIMINATOR_PARENT => ConfigurationItemParent::class,
  31.     ConfigurationItem::DISCRIMINATOR_VALUE => ConfigurationItemValue::class
  32. ])]
  33. class ConfigurationItem extends EntityTime
  34. {
  35.     const DISCRIMINATOR_ITEM 'item';
  36.     const DISCRIMINATOR_PARENT 'parent';
  37.     const DISCRIMINATOR_VALUE 'value';
  38.     #[ORM\Column(length100)]
  39.     #[Groups(['configuration-item:read'])]
  40.     protected ?string $name null;
  41.     #[ORM\ManyToOne(inversedBy'items')]
  42.     protected ?Configuration $configuration null;
  43.     #[ORM\ManyToOne(inversedBy'nodes')]
  44.     protected ?ConfigurationItemParent $parent null;
  45.     public function __construct(string $name null)
  46.     {
  47.         parent::__construct();
  48.         $this->name $name;
  49.     }
  50.     public function getName(): ?string
  51.     {
  52.         return $this->name;
  53.     }
  54.     public function setName(string $name): self
  55.     {
  56.         $this->name $name;
  57.         return $this;
  58.     }
  59.     public function getConfiguration(): ?Configuration
  60.     {
  61.         return $this->configuration;
  62.     }
  63.     public function setConfiguration(?Configuration $configuration): self
  64.     {
  65.         $this->configuration $configuration;
  66.         return $this;
  67.     }
  68.     public function getParent(): ?ConfigurationItemParent
  69.     {
  70.         return $this->parent;
  71.     }
  72.     public function setParent(?ConfigurationItemParent $parent): self
  73.     {
  74.         $this->parent $parent;
  75.         return $this;
  76.     }
  77.     public function getData(): mixed
  78.     {
  79.         return null;
  80.     }
  81.     #[Groups(['configuration-item:read'])]
  82.     public function getDiscriminator()
  83.     {
  84.         if ($this::class == ConfigurationItemValue::class)
  85.             return self::DISCRIMINATOR_VALUE;
  86.         if ($this::class == ConfigurationItemParent::class)
  87.             return self::DISCRIMINATOR_PARENT;
  88.         return self::DISCRIMINATOR_ITEM;
  89.     }
  90.     public function getGlobalConfiguration(): Configuration
  91.     {
  92.         if ($this->configuration)
  93.             return $this->configuration;
  94.         return $this->getParent()->getGlobalConfiguration();
  95.     }
  96. }