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

Breadcrumb

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

function Platform::expandPath

Parses tildes and environment variables in paths.

4 calls to Platform::expandPath()
ArtifactRepository::__construct in vendor/composer/composer/src/Composer/Repository/ArtifactRepository.php
Config::get in vendor/composer/composer/src/Composer/Config.php
Returns a setting
PathRepository::__construct in vendor/composer/composer/src/Composer/Repository/PathRepository.php
Initializes path repository.
VcsRepository::__construct in vendor/composer/composer/src/Composer/Repository/VcsRepository.php

File

vendor/composer/composer/src/Composer/Util/Platform.php, line 110

Class

Platform
Platform helper for uniform platform-specific tests.

Namespace

Composer\Util

Code

public static function expandPath(string $path) : string {
    if (Preg::isMatch('#^~[\\/]#', $path)) {
        return self::getUserDirectory() . substr($path, 1);
    }
    return Preg::replaceCallback('#^(\\$|(?P<percent>%))(?P<var>\\w++)(?(percent)%)(?P<path>.*)#', static function ($matches) : string {
        // Treat HOME as an alias for USERPROFILE on Windows for legacy reasons
        if (Platform::isWindows() && $matches['var'] === 'HOME') {
            if ((bool) Platform::getEnv('HOME')) {
                return Platform::getEnv('HOME') . $matches['path'];
            }
            return Platform::getEnv('USERPROFILE') . $matches['path'];
        }
        return Platform::getEnv($matches['var']) . $matches['path'];
    }, $path);
}

API Navigation

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