DeleteOperation.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Service\Rest\Operation;
  4. use JetBrains\PhpStorm\Pure;
  5. /**
  6. * A single delete operation (a DELETE request)
  7. */
  8. class DeleteOperation extends BaseRestOperation
  9. {
  10. protected string $entity;
  11. protected int $id;
  12. #[Pure]
  13. public function __construct(string $label, string $entityName, array $initialData, array $options = []) {
  14. $id = (int)$initialData['id'];
  15. parent::__construct(
  16. $label,
  17. 'DELETE',
  18. $entityName . '/' . $id,
  19. [],
  20. [],
  21. $options
  22. );
  23. $this->entity = $entityName;
  24. $this->id = $id;
  25. }
  26. /**
  27. * @return string
  28. */
  29. public function getEntity(): string
  30. {
  31. return $this->entity;
  32. }
  33. protected function getExpectedResult(): ?array {
  34. return null;
  35. }
  36. /**
  37. * Return an array of messages describing the change that this operation will bring
  38. *
  39. * @return array
  40. */
  41. public function getChangeLog(): array {
  42. return [
  43. '[DELETE ' . $this->entity . '/' . $this->id . ']'
  44. ];
  45. }
  46. }