RpcResponse.php
1 <?php 2 3 namespace BitcoindRPC; 4 5 class RpcResponse 6 { 7 public function __construct( 8 public mixed $data = null, 9 public ?string $error = null, 10 public int $statusCode = 200 11 ) {} 12 13 public function isSuccess(): bool 14 { 15 return $this->error === null && $this->statusCode === 200; 16 } 17 18 public function getData(): mixed 19 { 20 return $this->data; 21 } 22 23 public function getError(): ?string 24 { 25 return $this->error; 26 } 27 28 public function getStatusCode(): int 29 { 30 return $this->statusCode; 31 } 32 33 public function toArray(): array 34 { 35 return [ 36 'success' => $this->isSuccess(), 37 'data' => $this->data, 38 'error' => $this->error, 39 'status_code' => $this->statusCode, 40 ]; 41 } 42 }