OnChangeContext.php 799 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Service\OnChange;
  3. class OnChangeContext
  4. {
  5. public function __construct(
  6. private array $context
  7. ) {}
  8. /**
  9. * La requête traitée est de type POST
  10. *
  11. * @return bool
  12. */
  13. public function isPostRequest(): bool {
  14. return $this->context['collection_operation_name'] ?? null === 'post';
  15. }
  16. /**
  17. * La requête traitée est de type PUT
  18. *
  19. * @return bool
  20. */
  21. public function isPutRequest(): bool {
  22. return $this->context['item_operation_name'] ?? null === 'put';
  23. }
  24. /**
  25. * Retourne l'entité existante (avant mise à jour) si elle existe, null sinon
  26. *
  27. * @return mixed|null
  28. */
  29. public function previousData() {
  30. return $this->context['previous_data'] ?? null;
  31. }
  32. }