1 | <?php declare(strict_types=1); |
||
12 | class Record |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Identifies the FastCGI protocol version. |
||
17 | * |
||
18 | * @var int |
||
19 | */ |
||
20 | protected $version = FCGI::VERSION_1; |
||
21 | |||
22 | /** |
||
23 | * Identifies the FastCGI record type, i.e. the general function that the record performs. |
||
24 | * |
||
25 | * @var int |
||
26 | */ |
||
27 | protected $type = FCGI::UNKNOWN_TYPE; |
||
28 | |||
29 | /** |
||
30 | * Identifies the FastCGI request to which the record belongs. |
||
31 | * |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $requestId = FCGI::NULL_REQUEST_ID; |
||
35 | |||
36 | /** |
||
37 | * Reserved byte for future proposes |
||
38 | * |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $reserved = 0; |
||
42 | |||
43 | /** |
||
44 | * The number of bytes in the contentData component of the record. |
||
45 | * |
||
46 | * @var int |
||
47 | */ |
||
48 | private $contentLength = 0; |
||
49 | |||
50 | /** |
||
51 | * The number of bytes in the paddingData component of the record. |
||
52 | * |
||
53 | * @var int |
||
54 | */ |
||
55 | private $paddingLength = 0; |
||
56 | |||
57 | /** |
||
58 | * Binary data, between 0 and 65535 bytes of data, interpreted according to the record type. |
||
59 | * |
||
60 | * @var string |
||
61 | */ |
||
62 | private $contentData = ''; |
||
63 | |||
64 | /** |
||
65 | * Padding data, between 0 and 255 bytes of data, which are ignored. |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | private $paddingData = ''; |
||
70 | |||
71 | /** |
||
72 | * Unpacks the message from the binary data buffer |
||
73 | * |
||
74 | * @param string $data Binary buffer with raw data |
||
75 | * |
||
76 | * @return static |
||
77 | */ |
||
78 | final public static function unpack(string $data): self |
||
98 | |||
99 | /** |
||
100 | * Returns the binary message representation of record |
||
101 | */ |
||
102 | final public function __toString(): string |
||
119 | |||
120 | 13 | /** |
|
121 | * Sets the content data and adjusts the length fields |
||
122 | * |
||
123 | * @param string $data |
||
124 | * |
||
125 | * @return static |
||
126 | */ |
||
127 | public function setContentData(string $data): self |
||
135 | |||
136 | /** |
||
137 | * Returns the context data from the record |
||
138 | */ |
||
139 | public function getContentData(): string |
||
143 | 10 | ||
144 | /** |
||
145 | * Returns the version of record |
||
146 | */ |
||
147 | public function getVersion(): int |
||
151 | 1 | ||
152 | /** |
||
153 | 1 | * Returns record type |
|
154 | */ |
||
155 | public function getType(): int |
||
159 | 24 | ||
160 | /** |
||
161 | 24 | * Returns request ID |
|
162 | */ |
||
163 | public function getRequestId(): int |
||
167 | 4 | ||
168 | /** |
||
169 | 4 | * Sets request ID |
|
170 | * |
||
171 | * There should be only one unique ID for all active requests, |
||
172 | * use random number or preferably resetting auto-increment. |
||
173 | * |
||
174 | * @param int $requestId |
||
175 | * |
||
176 | * @return static |
||
177 | 3 | */ |
|
178 | public function setRequestId(int $requestId): self |
||
183 | |||
184 | /** |
||
185 | * Returns the size of content length |
||
186 | */ |
||
187 | final public function getContentLength(): int |
||
191 | 5 | ||
192 | /** |
||
193 | * Returns the size of padding length |
||
194 | */ |
||
195 | final public function getPaddingLength(): int |
||
199 | 3 | ||
200 | /** |
||
201 | 3 | * Method to unpack the payload for the record. |
|
202 | * |
||
203 | * NB: Default implementation will be always called |
||
204 | * |
||
205 | * @param static $self Instance of current frame |
||
206 | * @param string $data Binary data |
||
207 | */ |
||
208 | protected static function unpackPayload($self, string $data): void |
||
217 | 14 | ||
218 | 14 | /** |
|
219 | 14 | * Implementation of packing the payload |
|
220 | 14 | */ |
|
221 | protected function packPayload(): string |
||
225 | |||
226 | } |
||
227 |