@@ -227,39 +227,37 @@ protected function canTryAnotherPort()
227
227
protected function handleProcessOutput ()
228
228
{
229
229
return fn ($ type , $ buffer ) => str ($ buffer )->explode ("\n" )->each (function ($ line ) {
230
- $ parts = explode ('] ' , $ line );
231
-
232
230
if (str ($ line )->contains ('Development Server (http ' )) {
233
231
$ this ->components ->info ("Server running on [http:// {$ this ->host ()}: {$ this ->port ()}]. " );
234
232
$ this ->comment (' <fg=yellow;options=bold>Press Ctrl+C to stop the server</> ' );
235
233
236
234
$ this ->newLine ();
237
235
} elseif (str ($ line )->contains (' Accepted ' )) {
238
- $ startDate = Carbon::createFromFormat ('D M d H:i:s Y ' , ltrim ($ parts [0 ], '[ ' ));
239
-
240
- preg_match ('/\:(\d+)/ ' , $ parts [1 ], $ matches );
236
+ $ requestPort = $ this ->getRequestPortFromLine ($ line );
241
237
242
- $ this ->requestsPool [$ matches [1 ]] = [$ startDate , false ];
238
+ $ this ->requestsPool [$ requestPort ] = [
239
+ $ this ->getDateFromLine ($ line ),
240
+ false ,
241
+ ];
243
242
} elseif (str ($ line )->contains ([' [200]: GET ' ])) {
244
- preg_match ( ' /\:(\d+)/ ' , $ parts [ 1 ], $ matches );
243
+ $ requestPort = $ this -> getRequestPortFromLine ( $ line );
245
244
246
- $ this ->requestsPool [$ matches [ 1 ] ][1 ] = trim (explode ('[200]: GET ' , $ line )[1 ]);
245
+ $ this ->requestsPool [$ requestPort ][1 ] = trim (explode ('[200]: GET ' , $ line )[1 ]);
247
246
} elseif (str ($ line )->contains (' Closing ' )) {
248
- preg_match ('/\:(\d+)/ ' , $ parts [1 ], $ matches );
249
-
250
- $ request = $ this ->requestsPool [$ matches [1 ]];
247
+ $ requestPort = $ this ->getRequestPortFromLine ($ line );
248
+ $ request = $ this ->requestsPool [$ requestPort ];
251
249
252
250
[$ startDate , $ file ] = $ request ;
251
+
253
252
$ formattedStartedAt = $ startDate ->format ('Y-m-d H:i:s ' );
254
253
255
- unset($ this ->requestsPool [$ matches [ 1 ] ]);
254
+ unset($ this ->requestsPool [$ requestPort ]);
256
255
257
256
[$ date , $ time ] = explode (' ' , $ formattedStartedAt );
258
257
259
258
$ this ->output ->write (" <fg=gray> $ date</> $ time " );
260
259
261
- $ runTime = Carbon::createFromFormat ('D M d H:i:s Y ' , ltrim ($ parts [0 ], '[ ' ))
262
- ->diffInSeconds ($ startDate );
260
+ $ runTime = $ this ->getDateFromLine ($ line )->diffInSeconds ($ startDate );
263
261
264
262
if ($ file ) {
265
263
$ this ->output ->write ($ file = " $ file " );
@@ -269,16 +267,41 @@ protected function handleProcessOutput()
269
267
270
268
$ this ->output ->write (' ' .str_repeat ('<fg=gray>.</> ' , $ dots ));
271
269
$ this ->output ->writeln (" <fg=gray>~ {$ runTime }s</> " );
272
- } elseif (str ($ line )->contains (['Closed without sending a request ' , ' ]: ' ])) {
270
+ } elseif (str ($ line )->contains (['Closed without sending a request ' ])) {
273
271
// ...
274
- } elseif (isset ($ parts [1 ])) {
275
- $ this ->components ->warn ($ parts [1 ]);
276
272
} elseif (! empty ($ line )) {
277
- $ this ->components ->warn ($ line );
273
+ $ warning = explode ('] ' , $ line );
274
+ $ this ->components ->warn (count ($ warning ) > 1 ? $ warning [1 ] : $ warning [0 ]);
278
275
}
279
276
});
280
277
}
281
278
279
+ /**
280
+ * Get the date from the given PHP server output.
281
+ *
282
+ * @param string $line
283
+ * @return \Illuminate\Support\Carbon
284
+ */
285
+ protected function getDateFromLine ($ line )
286
+ {
287
+ preg_match ('/^\[([^\]]+)\]/ ' , $ line , $ matches );
288
+
289
+ return Carbon::createFromFormat ('D M d H:i:s Y ' , $ matches [1 ]);
290
+ }
291
+
292
+ /**
293
+ * Get the request port from the given PHP server output.
294
+ *
295
+ * @param string $line
296
+ * @return int
297
+ */
298
+ protected function getRequestPortFromLine ($ line )
299
+ {
300
+ preg_match ('/:(\d+)\s(?:(?:\w+$)|(?:\[.*))/ ' , $ line , $ matches );
301
+
302
+ return (int ) $ matches [1 ];
303
+ }
304
+
282
305
/**
283
306
* Get the console command options.
284
307
*
0 commit comments