function Factory::getHomeDir
Throws
\RuntimeException
1 call to Factory::getHomeDir()
- Factory::createConfig in vendor/
composer/ composer/ src/ Composer/ Factory.php
File
-
vendor/
composer/ composer/ src/ Composer/ Factory.php, line 58
Class
- Factory
- Creates a configured instance of composer.
Namespace
ComposerCode
protected static function getHomeDir() : string {
$home = Platform::getEnv('COMPOSER_HOME');
if ($home) {
return $home;
}
if (Platform::isWindows()) {
if (!Platform::getEnv('APPDATA')) {
throw new \RuntimeException('The APPDATA or COMPOSER_HOME environment variable must be set for composer to run correctly');
}
return rtrim(strtr(Platform::getEnv('APPDATA'), '\\', '/'), '/') . '/Composer';
}
$userDir = self::getUserDir();
$dirs = [];
if (self::useXdg()) {
// XDG Base Directory Specifications
$xdgConfig = Platform::getEnv('XDG_CONFIG_HOME');
if (!$xdgConfig) {
$xdgConfig = $userDir . '/.config';
}
$dirs[] = $xdgConfig . '/composer';
}
$dirs[] = $userDir . '/.composer';
// select first dir which exists of: $XDG_CONFIG_HOME/composer or ~/.composer
foreach ($dirs as $dir) {
if (Silencer::call('is_dir', $dir)) {
return $dir;
}
}
// if none exists, we default to first defined one (XDG one if system uses it, or ~/.composer otherwise)
return $dirs[0];
}