1
0
Fork 0

Add support for @php <abs path to binary from PATH>, fixes #9726

pull/9734/head
Jordi Boggiano 2021-03-09 10:38:46 +01:00
parent d0b399b788
commit bcd862c3dc
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 10 additions and 0 deletions

View File

@ -26,6 +26,7 @@ use Composer\Util\ProcessExecutor;
use Composer\Script\Event as ScriptEvent;
use Composer\ClassLoader;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\ExecutableFinder;
/**
* The Event Dispatcher.
@ -258,6 +259,15 @@ class EventDispatcher
return str_replace('/', '\\', $path[0]);
}, $pathAndArgs);
}
// match somename (not in quote, and not a qualified path) and if it is not a valid path from CWD then try to find it
// in $PATH. This allows support for `@php foo` where foo is a binary name found in PATH but not an actual relative path
preg_match('{^[^\'"\s/\\\\]+}', $pathAndArgs, $match);
if (!file_exists($match[0])) {
$finder = new ExecutableFinder;
if ($pathToExec = $finder->find($match[0])) {
$pathAndArgs = $pathToExec . substr($pathAndArgs, strlen($match[0]));
}
}
$exec = $this->getPhpExecCommand() . ' ' . $pathAndArgs;
} else {
$finder = new PhpExecutableFinder();