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@0
|
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@0
|
47 if (PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server', 'phpdbg')) && is_file(PHP_BINARY)) {
|
Chris@0
|
48 return PHP_BINARY.$args;
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 if ($php = getenv('PHP_PATH')) {
|
Chris@0
|
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@0
|
60 if (is_executable($php)) {
|
Chris@0
|
61 return $php;
|
Chris@0
|
62 }
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 $dirs = array(PHP_BINDIR);
|
Chris@0
|
66 if ('\\' === DIRECTORY_SEPARATOR) {
|
Chris@0
|
67 $dirs[] = 'C:\xampp\php\\';
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 return $this->executableFinder->find('php', false, $dirs);
|
Chris@0
|
71 }
|
Chris@0
|
72
|
Chris@0
|
73 /**
|
Chris@0
|
74 * Finds the PHP executable arguments.
|
Chris@0
|
75 *
|
Chris@0
|
76 * @return array The PHP executable arguments
|
Chris@0
|
77 */
|
Chris@0
|
78 public function findArguments()
|
Chris@0
|
79 {
|
Chris@0
|
80 $arguments = array();
|
Chris@0
|
81
|
Chris@0
|
82 if (defined('HHVM_VERSION')) {
|
Chris@0
|
83 $arguments[] = '--php';
|
Chris@0
|
84 } elseif ('phpdbg' === PHP_SAPI) {
|
Chris@0
|
85 $arguments[] = '-qrr';
|
Chris@0
|
86 }
|
Chris@0
|
87
|
Chris@0
|
88 return $arguments;
|
Chris@0
|
89 }
|
Chris@0
|
90 }
|