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

Breadcrumb

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

function Url::getOrigin

Parameters

non-empty-string $url:

Return value

non-empty-string

2 calls to Url::getOrigin()
CurlDownloader::restartJob in vendor/composer/composer/src/Composer/Util/Http/CurlDownloader.php
HttpDownloader::addJob in vendor/composer/composer/src/Composer/Util/HttpDownloader.php
@phpstan-param Request $request

File

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

Class

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

Namespace

Composer\Util

Code

public static function getOrigin(Config $config, string $url) : string {
    if (0 === strpos($url, 'file://')) {
        return $url;
    }
    $origin = (string) parse_url($url, PHP_URL_HOST);
    if ($port = parse_url($url, PHP_URL_PORT)) {
        $origin .= ':' . $port;
    }
    if (str_ends_with($origin, '.github.com') && $origin !== 'codeload.github.com') {
        return 'github.com';
    }
    if ($origin === 'repo.packagist.org') {
        return 'packagist.org';
    }
    if ($origin === '') {
        $origin = $url;
    }
    // Gitlab can be installed in a non-root context (i.e. gitlab.com/foo). When downloading archives the originUrl
    // is the host without the path, so we look for the registered gitlab-domains matching the host here
    if (false === strpos($origin, '/') && !in_array($origin, $config->get('gitlab-domains'), true)) {
        foreach ($config->get('gitlab-domains') as $gitlabDomain) {
            if ($gitlabDomain !== '' && str_starts_with($gitlabDomain, $origin)) {
                return $gitlabDomain;
            }
        }
    }
    return $origin;
}

API Navigation

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