|
6 | 6 | use Illuminate\Support\Carbon;
|
7 | 7 | use Illuminate\Support\Env;
|
8 | 8 | use Illuminate\Support\InteractsWithTime;
|
| 9 | +use InvalidArgumentException; |
9 | 10 | use Symfony\Component\Console\Attribute\AsCommand;
|
10 | 11 | use Symfony\Component\Console\Input\InputOption;
|
11 | 12 | use Symfony\Component\Process\Process;
|
12 |
| - |
13 | 13 | use function Illuminate\Support\php_binary;
|
14 | 14 | use function Termwind\terminal;
|
15 | 15 |
|
@@ -291,23 +291,23 @@ protected function flushOutputBuffer()
|
291 | 291 | }
|
292 | 292 |
|
293 | 293 | if (str($line)->contains(' Accepted')) {
|
294 |
| - $requestPort = $this->getRequestPortFromLine($line); |
| 294 | + $requestPort = static::getRequestPortFromLine($line); |
295 | 295 |
|
296 | 296 | $this->requestsPool[$requestPort] = [
|
297 | 297 | $this->getDateFromLine($line),
|
298 | 298 | $this->requestsPool[$requestPort][1] ?? false,
|
299 | 299 | microtime(true),
|
300 | 300 | ];
|
301 | 301 | } elseif (str($line)->contains([' [200]: GET '])) {
|
302 |
| - $requestPort = $this->getRequestPortFromLine($line); |
| 302 | + $requestPort = static::getRequestPortFromLine($line); |
303 | 303 |
|
304 | 304 | $this->requestsPool[$requestPort][1] = trim(explode('[200]: GET', $line)[1]);
|
305 | 305 | } elseif (str($line)->contains('URI:')) {
|
306 |
| - $requestPort = $this->getRequestPortFromLine($line); |
| 306 | + $requestPort = static::getRequestPortFromLine($line); |
307 | 307 |
|
308 | 308 | $this->requestsPool[$requestPort][1] = trim(explode('URI: ', $line)[1]);
|
309 | 309 | } elseif (str($line)->contains(' Closing')) {
|
310 |
| - $requestPort = $this->getRequestPortFromLine($line); |
| 310 | + $requestPort = static::getRequestPortFromLine($line); |
311 | 311 |
|
312 | 312 | if (empty($this->requestsPool[$requestPort])) {
|
313 | 313 | $this->requestsPool[$requestPort] = [
|
@@ -374,11 +374,15 @@ protected function getDateFromLine($line)
|
374 | 374 | * @param string $line
|
375 | 375 | * @return int
|
376 | 376 | */
|
377 |
| - protected function getRequestPortFromLine($line) |
| 377 | + public static function getRequestPortFromLine($line) |
378 | 378 | {
|
379 |
| - preg_match('/:(\d+)\s(?:(?:\w+$)|(?:\[.*))/', $line, $matches); |
| 379 | + preg_match('/(\[\w+\s\w+\s\d+\s[\d:]+\s\d{4}\]\s)?:(\d+)\s(?:(?:\w+$)|(?:\[.*))/', $line, $matches); |
| 380 | + |
| 381 | + if (! isset($matches[2])) { |
| 382 | + throw new \InvalidArgumentException("Failed to extract the request port. Ensure the log line contains a valid port: {$line}"); |
| 383 | + } |
380 | 384 |
|
381 |
| - return (int) $matches[1]; |
| 385 | + return (int) $matches[2]; |
382 | 386 | }
|
383 | 387 |
|
384 | 388 | /**
|
|
0 commit comments