Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Factory.php

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

Composer

Code

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];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal