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

Commit83dbaae

Browse files
committed
[FrameworkBundle][Server Command] add address port number option.
1 parent222701f commit83dbaae

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ protected function configure()
4444
{
4545
$this
4646
->setDefinition(array(
47-
newInputArgument('address', InputArgument::OPTIONAL,'Address:port','127.0.0.1:8000'),
47+
newInputArgument('address', InputArgument::OPTIONAL,'Address:port','127.0.0.1'),
48+
newInputOption('port','p', InputOption::VALUE_REQUIRED,'Address port number','8000'),
4849
newInputOption('docroot','d', InputOption::VALUE_REQUIRED,'Document root',null),
4950
newInputOption('router','r', InputOption::VALUE_REQUIRED,'Path to custom router script'),
5051
))
@@ -101,10 +102,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
101102
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
102103
}
103104

104-
$output->writeln(sprintf("Server running on <info>http://%s</info>\n",$input->getArgument('address')));
105+
$address =$input->getArgument('address');
106+
if (false ===strpos($address,':')) {
107+
$address =$address.':'.$input->getOption('port');
108+
}
109+
110+
$output->writeln(sprintf("Server running on <info>http://%s</info>\n",$address));
105111
$output->writeln('Quit the server with CONTROL-C.');
106112

107-
if (null ===$builder =$this->createPhpProcessBuilder($input,$output,$env)) {
113+
if (null ===$builder =$this->createPhpProcessBuilder($input,$output,$env,$address)) {
108114
return1;
109115
}
110116

@@ -131,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
131137
return$process->getExitCode();
132138
}
133139

134-
privatefunctioncreatePhpProcessBuilder(InputInterface$input,OutputInterface$output,$env)
140+
privatefunctioncreatePhpProcessBuilder(InputInterface$input,OutputInterface$output,$env,$address)
135141
{
136142
$router =$input->getOption('router') ?:$this
137143
->getContainer()
@@ -154,6 +160,6 @@ private function createPhpProcessBuilder(InputInterface $input, OutputInterface
154160
return;
155161
}
156162

157-
returnnewProcessBuilder(array($binary,'-S',$input->getArgument('address'),$router));
163+
returnnewProcessBuilder(array($binary,'-S',$address,$router));
158164
}
159165
}

‎src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ protected function configure()
3333
{
3434
$this
3535
->setDefinition(array(
36-
newInputArgument('address', InputArgument::OPTIONAL,'Address:port','127.0.0.1:8000'),
36+
newInputArgument('address', InputArgument::OPTIONAL,'Address:port','127.0.0.1'),
37+
newInputOption('port','p', InputOption::VALUE_REQUIRED,'Address port number','8000'),
3738
newInputOption('docroot','d', InputOption::VALUE_REQUIRED,'Document root',null),
3839
newInputOption('router','r', InputOption::VALUE_REQUIRED,'Path to custom router script'),
3940
))
@@ -98,12 +99,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9899
}
99100

100101
$env =$this->getContainer()->getParameter('kernel.environment');
101-
$address =$input->getArgument('address');
102102

103+
$address =$input->getArgument('address');
103104
if (false ===strpos($address,':')) {
104-
$output->writeln('The address has to be of the form <comment>bind-address:port</comment>.');
105-
106-
return1;
105+
$address =$address.':'.$input->getOption('port');
107106
}
108107

109108
if ($this->isOtherServerProcessRunning($address)) {

‎src/Symfony/Bundle/FrameworkBundle/Command/ServerStopCommand.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
useSymfony\Component\Console\Input\InputArgument;
1515
useSymfony\Component\Console\Input\InputInterface;
1616
useSymfony\Component\Console\Output\OutputInterface;
17+
useSymfony\Component\Console\Input\InputOption;
1718

1819
/**
1920
* Stops a background process running PHP's built-in web server.
@@ -29,7 +30,8 @@ protected function configure()
2930
{
3031
$this
3132
->setDefinition(array(
32-
newInputArgument('address', InputArgument::OPTIONAL,'Address:port','127.0.0.1:8000'),
33+
newInputArgument('address', InputArgument::OPTIONAL,'Address:port','127.0.0.1'),
34+
newInputOption('port','p', InputOption::VALUE_REQUIRED,'Address port number','8000'),
3335
))
3436
->setName('server:stop')
3537
->setDescription('Stops PHP\'s built-in web server that was started with the server:start command')
@@ -53,6 +55,10 @@ protected function configure()
5355
protectedfunctionexecute(InputInterface$input,OutputInterface$output)
5456
{
5557
$address =$input->getArgument('address');
58+
if (false ===strpos($address,':')) {
59+
$address =$address.':'.$input->getOption('port');
60+
}
61+
5662
$lockFile =$this->getLockFile($address);
5763

5864
if (!file_exists($lockFile)) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp