15
15
use Symfony \Component \Console \Input \InputOption ;
16
16
use Symfony \Component \Console \Input \InputInterface ;
17
17
use Symfony \Component \Console \Output \OutputInterface ;
18
+ use Symfony \Component \Process \PhpExecutableFinder ;
18
19
use Symfony \Component \Process \ProcessBuilder ;
19
20
20
21
/**
@@ -29,7 +30,7 @@ class ServerRunCommand extends ContainerAwareCommand
29
30
*/
30
31
public function isEnabled ()
31
32
{
32
- if (PHP_VERSION_ID < 50400 ) {
33
+ if (PHP_VERSION_ID < 50400 || defined ( ' HHVM_VERSION ' ) ) {
33
34
return false ;
34
35
}
35
36
@@ -99,24 +100,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
99
100
$ output ->writeln ('<error>Running PHP built-in server in production environment is NOT recommended!</error> ' );
100
101
}
101
102
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 )) {
111
104
return 1 ;
112
105
}
113
106
114
- $ router = realpath ($ router );
115
-
116
107
$ output ->writeln (sprintf ("Server running on <info>http://%s</info> \n" , $ input ->getArgument ('address ' )));
117
108
$ output ->writeln ('Quit the server with CONTROL-C. ' );
118
109
119
- $ builder = new ProcessBuilder (array (PHP_BINARY , '-S ' , $ input ->getArgument ('address ' ), $ router ));
120
110
$ builder ->setWorkingDirectory ($ documentRoot );
121
111
$ builder ->setTimeout (null );
122
112
$ process = $ builder ->getProcess ();
@@ -136,4 +126,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
136
126
137
127
return $ process ->getExitCode ();
138
128
}
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
+ }
139
155
}
0 commit comments