vendor/crosiersource/crosierlib-base/src/Entity/Config/AppConfig.php line 47

Open in your IDE?
  1. <?php
  2. namespace CrosierSource\CrosierLibBaseBundle\Entity\Config;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\EntityHandler;
  8. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\NotUppercase;
  9. use CrosierSource\CrosierLibBaseBundle\Entity\EntityId;
  10. use CrosierSource\CrosierLibBaseBundle\Entity\EntityIdTrait;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. /**
  14.  * @ApiResource(
  15.  *     normalizationContext={"groups"={"entity","entityId"},"enable_max_depth"=true},
  16.  *     denormalizationContext={"groups"={"entity"},"enable_max_depth"=true},
  17.  *
  18.  *     itemOperations={
  19.  *          "get"={"path"="/cfg/appConfig/{id}", "security"="is_granted('ROLE_ADMIN')"},
  20.  *          "put"={"path"="/cfg/appConfig/{id}", "security"="is_granted('ROLE_ADMIN')"},
  21.  *          "delete"={"path"="/cfg/appConfig/{id}", "security"="is_granted('ROLE_ADMIN')"}
  22.  *     },
  23.  *     collectionOperations={
  24.  *          "get"={"path"="/cfg/appConfig", "security"="is_granted('ROLE_ADMIN')"},
  25.  *          "post"={"path"="/cfg/appConfig", "security"="is_granted('ROLE_ADMIN')"}
  26.  *     },
  27.  *
  28.  *     attributes={
  29.  *          "pagination_items_per_page"=10,
  30.  *          "formats"={"jsonld", "csv"={"text/csv"}}
  31.  *     }
  32.  * )
  33.  *
  34.  * @ApiFilter(SearchFilter::class, properties={"appUUID": "exact", "chave": "partial"})
  35.  * @ApiFilter(OrderFilter::class, properties={"chave"}, arguments={"orderParameterName"="order"})
  36.  *
  37.  * @EntityHandler(entityHandlerClass="CrosierSource\CrosierLibBaseBundle\EntityHandler\Config\AppConfigEntityHandler")
  38.  *
  39.  * @ORM\Entity(repositoryClass="CrosierSource\CrosierLibBaseBundle\Repository\Config\AppConfigRepository")
  40.  * @ORM\Table(name="cfg_app_config")
  41.  *
  42.  * @author Carlos Eduardo Pauluk
  43.  */
  44. class AppConfig implements EntityId
  45. {
  46.     use EntityIdTrait;
  47.     /**
  48.      *
  49.      * @ORM\Column(name="chave", type="string", nullable=false, length=255)
  50.      * @NotUppercase()
  51.      * @Groups("entity")
  52.      *
  53.      * @var string|null
  54.      */
  55.     public ?string $chave null;
  56.     /**
  57.      *
  58.      * @ORM\Column(name="valor", type="text", nullable=true)
  59.      * @NotUppercase()
  60.      * @Groups("entity")
  61.      *
  62.      * @var string|null
  63.      */
  64.     public ?string $valor null;
  65.     /**
  66.      * @ORM\Column(name="is_json", type="boolean", nullable=false)
  67.      * @Groups("entity")
  68.      *
  69.      * @var bool|null
  70.      */
  71.     public ?bool $isJson false;
  72.     /**
  73.      * @var string
  74.      * @ORM\Column(name="app_uuid", type="string", nullable=false, length=36)
  75.      * @NotUppercase()
  76.      * @Groups("entity")
  77.      */
  78.     public ?string $appUUID null;
  79.     public function __construct(?string $chave null, ?string $appUUID null)
  80.     {
  81.         $this->chave $chave;
  82.         $this->appUUID $appUUID;
  83.     }
  84.     
  85.     public function getValorJsonDecoded(): ?array
  86.     {
  87.         if ($this->isJson || strpos($this->chave'.json') !== FALSE) {
  88.             return json_decode($this->valortrue);
  89.         } else {
  90.             return null;
  91.         }
  92.     }
  93. }