Skip to content

Commit 36fb2b2

Browse files
committed
#25187 Lookup php binary in PHP_BINDIR first
1 parent 37baa1d commit 36fb2b2

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

src/Symfony/Component/Process/ExecutableFinder.php

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class ExecutableFinder
2323

2424
/**
2525
* Replaces default suffixes of executable.
26+
*
27+
* @param array $suffixes
2628
*/
2729
public function setSuffixes(array $suffixes)
2830
{
@@ -40,15 +42,40 @@ public function addSuffix($suffix)
4042
}
4143

4244
/**
43-
* Finds an executable by name.
45+
* Finds an executable by name in given directories.
4446
*
4547
* @param string $name The executable name (without the extension)
48+
* @param array $dirs Dirs to check into
4649
* @param string $default The default to return if no executable is found
47-
* @param array $extraDirs Additional dirs to check into
4850
*
4951
* @return string The executable path or default value
5052
*/
51-
public function find($name, $default = null, array $extraDirs = array())
53+
public function findIn($name, array $dirs = array(), $default = null)
54+
{
55+
$suffixes = array('');
56+
if ('\\' === DIRECTORY_SEPARATOR) {
57+
$pathExt = getenv('PATHEXT');
58+
$suffixes = array_merge($suffixes, $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes);
59+
}
60+
foreach ($suffixes as $suffix) {
61+
foreach ($dirs as $dir) {
62+
if (@is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
63+
return $file;
64+
}
65+
}
66+
}
67+
68+
return $default;
69+
}
70+
71+
/**
72+
* Returns the search path directories from environment
73+
*
74+
* @param array $extraDirs Additional dirs to check into
75+
*
76+
* @return string[] The search paths
77+
*/
78+
public function path(array $extraDirs = array())
5279
{
5380
if (ini_get('open_basedir')) {
5481
$searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
@@ -70,19 +97,24 @@ public function find($name, $default = null, array $extraDirs = array())
7097
);
7198
}
7299

73-
$suffixes = array('');
74-
if ('\\' === DIRECTORY_SEPARATOR) {
75-
$pathExt = getenv('PATHEXT');
76-
$suffixes = array_merge($suffixes, $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes);
77-
}
78-
foreach ($suffixes as $suffix) {
79-
foreach ($dirs as $dir) {
80-
if (@is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
81-
return $file;
82-
}
83-
}
84-
}
100+
return $dirs;
101+
}
85102

86-
return $default;
103+
/**
104+
* Finds an executable by name.
105+
*
106+
* @param string $name The executable name (without the extension)
107+
* @param string $default The default to return if no executable is found
108+
* @param array $extraDirs Additional dirs to check into
109+
*
110+
* @return string The executable path or default value
111+
*/
112+
public function find($name, $default = null, array $extraDirs = array())
113+
{
114+
return $this->findIn(
115+
$name,
116+
$this->path($extraDirs),
117+
$default
118+
);
87119
}
88120
}

src/Symfony/Component/Process/PhpExecutableFinder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ public function find($includeArgs = true)
6262
}
6363
}
6464

65-
$dirs = array(PHP_BINDIR);
65+
$php = $this->executableFinder->findIn('php', array(PHP_BINDIR));
66+
if ($php !== null) {
67+
return $php;
68+
}
69+
70+
$dirs = array();
6671
if ('\\' === DIRECTORY_SEPARATOR) {
6772
$dirs[] = 'C:\xampp\php\\';
6873
}

0 commit comments

Comments
 (0)