/** * Retrieve all available versions for a package * * @param string $package * @return array * @throws \RuntimeException */ private function getPackageAvailableVersions($package) { $magentoRepositories = $this->composerInformation->getRootRepositories(); // Check we have only one repo.magento.com repository if (count($magentoRepositories) === 1 && strpos($magentoRepositories[0], $this->packagesAuth->getCredentialBaseUrl())) { $packagesJsonData = $this->getPackagesJson(); if ($packagesJsonData) { $packagesJsonData = json_decode($packagesJsonData, true); } else { $packagesJsonData['packages'] = []; } if (isset($packagesJsonData['packages'][$package])) { $packageVersions = $packagesJsonData['packages'][$package]; uksort($packageVersions, 'version_compare'); $packageVersions = array_reverse($packageVersions); return array_keys($packageVersions); } } else { $versionsPattern = '/^versions\\s*\\:\\s(.+)$/m'; $commandParams = [self::PARAM_COMMAND => self::COMPOSER_SHOW, self::PARAM_PACKAGE => $package, self::PARAM_AVAILABLE => true]; $applicationFactory = $this->objectManagerProvider->get()->get('Magento\\Framework\\Composer\\MagentoComposerApplicationFactory'); /** @var \Magento\Composer\MagentoComposerApplication $application */ $application = $applicationFactory->create(); $result = $application->runComposerCommand($commandParams); $matches = []; preg_match($versionsPattern, $result, $matches); if (isset($matches[1])) { return explode(', ', $matches[1]); } } throw new \RuntimeException(sprintf('Couldn\'t get available versions for package %s', $package)); }