OnChangeContext.php 863 B

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