@@ -169,25 +169,24 @@ private function processRecord(array $record)
169169
170170 $ content = 0 === $ record ['contentLength ' ] ? null : $ record ['contentData ' ];
171171
172- switch ($ record ['type ' ]) {
173- case DaemonInterface::FCGI_BEGIN_REQUEST :
174- $ this ->processBeginRequestRecord ($ requestId , $ content );
175- break ;
176-
177- case DaemonInterface::FCGI_PARAMS :
178- $ this ->processParamsRecord ($ requestId , $ content );
179- break ;
180-
181- case DaemonInterface::FCGI_STDIN :
182- $ this ->processStdinRecord ($ requestId , $ content );
183- break ;
184-
185- case DaemonInterface::FCGI_ABORT_REQUEST :
186- $ this ->processAbortRequestRecord ($ requestId );
187- break ;
188-
189- default :
190- throw new ProtocolException ('Unexpected packet of unkown type: ' .$ record ['type ' ]);
172+ if (DaemonInterface::FCGI_BEGIN_REQUEST === $ record ['type ' ]) {
173+ $ this ->processBeginRequestRecord ($ requestId , $ content );
174+ } elseif (!isset ($ this ->requests [$ requestId ])) {
175+ throw new ProtocolException ('Invalid request id for record of type: ' . $ record ['type ' ]);
176+ } elseif (DaemonInterface::FCGI_PARAMS === $ record ['type ' ]) {
177+ while (strlen ($ content ) > 0 ) {
178+ $ this ->readNameValuePair ($ requestId , $ content );
179+ }
180+ } elseif (DaemonInterface::FCGI_STDIN === $ record ['type ' ]) {
181+ if (null !== $ content ) {
182+ fwrite ($ this ->requests [$ requestId ]['stdin ' ], $ content );
183+ } else {
184+ $ this ->dispatchRequest ($ requestId );
185+ }
186+ } elseif (DaemonInterface::FCGI_ABORT_REQUEST === $ record ['type ' ]) {
187+ $ this ->endRequest ($ requestId );
188+ } else {
189+ throw new ProtocolException ('Unexpected packet of type: ' .$ record ['type ' ]);
191190 }
192191 }
193192
@@ -228,29 +227,6 @@ private function processBeginRequestRecord($requestId, $contentData)
228227 }
229228 }
230229
231- /**
232- * Process a FCGI_PARAMS record.
233- *
234- * @param int $requestId The request id sending the record
235- * @param string $contentData The content of the record
236- *
237- * @throws ProtocolException If the FCGI_PARAMS record is unexpected
238- */
239- private function processParamsRecord ($ requestId , $ contentData )
240- {
241- if (!isset ($ this ->requests [$ requestId ])) {
242- throw new ProtocolException ('Unexpected FCGI_PARAMS record ' );
243- }
244-
245- if (null === $ contentData ) {
246- return ;
247- }
248-
249- do {
250- $ this ->readNameValuePair ($ requestId , $ contentData );
251- } while (strlen ($ contentData ) > 0 );
252- }
253-
254230 /**
255231 * Read a FastCGI name-value pair from a buffer and add it to the request params
256232 *
@@ -303,45 +279,6 @@ private function readFieldLength(&$buffer)
303279 return $ length ;
304280 }
305281
306- /**
307- * Process a FCGI_STDIN record.
308- *
309- * @param int $requestId The request id sending the record
310- * @param string $contentData The content of the record
311- *
312- * @throws ProtocolException If the FCGI_STDIN record is unexpected
313- */
314- private function processStdinRecord ($ requestId , $ contentData )
315- {
316- if (!isset ($ this ->requests [$ requestId ])) {
317- throw new ProtocolException ('Unexpected FCGI_STDIN record ' );
318- }
319-
320- if (null === $ contentData ) {
321- $ this ->dispatchRequest ($ requestId );
322-
323- return ;
324- }
325-
326- fwrite ($ this ->requests [$ requestId ]['stdin ' ], $ contentData );
327- }
328-
329- /**
330- * Process a FCGI_ABORT_REQUEST record.
331- *
332- * @param int $requestId The request id sending the record
333- *
334- * @throws ProtocolException If the FCGI_ABORT_REQUEST record is unexpected
335- */
336- private function processAbortRequestRecord ($ requestId )
337- {
338- if (!isset ($ this ->requests [$ requestId ])) {
339- throw new ProtocolException ('Unexpected FCG_ABORT_REQUEST record ' );
340- }
341-
342- $ this ->endRequest ($ requestId );
343- }
344-
345282 /**
346283 * End the request by writing an FCGI_END_REQUEST record and then removing
347284 * the request from memory and closing the connection if necessary.
0 commit comments