CreateOperation.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 $data The data to update, will be post as Json within the request.
  14. * @param array $parameters
  15. * @param array $options
  16. */
  17. #[Pure]
  18. public function __construct(
  19. protected string $label,
  20. protected string $entityName,
  21. protected array $data,
  22. protected array $parameters = [],
  23. protected array $options = []
  24. ) {
  25. $options['json'] = $this->data;
  26. parent::__construct(
  27. $label,
  28. 'POST',
  29. $entityName,
  30. [],
  31. $parameters,
  32. $options
  33. );
  34. }
  35. /**
  36. * @return string
  37. */
  38. public function getEntityName(): string
  39. {
  40. return $this->entityName;
  41. }
  42. /**
  43. * @return array
  44. */
  45. public function getData(): array
  46. {
  47. return $this->data;
  48. }
  49. /**
  50. * Return an array of messages describing the change that this operation will bring
  51. *
  52. * @return array
  53. */
  54. public function getChangeLog(): array
  55. {
  56. $messages = [
  57. '[POST ' . $this->entityName . ']'
  58. ];
  59. array_push(
  60. $messages,
  61. ...self::getRecursiveChangeLog([], $this->data)
  62. );
  63. return $messages;
  64. }
  65. }