1 | <?php |
||
31 | class SelfTestCliRuntime extends AbstractSelfTest |
||
32 | { |
||
33 | /** |
||
34 | * The output buffer to keep track of the detection. |
||
35 | * |
||
36 | * @var BufferedOutput |
||
37 | */ |
||
38 | private $log; |
||
39 | |||
40 | /** |
||
41 | * Check that we have a correct CLI executable of PHP. |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | public function doTest() |
||
64 | |||
65 | /** |
||
66 | * Check if any usable php executable is available from the internal constants. |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | private function isBinaryAvailableFromConstants() |
||
79 | |||
80 | /** |
||
81 | * Check if any php executable is in the path. |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | private function isBinaryAvailableInPath() |
||
99 | |||
100 | /** |
||
101 | * Test the passed binaries. |
||
102 | * |
||
103 | * @param string[] $binaries The binaries to test. |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | private function isAnyBinaryValid($binaries) |
||
126 | |||
127 | /** |
||
128 | * Search all php binaries from the passed paths. |
||
129 | * |
||
130 | * @param string[] $paths The paths to scan for binaries. |
||
131 | * |
||
132 | * @param string[] $fileNames Optional names of files to search for. |
||
133 | * |
||
134 | * @return string[] |
||
135 | */ |
||
136 | private function findBinaries($paths, $fileNames = ['php', 'php-cli', 'php.exe']) |
||
179 | |||
180 | /** |
||
181 | * Filter out the paths not covered by basedir. |
||
182 | * |
||
183 | * @param string[] $paths The paths to filter. |
||
184 | * |
||
185 | * @param string[] $baseDirs The base dir paths. |
||
186 | * |
||
187 | * @return string[] |
||
188 | */ |
||
189 | private function filterBaseDir($paths, $baseDirs) |
||
200 | |||
201 | /** |
||
202 | * Test the cli runtime for a valid version string and return either the version or null. |
||
203 | * |
||
204 | * @param string $binary The binary to test. |
||
205 | * |
||
206 | * @return null|string |
||
207 | */ |
||
208 | private function testCliRuntime($binary) |
||
209 | { |
||
210 | $process = new Process( |
||
211 | sprintf( |
||
212 | '%s %s', |
||
213 | escapeshellcmd($binary), |
||
214 | escapeshellarg('--version') |
||
215 | ) |
||
216 | ); |
||
217 | |||
218 | if (0 !== $process->run()) { |
||
219 | return null; |
||
220 | } |
||
221 | |||
222 | // Examples for version output, add other examples here if the regex must get altered: |
||
223 | // "PHP 5.6.22-0+deb8u1 (cli)" (obtained from Debian jessie) |
||
224 | // "PHP 7.0.8-1~dotdeb+8.1 (cli) ( NTS )" (obtained from Debian jessie) |
||
225 | if (!preg_match('#.*PHP ([0-9a-zA-Z\.\-\+\~]+) \(cli\)#', $process->getOutput(), $output)) { |
||
226 | return null; |
||
227 | } |
||
228 | |||
229 | return $output[1]; |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * Retrieve the list of default paths for the current OS. |
||
234 | * |
||
235 | * @return string[] |
||
236 | */ |
||
237 | private function getDefaultPaths() |
||
252 | } |
||
253 |