CreateOperation.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Service\Rest\Operation;
  4. use JetBrains\PhpStorm\Pure;
  5. /**
  6. * A single create operation (a POST request)
  7. */
  8. class CreateOperation extends BaseRestOperation
  9. {
  10. /**
  11. * @param string $label A label for the operation
  12. * @param string $entityName The name of the entity to update. This will be used in the path of the request.
  13. * @param array<mixed> $data The data to update, will be post as Json within the request.
  14. * @param array<mixed> $parameters
  15. * @param array<mixed> $options
  16. */
  17. public function __construct(
  18. protected string $label,
  19. protected string $entityName,
  20. protected array $data,
  21. protected array $parameters = [],
  22. protected array $options = []
  23. ) {
  24. $options['json'] = $this->data;
  25. parent::__construct(
  26. $label,
  27. 'POST',
  28. $entityName,
  29. [],
  30. $parameters,
  31. $options
  32. );
  33. }
  34. /**
  35. * @return string
  36. */
  37. public function getEntityName(): string
  38. {
  39. return $this->entityName;
  40. }
  41. /**
  42. * @return array<mixed>
  43. */
  44. public function getData(): array
  45. {
  46. return $this->data;
  47. }
  48. /**
  49. * Return an array of messages describing the change that this operation will bring
  50. *
  51. * @return list<string>
  52. */
  53. public function getChangeLog(): array
  54. {
  55. $messages = [
  56. '[POST ' . $this->entityName . ']'
  57. ];
  58. array_push(
  59. $messages,
  60. ...self::getRecursiveChangeLog([], $this->data)
  61. );
  62. return $messages;
  63. }
  64. }