diff --git a/src/Composer/SelfUpdate/Versions.php b/src/Composer/SelfUpdate/Versions.php index 6a0a1bdbf..c2c54e984 100644 --- a/src/Composer/SelfUpdate/Versions.php +++ b/src/Composer/SelfUpdate/Versions.php @@ -26,6 +26,7 @@ class Versions private $rfs; private $config; private $channel; + private $versionsData; public function __construct(Config $config, RemoteFilesystem $rfs) { @@ -63,13 +64,7 @@ class Versions public function getLatest($channel = null) { - if ($this->config->get('disable-tls') === true) { - $protocol = 'http'; - } else { - $protocol = 'https'; - } - - $versions = JsonFile::parseJson($this->rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/versions', false)); + $versions = $this->getVersionsData(); foreach ($versions[$channel ?: $this->getChannel()] as $version) { 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.')'); } + + 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; + } }