10000 Add "executable" option to server:run console command · symfony/symfony@85061fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 85061fb

Browse files
committed
Add "executable" option to server:run console command
1 parent a2bd56e commit 85061fb

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/Symfony/Bundle/WebServerBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* WebServer can now use '*' as a wildcard to bind to 0.0.0.0 (INADDR_ANY)
8+
* `server:run` command now has `executable` option that allows using custom executable for the commandline server (such as `php -c /path/to/ini`)
89

910
3.3.0
1011
-----

src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function configure()
5050
new InputArgument('addressport', InputArgument::OPTIONAL, 'The address to listen to (can be address:port, address, or port)'),
5151
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root, usually where your front controllers are stored'),
5252
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
53+
new InputOption('executable', 'e', InputOption::VALUE_REQUIRED, 'Custom executable for the PHP commandline webserver'),
5354
))
5455
->setName('server:run')
5556
->setDescription('Runs a local web server')
@@ -76,6 +77,10 @@ protected function configure()
7677
7778
<info>%command.full_name% --router=app/config/router.php</info>
7879
80+
Specify your own server executable via the <info>--executable</info> option:
81+
82+
<info>%command.full_name% --executable=/usr/bin/php7</info>
83+
7984
See also: http://www.php.net/manual/en/features.commandline.webserver.php
8085
EOF
8186
)
@@ -129,7 +134,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
129134

130135
try {
131136
$server = new WebServer();
132-
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));
137+
$config = new WebServerConfig(
138+
$documentRoot,
139+
$env,
140+
$input->getArgument('addressport'),
141+
$input->getOption('router'),
142+
$input->getOption('executable')
143+
);
133144

134145
$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
135146
$io->comment('Quit the server with CONTROL-C.');

src/Symfony/Bundle/WebServerBundle/WebServer.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ public function isRunning($pidFile = null)
145145
*/
146146
private function createServerProcess(WebServerConfig $config)
147147
{
148-
$finder = new PhpExecutableFinder();
149-
if (false === $binary = $finder->find()) {
150-
throw new \RuntimeException('Unable to find the PHP binary.');
148+
$executable = $config->getExecutable();
149+
150+
if ($executable === null) {
151+
$finder = new PhpExecutableFinder();
152+
if (false === $executable = $finder->find()) {
153+
throw new \RuntimeException('Unable to find the PHP executable.');
154+
}
151155
}
152156

153-
$process = new Process(array($binary, '-S', $config->getAddress(), $config->getRouter()));
157+
$process = new Process(array($executable, '-S', $config->getAddress(), $config->getRouter()));
154158
$process->setWorkingDirectory($config->getDocumentRoot());
155159
$process->setTimeout(null);
156160

src/Symfony/Bundle/WebServerBundle/WebServerConfig.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class WebServerConfig
2121
private $documentRoot;
2222
private $env;
2323
private $router;
24+
private $executable;
2425

25-
public function __construct($documentRoot, $env, $address = null, $router = null)
26+
public function __construct($documentRoot, $env, $address = null, $router = null, $executable = null)
2627
{
2728
if (!is_dir($documentRoot)) {
2829
throw new \InvalidArgumentException(sprintf('The document root directory "%s" does not exist.', $documentRoot));
@@ -69,6 +70,8 @@ public function __construct($documentRoot, $env, $address = null, $router = null
6970
if (!ctype_digit($this->port)) {
7071
throw new \InvalidArgumentException(sprintf('Port "%s" is not valid.', $this->port));
7172
}
73+
74+
$this->executable = $executable;
7275
}
7376

7477
public function getDocumentRoot()
@@ -86,6 +89,11 @@ public function getRouter()
8689
return $this->router;
8790
}
8891

92+
public function getExecutable()
93+
{
94+
return $this->executable;
95+
}
96+
8997
public function getHostname()
9098
{
9199
return $this->hostname;

0 commit comments

Comments
 (0)
0