PhpExecutableFinder.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. if ($php = getenv('PHP_PEAR_PHP_BIN')) {
  42. if (is_executable($php)) {
  43. return $php;
  44. }
  45. }
  46. $dirs = array(PHP_BINDIR);
  47. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  48. $dirs[] = 'C:\xampp\php\\';
  49. }
  50. return $this->executableFinder->find('php', false, $dirs);
  51. }
  52. }