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

Breadcrumb

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

class ComposerMirror

Composer mirror utilities

@author Jordi Boggiano <j.boggiano@seld.be>

Hierarchy

  • class \Composer\Util\ComposerMirror

Expanded class hierarchy of ComposerMirror

1 file declares its use of ComposerMirror
Package.php in vendor/composer/composer/src/Composer/Package/Package.php

File

vendor/composer/composer/src/Composer/Util/ComposerMirror.php, line 22

Namespace

Composer\Util
View source
class ComposerMirror {
    
    /**
     * @param non-empty-string $mirrorUrl
     * @return non-empty-string
     */
    public static function processUrl(string $mirrorUrl, string $packageName, string $version, ?string $reference, ?string $type, ?string $prettyVersion = null) : string {
        if ($reference) {
            $reference = Preg::isMatch('{^([a-f0-9]*|%reference%)$}', $reference) ? $reference : hash('md5', $reference);
        }
        $version = strpos($version, '/') === false ? $version : hash('md5', $version);
        $from = [
            '%package%',
            '%version%',
            '%reference%',
            '%type%',
        ];
        $to = [
            $packageName,
            $version,
            $reference,
            $type,
        ];
        if (null !== $prettyVersion) {
            $from[] = '%prettyVersion%';
            $to[] = $prettyVersion;
        }
        $url = str_replace($from, $to, $mirrorUrl);
        assert($url !== '');
        return $url;
    }
    
    /**
     * @param non-empty-string $mirrorUrl
     * @return string
     */
    public static function processGitUrl(string $mirrorUrl, string $packageName, string $url, ?string $type) : string {
        if (Preg::isMatch('#^(?:(?:https?|git)://github\\.com/|git@github\\.com:)([^/]+)/(.+?)(?:\\.git)?$#', $url, $match)) {
            $url = 'gh-' . $match[1] . '/' . $match[2];
        }
        elseif (Preg::isMatch('#^https://bitbucket\\.org/([^/]+)/(.+?)(?:\\.git)?/?$#', $url, $match)) {
            $url = 'bb-' . $match[1] . '/' . $match[2];
        }
        else {
            $url = Preg::replace('{[^a-z0-9_.-]}i', '-', trim($url, '/'));
        }
        return str_replace([
            '%package%',
            '%normalizedUrl%',
            '%type%',
        ], [
            $packageName,
            $url,
            $type,
        ], $mirrorUrl);
    }
    
    /**
     * @param non-empty-string $mirrorUrl
     * @return string
     */
    public static function processHgUrl(string $mirrorUrl, string $packageName, string $url, string $type) : string {
        return self::processGitUrl($mirrorUrl, $packageName, $url, $type);
    }

}

Members

Title Sort descending Modifiers Object type Summary
ComposerMirror::processGitUrl public static function
ComposerMirror::processHgUrl public static function
ComposerMirror::processUrl public static function
RSS feed
Powered by Drupal