|
1 | 1 | <?php
|
2 |
| - |
3 | 2 | /**
|
4 | 3 | * CodeIgniter
|
5 | 4 | *
|
|
46 | 45 | *
|
47 | 46 | * Not testable, as it throws phpunit for a loop :-/
|
48 | 47 | *
|
| 48 | + * @package CodeIgniter\Commands\Server |
| 49 | + * |
49 | 50 | * @codeCoverageIgnore
|
50 | 51 | */
|
51 | 52 | class Serve extends BaseCommand
|
52 | 53 | {
|
| 54 | + /** |
| 55 | + * Minimum PHP version |
| 56 | + * |
| 57 | + * @var string |
| 58 | + */ |
53 | 59 | protected $minPHPVersion = '7.2';
|
54 | 60 |
|
55 |
| - protected $group = 'CodeIgniter'; |
56 |
| - protected $name = 'serve'; |
57 |
| - protected $description = 'Launchs the CodeIgniter PHP-Development Server.'; |
58 |
| - protected $usage = 'serve'; |
59 |
| - protected $arguments = []; |
60 |
| - protected $options = [ |
| 61 | + /** |
| 62 | + * Group |
| 63 | + * |
| 64 | + * @var string |
| 65 | + */ |
| 66 | + protected $group = 'CodeIgniter'; |
| 67 | + |
| 68 | + /** |
| 69 | + * Name |
| 70 | + * |
| 71 | + * @var string |
| 72 | + */ |
| 73 | + protected $name = 'serve'; |
| 74 | + |
| 75 | + /** |
| 76 | + * Description |
| 77 | + * |
| 78 | + * @var string |
| 79 | + */ |
| 80 | + protected $description = 'Launches the CodeIgniter PHP-Development Server.'; |
| 81 | + |
| 82 | + /** |
| 83 | + * Usage |
| 84 | + * |
| 85 | + * @var string |
| 86 | + */ |
| 87 | + protected $usage = 'serve'; |
| 88 | + |
| 89 | + /** |
| 90 | + * Arguments |
| 91 | + * |
| 92 | + * @var array |
| 93 | + */ |
| 94 | + protected $arguments = []; |
| 95 | + |
| 96 | + /** |
| 97 | + * Options |
| 98 | + * |
| 99 | + * @var array |
| 100 | + */ |
| 101 | + protected $options = [ |
61 | 102 | '-php' => 'The PHP Binary [default: "PHP_BINARY"]',
|
62 | 103 | '-host' => 'The HTTP Host [default: "localhost"]',
|
63 | 104 | '-port' => 'The HTTP Host Port [default: "8080"]',
|
64 | 105 | ];
|
65 | 106 |
|
| 107 | + /** |
| 108 | + * Run the server |
| 109 | + * |
| 110 | + * @param array $params Parameters |
| 111 | + * |
| 112 | + * @return void |
| 113 | + */ |
66 | 114 | public function run(array $params)
|
67 | 115 | {
|
68 | 116 | // Valid PHP Version?
|
69 | 117 | if (phpversion() < $this->minPHPVersion)
|
70 | 118 | {
|
71 |
| - die("You PHP version must be {$this->minPHPVersion} or higher to run CodeIgniter. Current version: " . phpversion()); |
| 119 | + die('Your PHP version must be ' . $this->minPHPVersion . |
| 120 | + ' or higher to run CodeIgniter. Current version: ' . phpversion()); |
72 | 121 | }
|
73 | 122 |
|
74 |
| - // Collect any user-supplied options and apply them |
75 |
| - $php = CLI::getOption('php') ?? PHP_BINARY; |
76 |
| - $host = CLI::getOption('host') ?? 'localhost'; |
77 |
| - $port = CLI::getOption('port') ?? '8080'; |
| 123 | + // Collect any user-supplied options and apply them. |
| 124 | + $php = escapeshellarg(CLI::getOption('php')) ?? PHP_BINARY; |
| 125 | + $host = escapeshellarg(CLI::getOption('host')) ?? 'localhost'; |
| 126 | + $port = escapeshellarg(CLI::getOption('port')) ?? '8080'; |
78 | 127 |
|
79 |
| - // Get the party started |
80 |
| - CLI::write("CodeIgniter development server started on http://{$host}:{$port}", 'green'); |
| 128 | + // Get the party started. |
| 129 | + CLI::write('CodeIgniter development server started on http://' . $host . ':' . $port, 'green'); |
81 | 130 | CLI::write('Press Control-C to stop.');
|
82 | 131 |
|
83 |
| - // Set the Front Controller path as Document Root |
84 |
| - $docroot = FCPATH; |
| 132 | + // Set the Front Controller path as Document Root. |
| 133 | + $docroot = escapeshellarg(FCPATH); |
85 | 134 |
|
86 |
| - // Mimic Apache's mod_rewrite functionality with user settings |
87 |
| - $rewrite = __DIR__ . '/rewrite.php'; |
| 135 | + // Mimic Apache's mod_rewrite functionality with user settings. |
| 136 | + $rewrite = escapeshellarg(__DIR__ . '/rewrite.php'); |
88 | 137 |
|
89 | 138 | // Call PHP's built-in webserver, making sure to set our
|
90 | 139 | // base path to the public folder, and to use the rewrite file
|
91 | 140 | // to ensure our environment is set and it simulates basic mod_rewrite.
|
92 |
| - passthru("{$php} -S {$host}:{$port} -t {$docroot} {$rewrite}"); |
| 141 | + passthru($php . ' -S ' . $host . ':' . $port . ' -t ' . $docroot . ' ' . $rewrite); |
93 | 142 | }
|
94 | 143 |
|
95 | 144 | }
|
0 commit comments