Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Process;
13
 
14
/**
15
 * An executable finder specifically designed for the PHP executable.
16
 *
17
 * @author Fabien Potencier <fabien@symfony.com>
18
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
19
 */
20
class PhpExecutableFinder
21
{
22
    private $executableFinder;
23
 
24
    public function __construct()
25
    {
26
        $this->executableFinder = new ExecutableFinder();
27
    }
28
 
29
    /**
30
     * Finds The PHP executable.
31
     */
32
    public function find(bool $includeArgs = true): string|false
33
    {
34
        if ($php = getenv('PHP_BINARY')) {
35
            if (!is_executable($php)) {
36
                $command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v';
37
                if ($php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
38
                    if (!is_executable($php)) {
39
                        return false;
40
                    }
41
                } else {
42
                    return false;
43
                }
44
            }
45
 
46
            if (@is_dir($php)) {
47
                return false;
48
            }
49
 
50
            return $php;
51
        }
52
 
53
        $args = $this->findArguments();
54
        $args = $includeArgs && $args ? ' '.implode(' ', $args) : '';
55
 
56
        // PHP_BINARY return the current sapi executable
1663 lars 57
        if (\PHP_BINARY && \in_array(\PHP_SAPI, ['cli', 'cli-server', 'phpdbg'], true)) {
148 lars 58
            return \PHP_BINARY.$args;
59
        }
60
 
61
        if ($php = getenv('PHP_PATH')) {
62
            if (!@is_executable($php) || @is_dir($php)) {
63
                return false;
64
            }
65
 
66
            return $php;
67
        }
68
 
69
        if ($php = getenv('PHP_PEAR_PHP_BIN')) {
70
            if (@is_executable($php) && !@is_dir($php)) {
71
                return $php;
72
            }
73
        }
74
 
75
        if (@is_executable($php = \PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php')) && !@is_dir($php)) {
76
            return $php;
77
        }
78
 
79
        $dirs = [\PHP_BINDIR];
80
        if ('\\' === \DIRECTORY_SEPARATOR) {
81
            $dirs[] = 'C:\xampp\php\\';
82
        }
83
 
84
        return $this->executableFinder->find('php', false, $dirs);
85
    }
86
 
87
    /**
88
     * Finds the PHP executable arguments.
89
     */
90
    public function findArguments(): array
91
    {
92
        $arguments = [];
93
        if ('phpdbg' === \PHP_SAPI) {
94
            $arguments[] = '-qrr';
95
        }
96
 
97
        return $arguments;
98
    }
99
}