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

Breadcrumb

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

function Url::updateDistReference

Parameters

non-empty-string $url:

Return value

non-empty-string the updated URL

1 call to Url::updateDistReference()
FileDownloader::processUrl in vendor/composer/composer/src/Composer/Downloader/FileDownloader.php
Process the download url

File

vendor/composer/composer/src/Composer/Util/Url.php, line 27

Class

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

Namespace

Composer\Util

Code

public static function updateDistReference(Config $config, string $url, string $ref) : string {
    $host = parse_url($url, PHP_URL_HOST);
    if ($host === 'api.github.com' || $host === 'github.com' || $host === 'www.github.com') {
        if (Preg::isMatch('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) {
            // update legacy github archives to API calls with the proper reference
            $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $ref;
        }
        elseif (Preg::isMatch('{^https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/archive/.+\\.(zip|tar)(?:\\.gz)?$}i', $url, $match)) {
            // update current github web archives to API calls with the proper reference
            $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $ref;
        }
        elseif (Preg::isMatch('{^https?://api\\.github\\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i', $url, $match)) {
            // update api archives to the proper reference
            $url = 'https://api.github.com/repos/' . $match[1] . '/' . $match[2] . '/' . $match[3] . 'ball/' . $ref;
        }
    }
    elseif ($host === 'bitbucket.org' || $host === 'www.bitbucket.org') {
        if (Preg::isMatch('{^https?://(?:www\\.)?bitbucket\\.org/([^/]+)/([^/]+)/get/(.+)\\.(zip|tar\\.gz|tar\\.bz2)$}i', $url, $match)) {
            // update Bitbucket archives to the proper reference
            $url = 'https://bitbucket.org/' . $match[1] . '/' . $match[2] . '/get/' . $ref . '.' . $match[4];
        }
    }
    elseif ($host === 'gitlab.com' || $host === 'www.gitlab.com') {
        if (Preg::isMatch('{^https?://(?:www\\.)?gitlab\\.com/api/v[34]/projects/([^/]+)/repository/archive\\.(zip|tar\\.gz|tar\\.bz2|tar)\\?sha=.+$}i', $url, $match)) {
            // update Gitlab archives to the proper reference
            $url = 'https://gitlab.com/api/v4/projects/' . $match[1] . '/repository/archive.' . $match[2] . '?sha=' . $ref;
        }
    }
    elseif (in_array($host, $config->get('github-domains'), true)) {
        $url = Preg::replace('{(/repos/[^/]+/[^/]+/(zip|tar)ball)(?:/.+)?$}i', '$1/' . $ref, $url);
    }
    elseif (in_array($host, $config->get('gitlab-domains'), true)) {
        $url = Preg::replace('{(/api/v[34]/projects/[^/]+/repository/archive\\.(?:zip|tar\\.gz|tar\\.bz2|tar)\\?sha=).+$}i', '${1}' . $ref, $url);
    }
    assert($url !== '');
    return $url;
}

API Navigation

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