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