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\UtilCode
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;
}