function ComposerRepository::fetchFileIfLastModified
Return value
array<mixed>|true
2 calls to ComposerRepository::fetchFileIfLastModified()
- ComposerRepository::loadRootServerFile in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php - ComposerRepository::whatProvides in vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php - @phpstan-param array<key-of<BasePackage::STABILITIES>, BasePackage::STABILITY_*>|null $acceptableStabilities
File
-
vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php, line 1564
Class
- ComposerRepository
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\RepositoryCode
private function fetchFileIfLastModified(string $filename, string $cacheKey, string $lastModifiedTime) {
if ('' === $filename) {
throw new \InvalidArgumentException('$filename should not be an empty string');
}
try {
$options = $this->options;
if ($this->eventDispatcher) {
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata', [
'repository' => $this,
]);
$preFileDownloadEvent->setTransportOptions($this->options);
$this->eventDispatcher
->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
$filename = $preFileDownloadEvent->getProcessedUrl();
$options = $preFileDownloadEvent->getTransportOptions();
}
if (isset($options['http']['header'])) {
$options['http']['header'] = (array) $options['http']['header'];
}
$options['http']['header'][] = 'If-Modified-Since: ' . $lastModifiedTime;
$response = $this->httpDownloader
->get($filename, $options);
$json = (string) $response->getBody();
if ($json === '' && $response->getStatusCode() === 304) {
return true;
}
if ($this->eventDispatcher) {
$postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, null, null, $filename, 'metadata', [
'response' => $response,
'repository' => $this,
]);
$this->eventDispatcher
->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent);
}
$data = $response->decodeJson();
HttpDownloader::outputWarnings($this->io, $this->url, $data);
$lastModifiedDate = $response->getHeader('last-modified');
$response->collect();
if ($lastModifiedDate) {
$data['last-modified'] = $lastModifiedDate;
$json = JsonFile::encode($data, 0);
}
if (!$this->cache
->isReadOnly()) {
$this->cache
->write($cacheKey, $json);
}
return $data;
} catch (\Exception $e) {
if ($e instanceof \LogicException) {
throw $e;
}
if ($e instanceof TransportException && $e->getStatusCode() === 404) {
throw $e;
}
if (!$this->degradedMode) {
$this->io
->writeError('<warning>' . $this->url . ' could not be fully loaded (' . $e->getMessage() . '), package information was loaded from the local cache and may be out of date</warning>');
}
$this->degradedMode = true;
return true;
}
}