Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| StartDevServerCommand | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| start | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Lucent\Commandline; |
| 4 | |
| 5 | use Lucent\Facades\FileSystem; |
| 6 | use Lucent\Logging\ConsoleColors; |
| 7 | |
| 8 | class StartDevServerCommand |
| 9 | { |
| 10 | |
| 11 | public static string $command = "serve"; |
| 12 | |
| 13 | public function start(array $options = []): string |
| 14 | { |
| 15 | $port = $options['port'] ?? 8080; |
| 16 | |
| 17 | if (!is_numeric($port)) { |
| 18 | return "Invalid port number provided, must be a 'number'"; |
| 19 | } |
| 20 | |
| 21 | echo ConsoleColors::FG_CYAN . "Lucent Development Server Starting..." . ConsoleColors::RESET . "\n"; |
| 22 | echo ConsoleColors::FG_YELLOW . " Press Ctrl+C to stop the server" . ConsoleColors::RESET . "\n"; |
| 23 | echo ConsoleColors::FG_BLUE . str_repeat("─", 50) . ConsoleColors::RESET . "\n"; |
| 24 | |
| 25 | $docRoot = FileSystem::rootPath() . DIRECTORY_SEPARATOR . "public"; |
| 26 | |
| 27 | // Build the PHP built-in server command |
| 28 | $command = sprintf( |
| 29 | 'php -S localhost:%d -t %s', |
| 30 | $port, |
| 31 | escapeshellarg($docRoot) |
| 32 | ); |
| 33 | |
| 34 | // Use passthru to stream output in real-time |
| 35 | passthru($command, $exitCode); |
| 36 | |
| 37 | // If we get here, the server stopped |
| 38 | if ($exitCode !== 0) { |
| 39 | echo "\n" . ConsoleColors::FG_RED . "✗ Server stopped with error code: {$exitCode}" . ConsoleColors::RESET . "\n"; |
| 40 | } else { |
| 41 | echo "\n" . ConsoleColors::FG_YELLOW . "Server stopped" . ConsoleColors::RESET . "\n"; |
| 42 | } |
| 43 | |
| 44 | return ""; |
| 45 | } |
| 46 | } |