PhpExecutableFinder.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * @param bool $includeArgs Whether or not include command arguments
  28. *
  29. * @return string|false The PHP executable path or false if it cannot be found
  30. */
  31. public function find($includeArgs = true)
  32. {
  33. // HHVM support
  34. if (defined('HHVM_VERSION')) {
  35. return (getenv('PHP_BINARY') ?: PHP_BINARY).($includeArgs ? ' '.implode(' ', $this->findArguments()) : '');
  36. }
  37. // PHP_BINARY return the current sapi executable
  38. if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server')) && is_file(PHP_BINARY)) {
  39. return PHP_BINARY;
  40. }
  41. if ($php = getenv('PHP_PATH')) {
  42. if (!is_executable($php)) {
  43. return false;
  44. }
  45. return $php;
  46. }
  47. if ($php = getenv('PHP_PEAR_PHP_BIN')) {
  48. if (is_executable($php)) {
  49. return $php;
  50. }
  51. }
  52. $dirs = array(PHP_BINDIR);
  53. if ('\\' === DIRECTORY_SEPARATOR) {
  54. $dirs[] = 'C:\xampp\php\\';
  55. }
  56. return $this->executableFinder->find('php', false, $dirs);
  57. }
  58. /**
  59. * Finds the PHP executable arguments.
  60. *
  61. * @return array The PHP executable arguments
  62. */
  63. public function findArguments()
  64. {
  65. $arguments = array();
  66. // HHVM support
  67. if (defined('HHVM_VERSION')) {
  68. $arguments[] = '--php';
  69. }
  70. return $arguments;
  71. }
  72. }