OnChangeContext.php 811 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. {
  15. return ($this->context['collection_operation_name'] ?? null) === 'post';
  16. }
  17. /**
  18. * La requête traitée est de type PUT
  19. *
  20. * @return bool
  21. */
  22. public function isPutRequest(): bool
  23. {
  24. return ($this->context['item_operation_name'] ?? null) === 'put';
  25. }
  26. /**
  27. * Retourne l'entité existante (avant mise à jour) si elle existe, null sinon
  28. *
  29. * @return mixed|null
  30. */
  31. public function previousData() {
  32. return $this->context['previous_data'] ?? null;
  33. }
  34. }