| @@ 5-59 (lines=55) @@ | ||
| 2 | ||
| 3 | namespace WyriHaximus\React\ChildProcess\Messenger\Messages; |
|
| 4 | ||
| 5 | class RpcError implements \JsonSerializable, ActionableMessageInterface |
|
| 6 | { |
|
| 7 | /** |
|
| 8 | * @var string |
|
| 9 | */ |
|
| 10 | protected $uniqid; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @var Payload |
|
| 14 | */ |
|
| 15 | protected $payload; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param string $uniqid |
|
| 19 | * @param Payload $payload |
|
| 20 | */ |
|
| 21 | public function __construct($uniqid, Payload $payload) |
|
| 22 | { |
|
| 23 | $this->uniqid = $uniqid; |
|
| 24 | $this->payload = $payload; |
|
| 25 | } |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @return Payload |
|
| 29 | */ |
|
| 30 | public function getPayload() |
|
| 31 | { |
|
| 32 | return $this->payload; |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @return string |
|
| 37 | */ |
|
| 38 | public function jsonSerialize() |
|
| 39 | { |
|
| 40 | return [ |
|
| 41 | 'type' => 'rpc_error', |
|
| 42 | 'uniqid' => $this->uniqid, |
|
| 43 | 'payload' => $this->payload, |
|
| 44 | ]; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * @param $bindTo |
|
| 49 | * @param $source |
|
| 50 | */ |
|
| 51 | public function handle($bindTo, $source) |
|
| 52 | { |
|
| 53 | $cb = function ($payload, $uniqid) { |
|
| 54 | $this->getOutstandingCall($uniqid)->reject($payload); |
|
| 55 | }; |
|
| 56 | $cb = $cb->bindTo($bindTo); |
|
| 57 | $cb($this->payload, $this->uniqid); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 5-59 (lines=55) @@ | ||
| 2 | ||
| 3 | namespace WyriHaximus\React\ChildProcess\Messenger\Messages; |
|
| 4 | ||
| 5 | class RpcNotify implements \JsonSerializable, ActionableMessageInterface |
|
| 6 | { |
|
| 7 | /** |
|
| 8 | * @var string |
|
| 9 | */ |
|
| 10 | protected $uniqid; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @var Payload |
|
| 14 | */ |
|
| 15 | protected $payload; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param string $uniqid |
|
| 19 | * @param Payload $payload |
|
| 20 | */ |
|
| 21 | public function __construct($uniqid, Payload $payload) |
|
| 22 | { |
|
| 23 | $this->uniqid = $uniqid; |
|
| 24 | $this->payload = $payload; |
|
| 25 | } |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @return Payload |
|
| 29 | */ |
|
| 30 | public function getPayload() |
|
| 31 | { |
|
| 32 | return $this->payload; |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @return string |
|
| 37 | */ |
|
| 38 | public function jsonSerialize() |
|
| 39 | { |
|
| 40 | return [ |
|
| 41 | 'type' => 'rpc_notify', |
|
| 42 | 'uniqid' => $this->uniqid, |
|
| 43 | 'payload' => $this->payload, |
|
| 44 | ]; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * @param $bindTo |
|
| 49 | * @param $source |
|
| 50 | */ |
|
| 51 | public function handle($bindTo, $source) |
|
| 52 | { |
|
| 53 | $cb = function ($payload, $uniqid) { |
|
| 54 | $this->getOutstandingCall($uniqid)->progress($payload); |
|
| 55 | }; |
|
| 56 | $cb = $cb->bindTo($bindTo); |
|
| 57 | $cb($this->payload, $this->uniqid); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 5-59 (lines=55) @@ | ||
| 2 | ||
| 3 | namespace WyriHaximus\React\ChildProcess\Messenger\Messages; |
|
| 4 | ||
| 5 | class RpcSuccess implements \JsonSerializable, ActionableMessageInterface |
|
| 6 | { |
|
| 7 | /** |
|
| 8 | * @var string |
|
| 9 | */ |
|
| 10 | protected $uniqid; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @var Payload |
|
| 14 | */ |
|
| 15 | protected $payload; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param string $uniqid |
|
| 19 | * @param Payload $payload |
|
| 20 | */ |
|
| 21 | public function __construct($uniqid, Payload $payload) |
|
| 22 | { |
|
| 23 | $this->uniqid = $uniqid; |
|
| 24 | $this->payload = $payload; |
|
| 25 | } |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @return Payload |
|
| 29 | */ |
|
| 30 | public function getPayload() |
|
| 31 | { |
|
| 32 | return $this->payload; |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @return string |
|
| 37 | */ |
|
| 38 | public function jsonSerialize() |
|
| 39 | { |
|
| 40 | return [ |
|
| 41 | 'type' => 'rpc_success', |
|
| 42 | 'uniqid' => $this->uniqid, |
|
| 43 | 'payload' => $this->payload, |
|
| 44 | ]; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * @param $bindTo |
|
| 49 | * @param $source |
|
| 50 | */ |
|
| 51 | public function handle($bindTo, $source) |
|
| 52 | { |
|
| 53 | $cb = function ($payload, $uniqid) { |
|
| 54 | $this->getOutstandingCall($uniqid)->resolve($payload); |
|
| 55 | }; |
|
| 56 | $cb = $cb->bindTo($bindTo); |
|
| 57 | $cb($this->payload, $this->uniqid); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||