1515use Symfony \Component \Console \Input \InputOption ;
1616use Symfony \Component \Console \Input \InputInterface ;
1717use Symfony \Component \Console \Output \OutputInterface ;
18+ use Symfony \Component \Process \PhpExecutableFinder ;
1819use Symfony \Component \Process \ProcessBuilder ;
1920
2021/**
@@ -29,7 +30,7 @@ class ServerRunCommand extends ContainerAwareCommand
2930 */
3031 public function isEnabled ()
3132 {
32- if (PHP_VERSION_ID < 50400 ) {
33+ if (PHP_VERSION_ID < 50400 || defined ( ' HHVM_VERSION ' ) ) {
3334 return false ;
3435 }
3536
@@ -99,24 +100,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
99100 $ output ->writeln ('<error>Running PHP built-in server in production environment is NOT recommended!</error> ' );
100101 }
101102
102- $ router = $ input ->getOption ('router ' ) ?: $ this
103- ->getContainer ()
104- ->get ('kernel ' )
105- ->locateResource (sprintf ('@FrameworkBundle/Resources/config/router_%s.php ' , $ env ))
106- ;
107-
108- if (!file_exists ($ router )) {
109- $ output ->writeln (sprintf ('<error>The given router script "%s" does not exist</error> ' , $ router ));
110-
103+ if (null === $ builder = $ this ->createPhpProcessBuilder ($ input , $ output , $ env )) {
111104 return 1 ;
112105 }
113106
114- $ router = realpath ($ router );
115-
116107 $ output ->writeln (sprintf ("Server running on <info>http://%s</info> \n" , $ input ->getArgument ('address ' )));
117108 $ output ->writeln ('Quit the server with CONTROL-C. ' );
118109
119- $ builder = new ProcessBuilder (array (PHP_BINARY , '-S ' , $ input ->getArgument ('address ' ), $ router ));
120110 $ builder ->setWorkingDirectory ($ documentRoot );
121111 $ builder ->setTimeout (null );
122112 $ process = $ builder ->getProcess ();
@@ -136,4 +126,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
136126
137127 return $ process ->getExitCode ();
138128 }
129+
130+ private function createPhpProcessBuilder (InputInterface $ input , OutputInterface $ output , $ env )
131+ {
132+ $ router = $ input ->getOption ('router ' ) ?: $ this
133+ ->getContainer ()
134+ ->get ('kernel ' )
135+ ->locateResource (sprintf ('@FrameworkBundle/Resources/config/router_%s.php ' , $ env ))
136+ ;
137+
138+ if (!file_exists ($ router )) {
139+ $ output ->writeln (sprintf ('<error>The given router script "%s" does not exist</error> ' , $ router ));
140+
141+ return ;
142+ }
143+
144+ $ router = realpath ($ router );
145+ $ finder = new PhpExecutableFinder ();
146+
147+ if (false === $ binary = $ finder ->find ()) {
148+ $ output ->writeln ('<error>Unable to find PHP binary to run server</error> ' );
149+
150+ return ;
151+ }
152+
153+ return new ProcessBuilder (array ($ binary , '-S ' , $ input ->getArgument ('address ' ), $ router ));
154+ }
139155}
0 commit comments