Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Process; Chris@0: Chris@0: /** Chris@0: * An executable finder specifically designed for the PHP executable. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: * @author Johannes M. Schmitt Chris@0: */ Chris@0: class PhpExecutableFinder Chris@0: { Chris@0: private $executableFinder; Chris@0: Chris@0: public function __construct() Chris@0: { Chris@0: $this->executableFinder = new ExecutableFinder(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Finds The PHP executable. Chris@0: * Chris@0: * @param bool $includeArgs Whether or not include command arguments Chris@0: * Chris@0: * @return string|false The PHP executable path or false if it cannot be found Chris@0: */ Chris@0: public function find($includeArgs = true) Chris@0: { Chris@0: $args = $this->findArguments(); Chris@0: $args = $includeArgs && $args ? ' '.implode(' ', $args) : ''; Chris@0: Chris@0: // HHVM support Chris@17: if (\defined('HHVM_VERSION')) { Chris@0: return (getenv('PHP_BINARY') ?: PHP_BINARY).$args; Chris@0: } Chris@0: Chris@0: // PHP_BINARY return the current sapi executable Chris@17: if (PHP_BINARY && \in_array(\PHP_SAPI, ['cli', 'cli-server', 'phpdbg'], true)) { Chris@0: return PHP_BINARY.$args; Chris@0: } Chris@0: Chris@0: if ($php = getenv('PHP_PATH')) { Chris@16: if (!@is_executable($php)) { Chris@0: return false; Chris@0: } Chris@0: Chris@0: return $php; Chris@0: } Chris@0: Chris@0: if ($php = getenv('PHP_PEAR_PHP_BIN')) { Chris@16: if (@is_executable($php)) { Chris@0: return $php; Chris@0: } Chris@0: } Chris@0: Chris@17: if (@is_executable($php = PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php'))) { Chris@14: return $php; Chris@14: } Chris@14: Chris@17: $dirs = [PHP_BINDIR]; Chris@17: if ('\\' === \DIRECTORY_SEPARATOR) { Chris@0: $dirs[] = 'C:\xampp\php\\'; Chris@0: } Chris@0: Chris@0: return $this->executableFinder->find('php', false, $dirs); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Finds the PHP executable arguments. Chris@0: * Chris@0: * @return array The PHP executable arguments Chris@0: */ Chris@0: public function findArguments() Chris@0: { Chris@17: $arguments = []; Chris@0: Chris@17: if (\defined('HHVM_VERSION')) { Chris@0: $arguments[] = '--php'; Chris@17: } elseif ('phpdbg' === \PHP_SAPI) { Chris@0: $arguments[] = '-qrr'; Chris@0: } Chris@0: Chris@0: return $arguments; Chris@0: } Chris@0: }