function EventDispatcher::ensureBinDirIsInPath
1 call to EventDispatcher::ensureBinDirIsInPath()
- EventDispatcher::doDispatch in vendor/
composer/ composer/ src/ Composer/ EventDispatcher/ EventDispatcher.php - Triggers the listeners of an event.
File
-
vendor/
composer/ composer/ src/ Composer/ EventDispatcher/ EventDispatcher.php, line 654
Class
- EventDispatcher
- The Event Dispatcher.
Namespace
Composer\EventDispatcherCode
private function ensureBinDirIsInPath() : void {
$pathEnv = 'PATH';
// checking if only Path and not PATH is set then we probably need to update the Path env
// on Windows getenv is case-insensitive so we cannot check it via Platform::getEnv and
// we need to check in $_SERVER directly
if (!isset($_SERVER[$pathEnv]) && isset($_SERVER['Path'])) {
$pathEnv = 'Path';
}
// add the bin dir to the PATH to make local binaries of deps usable in scripts
$binDir = $this->composer
->getConfig()
->get('bin-dir');
if (is_dir($binDir)) {
$binDir = realpath($binDir);
$pathValue = (string) Platform::getEnv($pathEnv);
if (!Preg::isMatch('{(^|' . PATH_SEPARATOR . ')' . preg_quote($binDir) . '($|' . PATH_SEPARATOR . ')}', $pathValue)) {
Platform::putEnv($pathEnv, $binDir . PATH_SEPARATOR . $pathValue);
}
}
}