PhpExecutableFinder.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Process;
  11. /**
  12. * An executable finder specifically designed for the PHP executable.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16. */
  17. class PhpExecutableFinder
  18. {
  19. private $executableFinder;
  20. public function __construct()
  21. {
  22. $this->executableFinder = new ExecutableFinder();
  23. }
  24. /**
  25. * Finds The PHP executable.
  26. *
  27. * @return string|false The PHP executable path or false if it cannot be found
  28. */
  29. public function find()
  30. {
  31. // PHP_BINARY return the current sapi executable
  32. if (defined('PHP_BINARY') && PHP_BINARY && ('cli' === PHP_SAPI)) {
  33. return PHP_BINARY;
  34. }
  35. if ($php = getenv('PHP_PATH')) {
  36. if (!is_executable($php)) {
  37. return false;
  38. }
  39. return $php;
  40. }
  41. $suffixes = DIRECTORY_SEPARATOR == '\\' ? (getenv('PATHEXT') ? explode(PATH_SEPARATOR, getenv('PATHEXT')) : array('.exe', '.bat', '.cmd', '.com')) : array('');
  42. foreach ($suffixes as $suffix) {
  43. if (is_executable($php = PHP_BINDIR.DIRECTORY_SEPARATOR.'php'.$suffix)) {
  44. return $php;
  45. }
  46. }
  47. if ($php = getenv('PHP_PEAR_PHP_BIN')) {
  48. if (is_executable($php)) {
  49. return $php;
  50. }
  51. }
  52. return $this->executableFinder->find('php');
  53. }
  54. }