@@ -29,32 +29,32 @@ class ConnectionHandler implements ConnectionHandlerInterface, LoggerAwareInterf
2929 /**
3030 * @var bool
3131 */
32- protected $ shutdown ;
32+ private $ shutdown ;
3333
3434 /**
3535 * @var KernelInterface
3636 */
37- protected $ kernel ;
37+ private $ kernel ;
3838
3939 /**
4040 * @var ConnectionInterface
4141 */
42- protected $ connection ;
42+ private $ connection ;
4343
4444 /**
4545 * @var array
4646 */
47- protected $ requests ;
47+ private $ requests ;
4848
4949 /**
5050 * @var string
5151 */
52- protected $ buffer ;
52+ private $ buffer ;
5353
5454 /**
5555 * @var int
5656 */
57- protected $ bufferLength ;
57+ private $ bufferLength ;
5858
5959 /**
6060 * Constructor.
@@ -127,7 +127,7 @@ public function close()
127127 *
128128 * @return array|null The record that has been read
129129 */
130- protected function readRecord ()
130+ private function readRecord ()
131131 {
132132 // Not enough data to read header
133133 if ($ this ->bufferLength < 8 ) {
@@ -156,91 +156,14 @@ protected function readRecord()
156156 return $ record ;
157157 }
158158
159- /**
160- * Write a record to the connection.
161- *
162- * @param int $requestId The request id to write to
163- * @param int $type The type of record
164- * @param string $content The content of the record
165- */
166- protected function writeRecord ($ requestId , $ type , $ content = null )
167- {
168- $ contentLength = null === $ content ? 0 : strlen ($ content );
169-
170- $ headerData = pack ('CCnnxx ' , DaemonInterface::FCGI_VERSION_1 , $ type , $ requestId , $ contentLength );
171-
172- $ this ->connection ->write ($ headerData );
173-
174- if (null !== $ content ) {
175- $ this ->connection ->write ($ content );
176- }
177- }
178-
179- /**
180- * Write a response to the connection as FCGI_STDOUT records.
181- *
182- * @param int $requestId The request id to write to
183- * @param string $headerData The header data to write (including terminating CRLFCRLF)
184- * @param StreamInterface $stream The stream to write
185- */
186- protected function writeResponse ($ requestId , $ headerData , StreamInterface $ stream )
187- {
188- $ data = $ headerData ;
189- $ eof = false ;
190-
191- $ stream ->rewind ();
192-
193- do {
194- $ dataLength = strlen ($ data );
195-
196- if ($ dataLength < 65535 && !$ eof && !($ eof = $ stream ->eof ())) {
197- $ readLength = 65535 - $ dataLength ;
198- $ data .= $ stream ->read ($ readLength );
199- $ dataLength = strlen ($ data );
200- }
201-
202- $ writeSize = min ($ dataLength , 65535 );
203- $ writeData = substr ($ data , 0 , $ writeSize );
204- $ data = substr ($ data , $ writeSize );
205-
206- $ this ->writeRecord ($ requestId , DaemonInterface::FCGI_STDOUT , $ writeData );
207- } while ($ writeSize === 65535 );
208-
209- $ this ->writeRecord ($ requestId , DaemonInterface::FCGI_STDOUT );
210- }
211-
212- /**
213- * End the request by writing an FCGI_END_REQUEST record and then removing
214- * the request from memory and closing the connection if necessary.
215- *
216- * @param int $requestId The request id to end
217- * @param int $appStatus The application status to declare
218- * @param int $protocolStatus The protocol status to declare
219- */
220- protected function endRequest ($ requestId , $ appStatus = 0 , $ protocolStatus = DaemonInterface::FCGI_REQUEST_COMPLETE )
221- {
222- $ content = pack ('NCx3 ' , $ appStatus , $ protocolStatus );
223- $ this ->writeRecord ($ requestId , DaemonInterface::FCGI_END_REQUEST , $ content );
224-
225- $ keepAlive = $ this ->requests [$ requestId ]['keepAlive ' ];
226-
227- fclose ($ this ->requests [$ requestId ]['stdin ' ]);
228-
229- unset($ this ->requests [$ requestId ]);
230-
231- if (!$ keepAlive ) {
232- $ this ->close ();
233- }
234- }
235-
236159 /**
237160 * Process a record.
238161 *
239162 * @param array $record The record that has been read
240163 *
241164 * @throws ProtocolException If the client sends an unexpected record.
242165 */
243- protected function processRecord (array $ record )
166+ private function processRecord (array $ record )
244167 {
245168 $ requestId = $ record ['requestId ' ];
246169
@@ -276,7 +199,7 @@ protected function processRecord(array $record)
276199 *
277200 * @throws ProtocolException If the FCGI_BEGIN_REQUEST record is unexpected
278201 */
279- protected function processBeginRequestRecord ($ requestId , $ contentData )
202+ private function processBeginRequestRecord ($ requestId , $ contentData )
280203 {
281204 if (isset ($ this ->requests [$ requestId ])) {
282205 throw new ProtocolException ('Unexpected FCGI_BEGIN_REQUEST record ' );
@@ -313,7 +236,7 @@ protected function processBeginRequestRecord($requestId, $contentData)
313236 *
314237 * @throws ProtocolException If the FCGI_PARAMS record is unexpected
315238 */
316- protected function processParamsRecord ($ requestId , $ contentData )
239+ private function processParamsRecord ($ requestId , $ contentData )
317240 {
318241 if (!isset ($ this ->requests [$ requestId ])) {
319242 throw new ProtocolException ('Unexpected FCGI_PARAMS record ' );
@@ -364,7 +287,7 @@ protected function processParamsRecord($requestId, $contentData)
364287 *
365288 * @throws ProtocolException If the FCGI_STDIN record is unexpected
366289 */
367- protected function processStdinRecord ($ requestId , $ contentData )
290+ private function processStdinRecord ($ requestId , $ contentData )
368291 {
369292 if (!isset ($ this ->requests [$ requestId ])) {
370293 throw new ProtocolException ('Unexpected FCGI_STDIN record ' );
@@ -386,14 +309,91 @@ protected function processStdinRecord($requestId, $contentData)
386309 *
387310 * @throws ProtocolException If the FCGI_ABORT_REQUEST record is unexpected
388311 */
389- protected function processAbortRequestRecord ($ requestId )
312+ private function processAbortRequestRecord ($ requestId )
390313 {
391314 if (!isset ($ this ->requests [$ requestId ])) {
392315 throw new ProtocolException ('Unexpected FCG_ABORT_REQUEST record ' );
393316 }
394317
395318 $ this ->endRequest ($ requestId );
396319 }
320+
321+ /**
322+ * End the request by writing an FCGI_END_REQUEST record and then removing
323+ * the request from memory and closing the connection if necessary.
324+ *
325+ * @param int $requestId The request id to end
326+ * @param int $appStatus The application status to declare
327+ * @param int $protocolStatus The protocol status to declare
328+ */
329+ private function endRequest ($ requestId , $ appStatus = 0 , $ protocolStatus = DaemonInterface::FCGI_REQUEST_COMPLETE )
330+ {
331+ $ content = pack ('NCx3 ' , $ appStatus , $ protocolStatus );
332+ $ this ->writeRecord ($ requestId , DaemonInterface::FCGI_END_REQUEST , $ content );
333+
334+ $ keepAlive = $ this ->requests [$ requestId ]['keepAlive ' ];
335+
336+ fclose ($ this ->requests [$ requestId ]['stdin ' ]);
337+
338+ unset($ this ->requests [$ requestId ]);
339+
340+ if (!$ keepAlive ) {
341+ $ this ->close ();
342+ }
343+ }
344+
345+ /**
346+ * Write a record to the connection.
347+ *
348+ * @param int $requestId The request id to write to
349+ * @param int $type The type of record
350+ * @param string $content The content of the record
351+ */
352+ private function writeRecord ($ requestId , $ type , $ content = null )
353+ {
354+ $ contentLength = null === $ content ? 0 : strlen ($ content );
355+
356+ $ headerData = pack ('CCnnxx ' , DaemonInterface::FCGI_VERSION_1 , $ type , $ requestId , $ contentLength );
357+
358+ $ this ->connection ->write ($ headerData );
359+
360+ if (null !== $ content ) {
361+ $ this ->connection ->write ($ content );
362+ }
363+ }
364+
365+ /**
366+ * Write a response to the connection as FCGI_STDOUT records.
367+ *
368+ * @param int $requestId The request id to write to
369+ * @param string $headerData The header data to write (including terminating CRLFCRLF)
370+ * @param StreamInterface $stream The stream to write
371+ */
372+ private function writeResponse ($ requestId , $ headerData , StreamInterface $ stream )
373+ {
374+ $ data = $ headerData ;
375+ $ eof = false ;
376+
377+ $ stream ->rewind ();
378+
379+ do {
380+ $ dataLength = strlen ($ data );
381+
382+ if ($ dataLength < 65535 && !$ eof && !($ eof = $ stream ->eof ())) {
383+ $ readLength = 65535 - $ dataLength ;
384+ $ data .= $ stream ->read ($ readLength );
385+ $ dataLength = strlen ($ data );
386+ }
387+
388+ $ writeSize = min ($ dataLength , 65535 );
389+ $ writeData = substr ($ data , 0 , $ writeSize );
390+ $ data = substr ($ data , $ writeSize );
391+
392+ $ this ->writeRecord ($ requestId , DaemonInterface::FCGI_STDOUT , $ writeData );
393+ } while ($ writeSize === 65535 );
394+
395+ $ this ->writeRecord ($ requestId , DaemonInterface::FCGI_STDOUT );
396+ }
397397
398398 /**
399399 * Dispatches a request to the kernel.
@@ -402,7 +402,7 @@ protected function processAbortRequestRecord($requestId)
402402 *
403403 * @throws DaemonException If there is an error dispatching the request
404404 */
405- protected function dispatchRequest ($ requestId )
405+ private function dispatchRequest ($ requestId )
406406 {
407407 $ request = new Request (
408408 $ this ->requests [$ requestId ]['params ' ],
@@ -434,7 +434,7 @@ protected function dispatchRequest($requestId)
434434 * @param int $requestId The request id to respond to
435435 * @param ResponseInterface $response The PSR-7 HTTP response message
436436 */
437- protected function sendResponse ($ requestId , ResponseInterface $ response )
437+ private function sendResponse ($ requestId , ResponseInterface $ response )
438438 {
439439 $ statusCode = $ response ->getStatusCode ();
440440 $ reasonPhrase = $ response ->getReasonPhrase ();
@@ -456,7 +456,7 @@ protected function sendResponse($requestId, ResponseInterface $response)
456456 * @param int $requestId The request id to respond to
457457 * @param HttpFoundationResponse $response The HTTP foundation response message
458458 */
459- protected function sendHttpFoundationResponse ($ requestId , HttpFoundationResponse $ response )
459+ private function sendHttpFoundationResponse ($ requestId , HttpFoundationResponse $ response )
460460 {
461461 $ statusCode = $ response ->getStatusCode ();
462462
0 commit comments