Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85061fb

Browse files
committed
Add "executable" option to server:run console command
1 parenta2bd56e commit85061fb

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
newInputArgument('addressport', InputArgument::OPTIONAL,'The address to listen to (can be address:port, address, or port)'),
5151
newInputOption('docroot','d', InputOption::VALUE_REQUIRED,'Document root, usually where your front controllers are stored'),
5252
newInputOption('router','r', InputOption::VALUE_REQUIRED,'Path to custom router script'),
53+
newInputOption('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 =newWebServer();
132-
$config =newWebServerConfig($documentRoot,$env,$input->getArgument('addressport'),$input->getOption('router'));
137+
$config =newWebServerConfig(
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
privatefunctioncreateServerProcess(WebServerConfig$config)
147147
{
148-
$finder =newPhpExecutableFinder();
149-
if (false ===$binary =$finder->find()) {
150-
thrownew \RuntimeException('Unable to find the PHP binary.');
148+
$executable =$config->getExecutable();
149+
150+
if ($executable ===null) {
151+
$finder =newPhpExecutableFinder();
152+
if (false ===$executable =$finder->find()) {
153+
thrownew \RuntimeException('Unable to find the PHP executable.');
154+
}
151155
}
152156

153-
$process =newProcess(array($binary,'-S',$config->getAddress(),$config->getRouter()));
157+
$process =newProcess(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-
publicfunction__construct($documentRoot,$env,$address =null,$router =null)
26+
publicfunction__construct($documentRoot,$env,$address =null,$router =null,$executable =null)
2627
{
2728
if (!is_dir($documentRoot)) {
2829
thrownew \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
thrownew \InvalidArgumentException(sprintf('Port "%s" is not valid.',$this->port));
7172
}
73+
74+
$this->executable =$executable;
7275
}
7376

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

92+
publicfunctiongetExecutable()
93+
{
94+
return$this->executable;
95+
}
96+
8997
publicfunctiongetHostname()
9098
{
9199
return$this->hostname;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp