Skip to content

Commit b108541

Browse files
authored
Merge pull request #1886 from louisl/feature/issue-1880-space-in-folders
Fixed issue #1880, fixed a few typos and updated code style
2 parents d18ac02 + 3f0524f commit b108541

File tree

1 file changed

+68
-19
lines changed

1 file changed

+68
-19
lines changed

system/Commands/Server/Serve.php

Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* CodeIgniter
54
*
@@ -46,50 +45,100 @@
4645
*
4746
* Not testable, as it throws phpunit for a loop :-/
4847
*
48+
* @package CodeIgniter\Commands\Server
49+
*
4950
* @codeCoverageIgnore
5051
*/
5152
class Serve extends BaseCommand
5253
{
54+
/**
55+
* Minimum PHP version
56+
*
57+
* @var string
58+
*/
5359
protected $minPHPVersion = '7.2';
5460

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 = [
61102
'-php' => 'The PHP Binary [default: "PHP_BINARY"]',
62103
'-host' => 'The HTTP Host [default: "localhost"]',
63104
'-port' => 'The HTTP Host Port [default: "8080"]',
64105
];
65106

107+
/**
108+
* Run the server
109+
*
110+
* @param array $params Parameters
111+
*
112+
* @return void
113+
*/
66114
public function run(array $params)
67115
{
68116
// Valid PHP Version?
69117
if (phpversion() < $this->minPHPVersion)
70118
{
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());
72121
}
73122

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';
78127

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');
81130
CLI::write('Press Control-C to stop.');
82131

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);
85134

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');
88137

89138
// Call PHP's built-in webserver, making sure to set our
90139
// base path to the public folder, and to use the rewrite file
91140
// 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);
93142
}
94143

95144
}

0 commit comments

Comments
 (0)