Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\Process;
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * An executable finder specifically designed for the PHP executable.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @author Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
18 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
Chris@0
|
19 */
|
Chris@0
|
20 class PhpExecutableFinder
|
Chris@0
|
21 {
|
Chris@0
|
22 private $executableFinder;
|
Chris@0
|
23
|
Chris@0
|
24 public function __construct()
|
Chris@0
|
25 {
|
Chris@0
|
26 $this->executableFinder = new ExecutableFinder();
|
Chris@0
|
27 }
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * Finds The PHP executable.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @param bool $includeArgs Whether or not include command arguments
|
Chris@0
|
33 *
|
Chris@0
|
34 * @return string|false The PHP executable path or false if it cannot be found
|
Chris@0
|
35 */
|
Chris@0
|
36 public function find($includeArgs = true)
|
Chris@0
|
37 {
|
Chris@0
|
38 $args = $this->findArguments();
|
Chris@0
|
39 $args = $includeArgs && $args ? ' '.implode(' ', $args) : '';
|
Chris@0
|
40
|
Chris@0
|
41 // HHVM support
|
Chris@17
|
42 if (\defined('HHVM_VERSION')) {
|
Chris@0
|
43 return (getenv('PHP_BINARY') ?: PHP_BINARY).$args;
|
Chris@0
|
44 }
|
Chris@0
|
45
|
Chris@0
|
46 // PHP_BINARY return the current sapi executable
|
Chris@17
|
47 if (PHP_BINARY && \in_array(\PHP_SAPI, ['cli', 'cli-server', 'phpdbg'], true)) {
|
Chris@0
|
48 return PHP_BINARY.$args;
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 if ($php = getenv('PHP_PATH')) {
|
Chris@16
|
52 if (!@is_executable($php)) {
|
Chris@0
|
53 return false;
|
Chris@0
|
54 }
|
Chris@0
|
55
|
Chris@0
|
56 return $php;
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 if ($php = getenv('PHP_PEAR_PHP_BIN')) {
|
Chris@16
|
60 if (@is_executable($php)) {
|
Chris@0
|
61 return $php;
|
Chris@0
|
62 }
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@17
|
65 if (@is_executable($php = PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php'))) {
|
Chris@14
|
66 return $php;
|
Chris@14
|
67 }
|
Chris@14
|
68
|
Chris@17
|
69 $dirs = [PHP_BINDIR];
|
Chris@17
|
70 if ('\\' === \DIRECTORY_SEPARATOR) {
|
Chris@0
|
71 $dirs[] = 'C:\xampp\php\\';
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 return $this->executableFinder->find('php', false, $dirs);
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 /**
|
Chris@0
|
78 * Finds the PHP executable arguments.
|
Chris@0
|
79 *
|
Chris@0
|
80 * @return array The PHP executable arguments
|
Chris@0
|
81 */
|
Chris@0
|
82 public function findArguments()
|
Chris@0
|
83 {
|
Chris@17
|
84 $arguments = [];
|
Chris@0
|
85
|
Chris@17
|
86 if (\defined('HHVM_VERSION')) {
|
Chris@0
|
87 $arguments[] = '--php';
|
Chris@17
|
88 } elseif ('phpdbg' === \PHP_SAPI) {
|
Chris@0
|
89 $arguments[] = '-qrr';
|
Chris@0
|
90 }
|
Chris@0
|
91
|
Chris@0
|
92 return $arguments;
|
Chris@0
|
93 }
|
Chris@0
|
94 }
|