function ComposerRepository::loadRootServerFile
Return value
array<'providers'|'provider-includes'|'packages'|'providers-url'|'notify-batch'|'search'|'mirrors'|'providers-lazy-url'|'metadata-url'|'available-packages'|'available-package-patterns', mixed>|true
10 calls to ComposerRepository::loadRootServerFile()
- ComposerRepository::getProviderNames in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php - ComposerRepository::getProviders in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php - @inheritDoc
- ComposerRepository::getSecurityAdvisories in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php - @inheritDoc
- ComposerRepository::hasProviders in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php - ComposerRepository::hasSecurityAdvisories in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php
File
-
vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php, line 1173
Class
- ComposerRepository
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\RepositoryCode
protected function loadRootServerFile(?int $rootMaxAge = null) {
if (null !== $this->rootData) {
return $this->rootData;
}
if (!extension_loaded('openssl') && strpos($this->url, 'https') === 0) {
throw new \RuntimeException('You must enable the openssl extension in your php.ini to load information from ' . $this->url);
}
if ($cachedData = $this->cache
->read('packages.json')) {
$cachedData = json_decode($cachedData, true);
if ($rootMaxAge !== null && ($age = $this->cache
->getAge('packages.json')) !== false && $age <= $rootMaxAge) {
$data = $cachedData;
}
elseif (isset($cachedData['last-modified'])) {
$response = $this->fetchFileIfLastModified($this->getPackagesJsonUrl(), 'packages.json', $cachedData['last-modified']);
$data = true === $response ? $cachedData : $response;
}
}
if (!isset($data)) {
$data = $this->fetchFile($this->getPackagesJsonUrl(), 'packages.json', null, true);
}
if (!empty($data['notify-batch'])) {
$this->notifyUrl = $this->canonicalizeUrl($data['notify-batch']);
}
elseif (!empty($data['notify'])) {
$this->notifyUrl = $this->canonicalizeUrl($data['notify']);
}
if (!empty($data['search'])) {
$this->searchUrl = $this->canonicalizeUrl($data['search']);
}
if (!empty($data['mirrors'])) {
foreach ($data['mirrors'] as $mirror) {
if (!empty($mirror['git-url'])) {
$this->sourceMirrors['git'][] = [
'url' => $mirror['git-url'],
'preferred' => !empty($mirror['preferred']),
];
}
if (!empty($mirror['hg-url'])) {
$this->sourceMirrors['hg'][] = [
'url' => $mirror['hg-url'],
'preferred' => !empty($mirror['preferred']),
];
}
if (!empty($mirror['dist-url'])) {
$this->distMirrors[] = [
'url' => $this->canonicalizeUrl($mirror['dist-url']),
'preferred' => !empty($mirror['preferred']),
];
}
}
}
if (!empty($data['providers-lazy-url'])) {
$this->lazyProvidersUrl = $this->canonicalizeUrl($data['providers-lazy-url']);
$this->hasProviders = true;
$this->hasPartialPackages = !empty($data['packages']) && is_array($data['packages']);
}
// metadata-url indicates V2 repo protocol so it takes over from all the V1 types
// V2 only has lazyProviders and possibly partial packages, but no ability to process anything else,
// V2 also supports async loading
if (!empty($data['metadata-url'])) {
$this->lazyProvidersUrl = $this->canonicalizeUrl($data['metadata-url']);
$this->providersUrl = null;
$this->hasProviders = false;
$this->hasPartialPackages = !empty($data['packages']) && is_array($data['packages']);
$this->allowSslDowngrade = false;
// provides a list of package names that are available in this repo
// this disables lazy-provider behavior in the sense that if a list is available we assume it is finite and won't search for other packages in that repo
// while if no list is there lazyProvidersUrl is used when looking for any package name to see if the repo knows it
if (!empty($data['available-packages'])) {
$availPackages = array_map('strtolower', $data['available-packages']);
$this->availablePackages = array_combine($availPackages, $availPackages);
$this->hasAvailablePackageList = true;
}
// Provides a list of package name patterns (using * wildcards to match any substring, e.g. "vendor/*") that are available in this repo
// Disables lazy-provider behavior as with available-packages, but may allow much more compact expression of packages covered by this repository.
// Over-specifying covered packages is safe, but may result in increased traffic to your repository.
if (!empty($data['available-package-patterns'])) {
$this->availablePackagePatterns = array_map(static function ($pattern) : string {
return BasePackage::packageNameToRegexp($pattern);
}, $data['available-package-patterns']);
$this->hasAvailablePackageList = true;
}
// Remove legacy keys as most repos need to be compatible with Composer v1
// as well but we are not interested in the old format anymore at this point
unset($data['providers-url'], $data['providers'], $data['providers-includes']);
if (isset($data['security-advisories']) && is_array($data['security-advisories'])) {
$this->securityAdvisoryConfig = [
'metadata' => $data['security-advisories']['metadata'] ?? false,
'api-url' => isset($data['security-advisories']['api-url']) && is_string($data['security-advisories']['api-url']) ? $this->canonicalizeUrl($data['security-advisories']['api-url']) : null,
];
if ($this->securityAdvisoryConfig['api-url'] === null && !$this->hasAvailablePackageList) {
throw new \UnexpectedValueException('Invalid security advisory configuration on ' . $this->getRepoName() . ': If the repository does not provide a security-advisories.api-url then available-packages or available-package-patterns are required to be provided for performance reason.');
}
}
}
if ($this->allowSslDowngrade) {
$this->url = str_replace('https://', 'http://', $this->url);
$this->baseUrl = str_replace('https://', 'http://', $this->baseUrl);
}
if (!empty($data['providers-url'])) {
$this->providersUrl = $this->canonicalizeUrl($data['providers-url']);
$this->hasProviders = true;
}
if (!empty($data['list'])) {
$this->listUrl = $this->canonicalizeUrl($data['list']);
}
if (!empty($data['providers']) || !empty($data['providers-includes'])) {
$this->hasProviders = true;
}
if (!empty($data['providers-api'])) {
$this->providersApiUrl = $this->canonicalizeUrl($data['providers-api']);
}
return $this->rootData = $data;
}