Cache versions data to avoid redownloading it twice during self-update
parent
7028d0ce27
commit
5bd61ac55c
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue