diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index fa2b176f4..df2b41359 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -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 diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 8eb2d24cf..e0947b46a 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -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; }