1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\RemoteRequest\Protocols\Fsp; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\RemoteRequest\Protocols; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Query |
11
|
|
|
* @package RemoteRequest\Protocols\Fsp |
12
|
|
|
* Simple FSP query to remote source - create packet |
13
|
|
|
* This is the "transport box" |
14
|
|
|
* @todo: throw compute checksum and packet building outside this class; that's logic, not pure data |
15
|
|
|
* then getData() call can have that logic |
16
|
|
|
* - X - -> re-define where are the data storages (local - this class; and remote - the packet into the run) |
17
|
|
|
* - then it's simple case of many adapters and that calculating calls should be there |
18
|
|
|
* - Adapters in HTTP are descendants of Dummy\Query and Dummy\Answer |
19
|
|
|
*/ |
20
|
|
|
class Query extends Protocols\Dummy\Query |
21
|
|
|
{ |
22
|
|
|
use Traits\THeader; |
23
|
|
|
use Traits\TChecksum; |
24
|
|
|
|
25
|
|
|
public ?int $maxLength = Protocols\Fsp::MAX_PACKET_SIZE; |
26
|
|
|
protected int $headCommand = 0; |
27
|
|
|
protected int $headServerKey = 0; |
28
|
|
|
protected int $headSequence = 0; |
29
|
|
|
protected int $headFilePosition = 0; |
30
|
|
|
protected string $contentData = ''; |
31
|
|
|
protected string $contentExtraData = ''; |
32
|
|
|
|
33
|
|
|
private string $preparedPacket = ''; |
34
|
|
|
|
35
|
17 |
|
public function setKey(int $key = 0): self |
36
|
|
|
{ |
37
|
17 |
|
$this->headServerKey = $key; |
38
|
17 |
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
17 |
|
public function setSequence(int $sequenceNumber = 0): self |
42
|
|
|
{ |
43
|
17 |
|
$this->headSequence = $sequenceNumber; |
44
|
17 |
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
17 |
|
public function setCommand(int $command): self |
48
|
|
|
{ |
49
|
17 |
|
$this->headCommand = $command; |
50
|
17 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
17 |
|
public function setFilePosition(int $filePosition): self |
54
|
|
|
{ |
55
|
17 |
|
$this->headFilePosition = $filePosition; |
56
|
17 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
17 |
|
public function setContent(string $data): self |
60
|
|
|
{ |
61
|
17 |
|
$this->contentData = $data; |
62
|
17 |
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
17 |
|
public function setExtraData(string $extraData): self |
66
|
|
|
{ |
67
|
17 |
|
$this->contentExtraData = $extraData; |
68
|
17 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
17 |
|
public function getPacket(): string |
72
|
|
|
{ |
73
|
17 |
|
$this->preparedPacket = $this->renderRequestHeader() . $this->getContent() . $this->getExtraData(); |
74
|
17 |
|
$this->preparedPacket[1] = chr($this->computeCheckSum()); |
75
|
17 |
|
return $this->preparedPacket; |
76
|
|
|
} |
77
|
|
|
|
78
|
17 |
|
public function getChecksumPacket(): string |
79
|
|
|
{ |
80
|
17 |
|
return strval($this->preparedPacket); |
81
|
|
|
} |
82
|
|
|
|
83
|
17 |
|
public function getInitialSumChunk(): int |
84
|
|
|
{ |
85
|
17 |
|
return strlen($this->preparedPacket); |
86
|
|
|
} |
87
|
|
|
|
88
|
17 |
|
protected function getCommand(): int |
89
|
|
|
{ |
90
|
17 |
|
return intval($this->headCommand); |
91
|
|
|
} |
92
|
|
|
|
93
|
17 |
|
protected function getKey(): int |
94
|
|
|
{ |
95
|
17 |
|
return intval($this->headServerKey); |
96
|
|
|
} |
97
|
|
|
|
98
|
17 |
|
protected function getSequence(): int |
99
|
|
|
{ |
100
|
17 |
|
return intval($this->headSequence); |
101
|
|
|
} |
102
|
|
|
|
103
|
17 |
|
protected function getDataLength(): int |
104
|
|
|
{ |
105
|
17 |
|
return strlen($this->getContent()); |
106
|
|
|
} |
107
|
|
|
|
108
|
17 |
|
protected function getFilePosition(): int |
109
|
|
|
{ |
110
|
17 |
|
return intval($this->headFilePosition); |
111
|
|
|
} |
112
|
|
|
|
113
|
17 |
|
protected function getContent(): string |
114
|
|
|
{ |
115
|
17 |
|
return strval($this->contentData); |
116
|
|
|
} |
117
|
|
|
|
118
|
17 |
|
protected function getExtraData(): string |
119
|
|
|
{ |
120
|
17 |
|
return strval($this->contentExtraData); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|