1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\Core\Objects; |
4
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface; |
7
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\ISuccessCurlResponseDtoInterface; |
8
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection; |
9
|
|
|
|
10
|
|
|
class SuccessResponse implements ISuccessCurlResponseDtoInterface, IResponseInterface |
11
|
|
|
{ |
12
|
|
|
private int $retCode; |
13
|
|
|
private string $retMsg; |
14
|
|
|
private array $retExtInfo; |
15
|
|
|
private ?string $nextPageCursor; |
16
|
|
|
private AbstractResponse $result; |
17
|
|
|
|
18
|
|
|
public function __construct(string $responseClassName, int $retCode, string $retMsg, ?array $retExtInfo, array $result, ?string $nextPageCursor = null) |
19
|
|
|
{ |
20
|
|
|
$this->retCode = $retCode; |
21
|
|
|
$this->retMsg = $retMsg; |
22
|
|
|
$this->retExtInfo = $retExtInfo ?? []; |
23
|
|
|
$this->nextPageCursor = $nextPageCursor; |
24
|
|
|
$this->result = $this->draw([$result], $responseClassName); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getReturnCode(): int |
28
|
|
|
{ |
29
|
|
|
return $this->retCode; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getReturnMessage(): string |
33
|
|
|
{ |
34
|
|
|
return $this->retMsg; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getNextPageCursor(): ?string |
38
|
|
|
{ |
39
|
|
|
return $this->nextPageCursor; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getResult(): AbstractResponse |
43
|
|
|
{ |
44
|
|
|
return $this->result; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function draw(array $result, string $responseClassName): AbstractResponse |
48
|
|
|
{ |
49
|
|
|
$collection = new EntityCollection(); |
50
|
|
|
array_walk($result, function ($item) use ($collection, $responseClassName) { |
51
|
|
|
$collection->push(ResponseDtoBuilder::make($responseClassName, $item)); |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
return $collection->fetch(); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getExtendedInfo(): array |
58
|
|
|
{ |
59
|
|
|
return $this->retExtInfo; |
60
|
|
|
} |
61
|
|
|
} |