Rocket.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Pay;
  4. use ArrayAccess;
  5. use JsonSerializable as JsonSerializableInterface;
  6. use Psr\Http\Message\MessageInterface;
  7. use Psr\Http\Message\RequestInterface;
  8. use Yansongda\Pay\Contract\DirectionInterface;
  9. use Yansongda\Pay\Contract\PackerInterface;
  10. use Yansongda\Supports\Collection;
  11. use Yansongda\Supports\Traits\Accessable;
  12. use Yansongda\Supports\Traits\Arrayable;
  13. use Yansongda\Supports\Traits\Serializable;
  14. class Rocket implements JsonSerializableInterface, ArrayAccess
  15. {
  16. use Accessable;
  17. use Arrayable;
  18. use Serializable;
  19. private ?RequestInterface $radar = null;
  20. private array $params = [];
  21. private ?Collection $payload = null;
  22. private string $packer = PackerInterface::class;
  23. private string $direction = DirectionInterface::class;
  24. /**
  25. * @var null|array|Collection|MessageInterface
  26. */
  27. private $destination;
  28. private ?MessageInterface $destinationOrigin = null;
  29. public function getRadar(): ?RequestInterface
  30. {
  31. return $this->radar;
  32. }
  33. public function setRadar(?RequestInterface $radar): Rocket
  34. {
  35. $this->radar = $radar;
  36. return $this;
  37. }
  38. public function getParams(): array
  39. {
  40. return $this->params;
  41. }
  42. public function setParams(array $params): Rocket
  43. {
  44. $this->params = $params;
  45. return $this;
  46. }
  47. public function mergeParams(array $params): Rocket
  48. {
  49. $this->params = array_merge($this->params, $params);
  50. return $this;
  51. }
  52. public function getPayload(): ?Collection
  53. {
  54. return $this->payload;
  55. }
  56. public function setPayload(?Collection $payload): Rocket
  57. {
  58. $this->payload = $payload;
  59. return $this;
  60. }
  61. public function mergePayload(array $payload): Rocket
  62. {
  63. if (empty($this->payload)) {
  64. $this->payload = new Collection();
  65. }
  66. $this->payload = $this->payload->merge($payload);
  67. return $this;
  68. }
  69. public function getPacker(): string
  70. {
  71. return $this->packer;
  72. }
  73. public function setPacker(string $packer): Rocket
  74. {
  75. $this->packer = $packer;
  76. return $this;
  77. }
  78. public function getDirection(): string
  79. {
  80. return $this->direction;
  81. }
  82. public function setDirection(string $direction): Rocket
  83. {
  84. $this->direction = $direction;
  85. return $this;
  86. }
  87. /**
  88. * @return null|array|Collection|MessageInterface
  89. */
  90. public function getDestination()
  91. {
  92. return $this->destination;
  93. }
  94. /**
  95. * @param null|array|Collection|MessageInterface $destination
  96. */
  97. public function setDestination($destination): Rocket
  98. {
  99. $this->destination = $destination;
  100. return $this;
  101. }
  102. public function getDestinationOrigin(): ?MessageInterface
  103. {
  104. return $this->destinationOrigin;
  105. }
  106. public function setDestinationOrigin(?MessageInterface $destinationOrigin): Rocket
  107. {
  108. $this->destinationOrigin = $destinationOrigin;
  109. return $this;
  110. }
  111. }