Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PhpExecutableFinder.php

class PhpExecutableFinder

An executable finder specifically designed for the PHP executable.

@author Fabien Potencier <fabien@symfony.com> @author Johannes M. Schmitt <schmittjoh@gmail.com>

Hierarchy

  • class \Symfony\Component\Process\PhpExecutableFinder

Expanded class hierarchy of PhpExecutableFinder

4 files declare their use of PhpExecutableFinder
EventDispatcher.php in vendor/composer/composer/src/Composer/EventDispatcher/EventDispatcher.php
PhpUnitTestRunner.php in core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
Plugin.php in vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php
ServerCommand.php in core/lib/Drupal/Core/Command/ServerCommand.php

File

vendor/symfony/process/PhpExecutableFinder.php, line 20

Namespace

Symfony\Component\Process
View source
class PhpExecutableFinder {
    private ExecutableFinder $executableFinder;
    public function __construct() {
        $this->executableFinder = new ExecutableFinder();
    }
    
    /**
     * Finds The PHP executable.
     */
    public function find(bool $includeArgs = true) : string|false {
        if ($php = getenv('PHP_BINARY')) {
            if (!is_executable($php) && !($php = $this->executableFinder
                ->find($php))) {
                return false;
            }
            if (@is_dir($php)) {
                return false;
            }
            return $php;
        }
        $args = $this->findArguments();
        $args = $includeArgs && $args ? ' ' . implode(' ', $args) : '';
        // PHP_BINARY return the current sapi executable
        if (\PHP_BINARY && \in_array(\PHP_SAPI, [
            'cli',
            'cli-server',
            'phpdbg',
        ], true)) {
            return \PHP_BINARY . $args;
        }
        if ($php = getenv('PHP_PATH')) {
            if (!@is_executable($php) || @is_dir($php)) {
                return false;
            }
            return $php;
        }
        if ($php = getenv('PHP_PEAR_PHP_BIN')) {
            if (@is_executable($php) && !@is_dir($php)) {
                return $php;
            }
        }
        if (@is_executable($php = \PHP_BINDIR . ('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php')) && !@is_dir($php)) {
            return $php;
        }
        $dirs = [
            \PHP_BINDIR,
        ];
        if ('\\' === \DIRECTORY_SEPARATOR) {
            $dirs[] = 'C:\\xampp\\php\\';
        }
        if ($herdPath = getenv('HERD_HOME')) {
            $dirs[] = $herdPath . \DIRECTORY_SEPARATOR . 'bin';
        }
        return $this->executableFinder
            ->find('php', false, $dirs);
    }
    
    /**
     * Finds the PHP executable arguments.
     */
    public function findArguments() : array {
        $arguments = [];
        if ('phpdbg' === \PHP_SAPI) {
            $arguments[] = '-qrr';
        }
        return $arguments;
    }

}

Members

Title Sort descending Modifiers Object type Summary
PhpExecutableFinder::$executableFinder private property
PhpExecutableFinder::find public function Finds The PHP executable.
PhpExecutableFinder::findArguments public function Finds the PHP executable arguments.
PhpExecutableFinder::__construct public function
RSS feed
Powered by Drupal