@@ -44,7 +44,8 @@ protected function configure()
44
44
{
45
45
$ this
46
46
->setDefinition (array (
47
- new InputArgument ('address ' , InputArgument::OPTIONAL , 'Address:port ' , '127.0.0.1:8000 ' ),
47
+ new InputArgument ('address ' , InputArgument::OPTIONAL , 'Address:port ' , '127.0.0.1 ' ),
48
+ new InputOption ('port ' , 'p ' , InputOption::VALUE_REQUIRED , 'Address port number ' , '8000 ' ),
48
49
new InputOption ('docroot ' , 'd ' , InputOption::VALUE_REQUIRED , 'Document root ' , null ),
49
50
new InputOption ('router ' , 'r ' , InputOption::VALUE_REQUIRED , 'Path to custom router script ' ),
50
51
))
@@ -101,10 +102,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
101
102
$ output ->writeln ('<error>Running PHP built-in server in production environment is NOT recommended!</error> ' );
102
103
}
103
104
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 ));
105
111
$ output ->writeln ('Quit the server with CONTROL-C. ' );
106
112
107
- if (null === $ builder = $ this ->createPhpProcessBuilder ($ input , $ output , $ env )) {
113
+ if (null === $ builder = $ this ->createPhpProcessBuilder ($ input , $ output , $ env, $ address )) {
108
114
return 1 ;
109
115
}
110
116
@@ -131,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
131
137
return $ process ->getExitCode ();
132
138
}
133
139
134
- private function createPhpProcessBuilder (InputInterface $ input , OutputInterface $ output , $ env )
140
+ private function createPhpProcessBuilder (InputInterface $ input , OutputInterface $ output , $ env, $ address )
135
141
{
136
142
$ router = $ input ->getOption ('router ' ) ?: $ this
137
143
->getContainer ()
@@ -154,6 +160,6 @@ private function createPhpProcessBuilder(InputInterface $input, OutputInterface
154
160
return ;
155
161
}
156
162
157
- return new ProcessBuilder (array ($ binary , '-S ' , $ input -> getArgument ( ' address ' ) , $ router ));
163
+ return new ProcessBuilder (array ($ binary , '-S ' , $ address , $ router ));
158
164
}
159
165
}
0 commit comments