1
0
Fork 0

Cache versions data to avoid redownloading it twice during self-update

pull/9092/head
Jordi Boggiano 2020-07-30 15:43:28 +02:00
parent 7028d0ce27
commit 5bd61ac55c
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 17 additions and 7 deletions

View File

@ -26,6 +26,7 @@ class Versions
private $rfs; private $rfs;
private $config; private $config;
private $channel; private $channel;
private $versionsData;
public function __construct(Config $config, RemoteFilesystem $rfs) public function __construct(Config $config, RemoteFilesystem $rfs)
{ {
@ -63,13 +64,7 @@ class Versions
public function getLatest($channel = null) public function getLatest($channel = null)
{ {
if ($this->config->get('disable-tls') === true) { $versions = $this->getVersionsData();
$protocol = 'http';
} else {
$protocol = 'https';
}
$versions = JsonFile::parseJson($this->rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/versions', false));
foreach ($versions[$channel ?: $this->getChannel()] as $version) { foreach ($versions[$channel ?: $this->getChannel()] as $version) {
if ($version['min-php'] <= PHP_VERSION_ID) { if ($version['min-php'] <= PHP_VERSION_ID) {
@ -79,4 +74,19 @@ class Versions
throw new \LogicException('There is no version of Composer available for your PHP version ('.PHP_VERSION.')'); throw new \LogicException('There is no version of Composer available for your PHP version ('.PHP_VERSION.')');
} }
private function getVersionsData()
{
if (!$this->versionsData) {
if ($this->config->get('disable-tls') === true) {
$protocol = 'http';
} else {
$protocol = 'https';
}
$this->versionsData = JsonFile::parseJson($this->rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/versions', false));
}
return $this->versionsData;
}
} }