1
0
Fork 0

Improve support for XDG and default to XDG config dir if both that and ~/.composer are available, fixes #9045

pull/9056/head
Jordi Boggiano 2020-07-15 10:53:44 +02:00
parent 92ef439666
commit 10590dc519
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 25 additions and 6 deletions

View File

@ -5,6 +5,7 @@
- The new platform-check feature means that Composer checks the runtime PHP version and available extensions to ensure they match the project dependencies. If a mismatch is found, it exits with error details to make sure problems are not overlooked. To avoid issues when deploying to production it is recommended to run `composer check-platform-reqs` with the production PHP process as part of your build or deployment process.
- If a package exists in a higher priority repository, it will now be entirely ignored in lower priority repositories. See [repository priorities](https://getcomposer.org/repoprio) for details.
- Invalid PSR-0 / PSR-4 class configurations will not autoload anymore in optimized-autoloader mode, as per the warnings introduced in 1.10
- On linux systems supporting the XDG Base Directory Specification, Composer will now prefer using XDG_CONFIG_DIR/composer over ~/.composer if both are available (1.x used ~/.composer first)
- Package names now must comply to our [naming guidelines](doc/04-schema.md#name) or Composer will abort, as per the warnings introduced in 1.8.1
- Deprecated --no-suggest flag as it is not needed anymore
- PEAR support (repository, downloader, etc.) has been removed

View File

@ -69,18 +69,32 @@ class Factory
}
$userDir = self::getUserDir();
if (is_dir($userDir . '/.composer')) {
return $userDir . '/.composer';
}
$dirs = array();
if (self::useXdg()) {
// XDG Base Directory Specifications
$xdgConfig = getenv('XDG_CONFIG_HOME') ?: $userDir . '/.config';
$xdgConfig = getenv('XDG_CONFIG_HOME');
if (!$xdgConfig && is_dir('/etc/xdg')) {
$xdgConfig = '/etc/xdg';
}
if (!$xdgConfig) {
$xdgConfig = $userDir . '/.config';
}
return $xdgConfig . '/composer';
$dirs[] = $xdgConfig . '/composer';
}
return $userDir . '/.composer';
$dirs[] = $userDir . '/.composer';
// select first dir which exists of: $XDG_CONFIG_HOME/composer or ~/.composer
foreach ($dirs as $dir) {
if (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];
}
/**
@ -644,6 +658,10 @@ class Factory
}
}
if (is_dir('/etc/xdg')) {
return true;
}
return false;
}