diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index eecf859d2..50da29b7c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,13 +19,8 @@ jobs: fail-fast: false matrix: include: - - php: '7.1' - - php: '7.2' - - php: '7.3' - - php: '7.4' - php: '8.0' - php: '8.1' - - php: '7.4' mode: low-deps steps: @@ -42,9 +37,8 @@ jobs: - name: "Validate composer.json" run: "composer validate --strict --no-check-lock" - - run: | - composer require --no-update composer/composer:^1.0.2 --ansi - + - name: "Install dependencies" + run: | if [[ "${{ matrix.mode }}" = low-deps ]]; then composer u --prefer-lowest --prefer-stable --ansi else @@ -56,17 +50,6 @@ jobs: - run: vendor/bin/simple-phpunit - - run: | - composer require --no-update composer/composer:^2 --ansi - - if [[ "${{ matrix.mode }}" = low-deps ]]; then - composer u --prefer-lowest --prefer-stable --ansi - else - composer u --ansi - fi - - - run: vendor/bin/simple-phpunit - - - if: matrix.php == '7.1' + - if: matrix.php == '8.0' name: "Lint PHP files" run: find src/ -name '*.php' | xargs -n1 php -l diff --git a/composer.json b/composer.json index 0e1e7c3b2..fc229bac3 100644 --- a/composer.json +++ b/composer.json @@ -11,25 +11,28 @@ ], "minimum-stability": "dev", "require": { - "php": ">=7.1", - "composer-plugin-api": "^1.0|^2.0" + "php": ">=8.0", + "composer-plugin-api": "^2.1" }, "require-dev": { - "composer/composer": "^1.0.2|^2.0", - "symfony/dotenv": "^4.4|^5.0|^6.0", - "symfony/filesystem": "^4.4|^5.0|^6.0", - "symfony/phpunit-bridge": "^4.4.12|^5.0|^6.0", - "symfony/process": "^4.4|^5.0|^6.0" + "composer/composer": "^2.1", + "symfony/dotenv": "^5.4|^6.0", + "symfony/filesystem": "^5.4|^6.0", + "symfony/phpunit-bridge": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0" }, "autoload": { "psr-4": { "Symfony\\Flex\\": "src" } }, + "replace": { + "symfony/polyfill-php72": "*", + "symfony/polyfill-php73": "*", + "symfony/polyfill-php74": "*", + "symfony/polyfill-php80": "*" + }, "extra": { - "branch-alias": { - "dev-main": "1.17-dev" - }, "class": "Symfony\\Flex\\Flex" } } diff --git a/src/Cache.php b/src/Cache.php deleted file mode 100644 index d1c00248d..000000000 --- a/src/Cache.php +++ /dev/null @@ -1,158 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Flex; - -use Composer\Cache as BaseCache; -use Composer\IO\IOInterface; -use Composer\Package\RootPackageInterface; -use Composer\Semver\Constraint\Constraint; -use Composer\Semver\VersionParser; - -/** - * @author Nicolas Grekas
- */
-class Cache extends BaseCache
-{
- private $versions;
- private $versionParser;
- private $symfonyRequire;
- private $rootConstraints = [];
- private $symfonyConstraints;
- private $downloader;
- private $io;
-
- public function setSymfonyRequire(string $symfonyRequire, RootPackageInterface $rootPackage, Downloader $downloader, IOInterface $io = null)
- {
- $this->versionParser = new VersionParser();
- $this->symfonyRequire = $symfonyRequire;
- $this->symfonyConstraints = $this->versionParser->parseConstraints($symfonyRequire);
- $this->downloader = $downloader;
- $this->io = $io;
-
- foreach ($rootPackage->getRequires() + $rootPackage->getDevRequires() as $name => $link) {
- $this->rootConstraints[$name] = $link->getConstraint();
- }
- }
-
- public function read($file)
- {
- $content = parent::read($file);
-
- if (0 === strpos($file, 'provider-symfony$') && \is_array($data = json_decode($content, true))) {
- $content = json_encode($this->removeLegacyTags($data));
- }
-
- return $content;
- }
-
- public function removeLegacyTags(array $data): array
- {
- if (!$this->symfonyConstraints || !isset($data['packages'])) {
- return $data;
- }
-
- foreach ($data['packages'] as $name => $versions) {
- if (!isset($this->getVersions()['splits'][$name])) {
- continue;
- }
-
- $rootConstraint = $this->rootConstraints[$name] ?? null;
- $rootVersions = [];
-
- foreach ($versions as $version => $composerJson) {
- if (null !== $alias = $composerJson['extra']['branch-alias'][$version] ?? null) {
- $normalizedVersion = $this->versionParser->normalize($alias);
- } elseif (null === $normalizedVersion = $composerJson['version_normalized'] ?? null) {
- continue;
- }
-
- $constraint = new Constraint('==', $normalizedVersion);
-
- if ($rootConstraint && $rootConstraint->matches($constraint)) {
- $rootVersions[$version] = $composerJson;
- }
-
- if (!$this->symfonyConstraints->matches($constraint)) {
- if (null !== $this->io) {
- $this->io->writeError(sprintf('
- */
-class ComposerRepository extends BaseComposerRepository
-{
- private $providerFiles;
-
- protected function loadProviderListings($data)
- {
- if (null !== $this->providerFiles) {
- parent::loadProviderListings($data);
-
- return;
- }
-
- $data = [$data];
-
- while ($data) {
- $this->providerFiles = [];
- foreach ($data as $data) {
- $this->loadProviderListings($data);
- }
-
- $loadingFiles = $this->providerFiles;
- $this->providerFiles = null;
- $data = [];
- $this->rfs->download($loadingFiles, function (...$args) use (&$data) {
- $data[] = $this->fetchFile(...$args);
- });
- }
- }
-
- protected function fetchFile($filename, $cacheKey = null, $sha256 = null, $storeLastModifiedTime = false)
- {
- if (null !== $this->providerFiles) {
- $this->providerFiles[] = [$filename, $cacheKey, $sha256, $storeLastModifiedTime];
-
- return [];
- }
-
- return parent::fetchFile($filename, $cacheKey, $sha256, $storeLastModifiedTime);
- }
-}
diff --git a/src/CurlDownloader.php b/src/CurlDownloader.php
deleted file mode 100644
index 9da133311..000000000
--- a/src/CurlDownloader.php
+++ /dev/null
@@ -1,216 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Flex;
-
-use Composer\Downloader\TransportException;
-
-/**
- * @author Nicolas Grekas
- */
-class CurlDownloader
-{
- private $multiHandle;
- private $shareHandle;
- private $jobs = [];
- private $exceptions = [];
-
- private static $options = [
- 'http' => [
- 'method' => \CURLOPT_CUSTOMREQUEST,
- 'content' => \CURLOPT_POSTFIELDS,
- ],
- 'ssl' => [
- 'cafile' => \CURLOPT_CAINFO,
- 'capath' => \CURLOPT_CAPATH,
- ],
- ];
-
- private static $timeInfo = [
- 'total_time' => true,
- 'namelookup_time' => true,
- 'connect_time' => true,
- 'pretransfer_time' => true,
- 'starttransfer_time' => true,
- 'redirect_time' => true,
- ];
-
- public function __construct()
- {
- $this->multiHandle = $mh = curl_multi_init();
- curl_multi_setopt($mh, \CURLMOPT_PIPELINING, /*CURLPIPE_MULTIPLEX*/ 2);
- if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) {
- curl_multi_setopt($mh, \CURLMOPT_MAX_HOST_CONNECTIONS, 8);
- }
-
- $this->shareHandle = $sh = curl_share_init();
- curl_share_setopt($sh, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_COOKIE);
- curl_share_setopt($sh, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_DNS);
- curl_share_setopt($sh, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_SSL_SESSION);
- }
-
- public function get($origin, $url, $context, $file)
- {
- $params = stream_context_get_params($context);
-
- $ch = curl_init();
- $hd = fopen('php://temp/maxmemory:32768', 'w+b');
- if ($file && !$fd = @fopen($file.'~', 'w+b')) {
- $file = null;
- }
- if (!$file) {
- $fd = @fopen('php://temp/maxmemory:524288', 'w+b');
- }
- $headers = array_diff($params['options']['http']['header'], ['Connection: close']);
-
- if (!isset($params['options']['http']['protocol_version'])) {
- curl_setopt($ch, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_0);
- } else {
- $headers[] = 'Connection: keep-alive';
- if (0 === strpos($url, 'https://') && \defined('CURL_VERSION_HTTP2') && \defined('CURL_HTTP_VERSION_2_0') && (\CURL_VERSION_HTTP2 & curl_version()['features'])) {
- curl_setopt($ch, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_2_0);
- }
- }
-
- curl_setopt($ch, \CURLOPT_URL, $url);
- curl_setopt($ch, \CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, \CURLOPT_DNS_USE_GLOBAL_CACHE, false);
- curl_setopt($ch, \CURLOPT_WRITEHEADER, $hd);
- curl_setopt($ch, \CURLOPT_FILE, $fd);
- curl_setopt($ch, \CURLOPT_SHARE, $this->shareHandle);
-
- foreach (self::$options as $type => $options) {
- foreach ($options as $name => $curlopt) {
- if (isset($params['options'][$type][$name])) {
- curl_setopt($ch, $curlopt, $params['options'][$type][$name]);
- }
- }
- }
-
- $progress = array_diff_key(curl_getinfo($ch), self::$timeInfo);
- $this->jobs[(int) $ch] = [
- 'progress' => $progress,
- 'ch' => $ch,
- 'callback' => $params['notification'],
- 'file' => $file,
- 'fd' => $fd,
- ];
-
- curl_multi_add_handle($this->multiHandle, $ch);
- $params['notification'](\STREAM_NOTIFY_RESOLVE, \STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, 0, false);
- $active = true;
-
- try {
- while ($active && isset($this->jobs[(int) $ch])) {
- curl_multi_exec($this->multiHandle, $active);
- curl_multi_select($this->multiHandle);
-
- while ($progress = curl_multi_info_read($this->multiHandle)) {
- if (!isset($this->jobs[$i = (int) $h = $progress['handle']])) {
- continue;
- }
- $progress = array_diff_key(curl_getinfo($h), self::$timeInfo);
- $job = $this->jobs[$i];
- unset($this->jobs[$i]);
- curl_multi_remove_handle($this->multiHandle, $h);
- try {
- $this->onProgress($h, $job['callback'], $progress, $job['progress']);
-
- if ('' !== curl_error($h)) {
- throw new TransportException(curl_error($h));
- }
- if ($job['file'] && \CURLE_OK === curl_errno($h) && !isset($this->exceptions[$i])) {
- fclose($job['fd']);
- rename($job['file'].'~', $job['file']);
- }
- } catch (TransportException $e) {
- $this->exceptions[$i] = $e;
- }
- }
-
- foreach ($this->jobs as $i => $h) {
- if (!isset($this->jobs[$i])) {
- continue;
- }
- $h = $this->jobs[$i]['ch'];
- $progress = array_diff_key(curl_getinfo($h), self::$timeInfo);
-
- if ($this->jobs[$i]['progress'] !== $progress) {
- $previousProgress = $this->jobs[$i]['progress'];
- $this->jobs[$i]['progress'] = $progress;
- try {
- $this->onProgress($h, $this->jobs[$i]['callback'], $progress, $previousProgress);
- } catch (TransportException $e) {
- unset($this->jobs[$i]);
- curl_multi_remove_handle($this->multiHandle, $h);
- $this->exceptions[$i] = $e;
- }
- }
- }
- }
-
- if ('' !== curl_error($ch) || \CURLE_OK !== curl_errno($ch)) {
- $this->exceptions[(int) $ch] = new TransportException(curl_error($ch), curl_getinfo($ch, \CURLINFO_HTTP_CODE) ?: 0);
- }
- if (isset($this->exceptions[(int) $ch])) {
- throw $this->exceptions[(int) $ch];
- }
- } finally {
- if ($file && !isset($this->exceptions[(int) $ch])) {
- $fd = fopen($file, 'rb');
- }
- $progress = array_diff_key(curl_getinfo($ch), self::$timeInfo);
- $this->finishProgress($ch, $params['notification'], $progress);
- unset($this->jobs[(int) $ch], $this->exceptions[(int) $ch]);
- curl_multi_remove_handle($this->multiHandle, $ch);
- curl_close($ch);
-
- rewind($hd);
- $headers = explode("\r\n", rtrim(stream_get_contents($hd)));
- fclose($hd);
-
- rewind($fd);
- $contents = stream_get_contents($fd);
- fclose($fd);
- }
-
- return [$headers, $contents];
- }
-
- private function onProgress($ch, callable $notify, array $progress, array $previousProgress)
- {
- if (300 <= $progress['http_code'] && $progress['http_code'] < 400 || 0 > $progress['download_content_length']) {
- return;
- }
-
- if (!$previousProgress['http_code'] && $progress['http_code'] && $progress['http_code'] < 200 || 400 <= $progress['http_code']) {
- $code = 403 === $progress['http_code'] ? \STREAM_NOTIFY_AUTH_RESULT : \STREAM_NOTIFY_FAILURE;
- $notify($code, \STREAM_NOTIFY_SEVERITY_ERR, curl_error($ch), $progress['http_code'], 0, 0, false);
- }
-
- if ($previousProgress['download_content_length'] < $progress['download_content_length']) {
- $notify(\STREAM_NOTIFY_FILE_SIZE_IS, \STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, (int) $progress['download_content_length'], false);
- }
-
- if ($previousProgress['size_download'] < $progress['size_download']) {
- $notify(\STREAM_NOTIFY_PROGRESS, \STREAM_NOTIFY_SEVERITY_INFO, '', 0, (int) $progress['size_download'], (int) $progress['download_content_length'], false);
- }
- }
-
- private function finishProgress($ch, callable $notify, array $progress)
- {
- if ($progress['download_content_length'] < 0) {
- $notify(\STREAM_NOTIFY_FILE_SIZE_IS, \STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, (int) $progress['size_download'], false);
- $notify(\STREAM_NOTIFY_PROGRESS, \STREAM_NOTIFY_SEVERITY_INFO, '', 0, (int) $progress['size_download'], (int) $progress['size_download'], false);
- }
- }
-}
diff --git a/src/Downloader.php b/src/Downloader.php
index 919d68bb2..a6aeb0167 100644
--- a/src/Downloader.php
+++ b/src/Downloader.php
@@ -11,7 +11,7 @@
namespace Symfony\Flex;
-use Composer\Cache as ComposerCache;
+use Composer\Cache;
use Composer\Composer;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\DependencyResolver\Operation\UninstallOperation;
@@ -41,8 +41,7 @@ class Downloader
private $sess;
private $cache;
- /** @var HttpDownloader|ParallelDownloader */
- private $rfs;
+ private HttpDownloader $rfs;
private $degradedMode = false;
private $endpoints;
private $index;
@@ -50,7 +49,7 @@ class Downloader
private $caFile;
private $enabled = true;
- public function __construct(Composer $composer, IoInterface $io, $rfs)
+ public function __construct(Composer $composer, IoInterface $io, HttpDownloader $rfs)
{
if (getenv('SYMFONY_CAFILE')) {
$this->caFile = getenv('SYMFONY_CAFILE');
@@ -89,7 +88,7 @@ public function __construct(Composer $composer, IoInterface $io, $rfs)
$this->io = $io;
$config = $composer->getConfig();
$this->rfs = $rfs;
- $this->cache = new ComposerCache($io, $config->get('cache-repo-dir').'/flex');
+ $this->cache = new Cache($io, $config->get('cache-repo-dir').'/flex');
$this->sess = bin2hex(random_bytes(16));
}
@@ -98,11 +97,6 @@ public function getSessionId(): string
return $this->sess;
}
- public function setFlexId(string $id = null)
- {
- // No-op to support downgrading to v1.12.x
- }
-
public function isEnabled()
{
return $this->enabled;
@@ -294,37 +288,19 @@ private function get(array $urls, bool $isRecipe = false, int $try = 3): array
$options[$url] = $this->getOptions($headers);
}
- if ($this->rfs instanceof HttpDownloader) {
- $loop = new Loop($this->rfs);
- $jobs = [];
- foreach ($urls as $url) {
- $jobs[] = $this->rfs->add($url, $options[$url])->then(function (ComposerResponse $response) use ($url, &$responses) {
- if (200 === $response->getStatusCode()) {
- $cacheKey = self::generateCacheKey($url);
- $responses[$url] = $this->parseJson($response->getBody(), $url, $cacheKey, $response->getHeaders())->getBody();
- }
- }, function (\Exception $e) use ($url, &$retries) {
- $retries[] = [$url, $e];
- });
- }
- $loop->wait($jobs);
- } else {
- foreach ($urls as $i => $url) {
- $urls[$i] = [$url];
- }
- $this->rfs->download($urls, function ($url) use ($options, &$responses, &$retries, &$error) {
- try {
+ $loop = new Loop($this->rfs);
+ $jobs = [];
+ foreach ($urls as $url) {
+ $jobs[] = $this->rfs->add($url, $options[$url])->then(function (ComposerResponse $response) use ($url, &$responses) {
+ if (200 === $response->getStatusCode()) {
$cacheKey = self::generateCacheKey($url);
- $origin = method_exists($this->rfs, 'getOrigin') ? $this->rfs::getOrigin($url) : parse_url($url, \PHP_URL_HOST);
- $json = $this->rfs->getContents($origin, $url, false, $options[$url]);
- if (200 === $this->rfs->findStatusCode($this->rfs->getLastHeaders())) {
- $responses[$url] = $this->parseJson($json, $url, $cacheKey, $this->rfs->getLastHeaders())->getBody();
- }
- } catch (\Exception $e) {
- $retries[] = [$url, $e];
+ $responses[$url] = $this->parseJson($response->getBody(), $url, $cacheKey, $response->getHeaders())->getBody();
}
+ }, function (\Exception $e) use ($url, &$retries) {
+ $retries[] = [$url, $e];
});
}
+ $loop->wait($jobs);
if (!$retries) {
return $responses;
diff --git a/src/Flex.php b/src/Flex.php
index 0d6913916..7789463c8 100644
--- a/src/Flex.php
+++ b/src/Flex.php
@@ -17,13 +17,9 @@
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
-use Composer\DependencyResolver\Pool;
-use Composer\Downloader\FileDownloader;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Factory;
use Composer\Installer;
-use Composer\Installer\InstallerEvent;
-use Composer\Installer\InstallerEvents;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\Installer\SuggestedPackagesReporter;
@@ -32,16 +28,10 @@
use Composer\Json\JsonFile;
use Composer\Json\JsonManipulator;
use Composer\Package\BasePackage;
-use Composer\Package\Comparer\Comparer;
use Composer\Package\Locker;
-use Composer\Package\PackageInterface;
use Composer\Plugin\PluginEvents;
use Composer\Plugin\PluginInterface;
-use Composer\Plugin\PreFileDownloadEvent;
use Composer\Plugin\PrePoolCreateEvent;
-use Composer\Repository\ComposerRepository as BaseComposerRepository;
-use Composer\Repository\RepositoryFactory;
-use Composer\Repository\RepositoryManager;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Symfony\Component\Console\Input\ArgvInput;
@@ -78,19 +68,9 @@ class Flex implements PluginInterface, EventSubscriberInterface
private $postInstallOutput = [''];
private $operations = [];
private $lock;
- private $cacheDirPopulated = false;
private $displayThanksReminder = 0;
- private $rfs;
- private $progress = true;
private $dryRun = false;
private static $activated = true;
- private static $repoReadingCommands = [
- 'create-project' => true,
- 'outdated' => true,
- 'require' => true,
- 'update' => true,
- 'install' => true,
- ];
private static $aliasResolveCommands = [
'require' => true,
'update' => false,
@@ -123,40 +103,12 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
$symfonyRequire = preg_replace('/\.x$/', '.x-dev', getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? ''));
- if ($composer2 = version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '<=')) {
- $rfs = Factory::createHttpDownloader($this->io, $this->config);
+ $rfs = Factory::createHttpDownloader($this->io, $this->config);
- $this->downloader = $downloader = new Downloader($composer, $io, $rfs);
-
- if ($symfonyRequire) {
- $this->filter = new PackageFilter($io, $symfonyRequire, $this->downloader);
- }
+ $this->downloader = $downloader = new Downloader($composer, $io, $rfs);
- $setRepositories = null;
- } else {
- $rfs = Factory::createRemoteFilesystem($this->io, $this->config);
- $this->rfs = $rfs = new ParallelDownloader($this->io, $this->config, $rfs->getOptions(), $rfs->isTlsDisabled());
-
- $this->downloader = $downloader = new Downloader($composer, $io, $this->rfs);
-
- $rootPackage = $composer->getPackage();
- $manager = RepositoryFactory::manager($this->io, $this->config, $composer->getEventDispatcher(), $this->rfs);
- $setRepositories = \Closure::bind(function (RepositoryManager $manager) use (&$symfonyRequire, $rootPackage, $downloader) {
- $manager->repositoryClasses = $this->repositoryClasses;
- $manager->setRepositoryClass('composer', TruncatedComposerRepository::class);
- $manager->repositories = $this->repositories;
- $i = 0;
- foreach (RepositoryFactory::defaultRepos(null, $this->config, $manager) as $repo) {
- $manager->repositories[$i++] = $repo;
- if ($repo instanceof TruncatedComposerRepository && $symfonyRequire) {
- $repo->setSymfonyRequire($symfonyRequire, $rootPackage, $downloader, $this->io);
- }
- }
- $manager->setLocalRepository($this->getLocalRepository());
- }, $composer->getRepositoryManager(), RepositoryManager::class);
-
- $setRepositories($manager);
- $composer->setRepositoryManager($manager);
+ if ($symfonyRequire) {
+ $this->filter = new PackageFilter($io, $symfonyRequire, $this->downloader);
}
$this->configurator = new Configurator($composer, $io, $this->options);
@@ -174,21 +126,6 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
$downloader->disable();
}
- $populateRepoCacheDir = !$composer2 && __CLASS__ === self::class;
- if (!$composer2 && $composer->getPluginManager()) {
- foreach ($composer->getPluginManager()->getPlugins() as $plugin) {
- if (0 === strpos(\get_class($plugin), 'Hirak\Prestissimo\Plugin')) {
- if (method_exists($rfs, 'getRemoteContents')) {
- $plugin->disable();
- } else {
- $this->cacheDirPopulated = true;
- }
- $populateRepoCacheDir = false;
- break;
- }
- }
- }
-
$backtrace = $this->configureInstaller();
foreach ($backtrace as $trace) {
@@ -207,12 +144,6 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
$resolver = new PackageResolver($this->downloader);
- if (version_compare('1.1.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
- $note = $app->has('self-update') ? sprintf('`php %s self-update`', $_SERVER['argv'][0]) : 'https://getcomposer.org/';
- $io->writeError('
- */
-class ParallelDownloader extends RemoteFilesystem
-{
- private $io;
- private $downloader;
- private $quiet = true;
- private $progress = true;
- private $nextCallback;
- private $downloadCount;
- private $nextOptions = [];
- private $sharedState;
- private $fileName;
- private $lastHeaders;
-
- public static $cacheNext = false;
- protected static $cache = [];
-
- public function __construct(IOInterface $io, Config $config, array $options = [], $disableTls = false)
- {
- $this->io = $io;
- if (!method_exists(parent::class, 'getRemoteContents')) {
- $this->io->writeError('Composer >=1.7 not found, downloads will happen in sequence', true, IOInterface::DEBUG);
- } elseif (!\extension_loaded('curl')) {
- $this->io->writeError('ext-curl not found, downloads will happen in sequence', true, IOInterface::DEBUG);
- } else {
- $this->downloader = new CurlDownloader();
- }
- parent::__construct($io, $config, $options, $disableTls);
- }
-
- public function download(array &$nextArgs, callable $nextCallback, bool $quiet = true, bool $progress = true)
- {
- $previousState = [$this->quiet, $this->progress, $this->downloadCount, $this->nextCallback, $this->sharedState];
- $this->quiet = $quiet;
- $this->progress = $progress;
- $this->downloadCount = \count($nextArgs);
- $this->nextCallback = $nextCallback;
- $this->sharedState = (object) [
- 'bytesMaxCount' => 0,
- 'bytesMax' => 0,
- 'bytesTransferred' => 0,
- 'nextArgs' => &$nextArgs,
- 'nestingLevel' => 0,
- 'maxNestingReached' => false,
- 'lastProgress' => 0,
- 'lastUpdate' => microtime(true),
- ];
-
- if (!$this->quiet) {
- if (!$this->downloader && method_exists(parent::class, 'getRemoteContents')) {
- $this->io->writeError('
- */
-class TruncatedComposerRepository extends BaseComposerRepository
-{
- public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, RemoteFilesystem $rfs = null)
- {
- parent::__construct($repoConfig, $io, $config, $eventDispatcher, $rfs);
-
- $this->cache = new Cache($io, $config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$');
- }
-
- public function setSymfonyRequire(string $symfonyRequire, RootPackageInterface $rootPackage, Downloader $downloader, IOInterface $io)
- {
- $this->cache->setSymfonyRequire($symfonyRequire, $rootPackage, $downloader, $io);
- }
-
- protected function fetchFile($filename, $cacheKey = null, $sha256 = null, $storeLastModifiedTime = false)
- {
- $data = parent::fetchFile($filename, $cacheKey, $sha256, $storeLastModifiedTime);
-
- return \is_array($data) ? $this->cache->removeLegacyTags($data) : $data;
- }
-}
diff --git a/src/Unpacker.php b/src/Unpacker.php
index 97482929a..e186e0323 100644
--- a/src/Unpacker.php
+++ b/src/Unpacker.php
@@ -13,14 +13,12 @@
use Composer\Composer;
use Composer\Config\JsonConfigSource;
-use Composer\DependencyResolver\Pool;
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Composer\Json\JsonManipulator;
use Composer\Package\Locker;
use Composer\Package\Version\VersionSelector;
-use Composer\Plugin\PluginInterface;
use Composer\Repository\CompositeRepository;
use Composer\Repository\RepositorySet;
use Composer\Semver\VersionParser;
@@ -105,8 +103,7 @@ public function unpack(Operation $op, Result $result = null, &$links = [], bool
if ('*' === $constraint) {
if (null === $versionSelector) {
- $pool = class_exists(RepositorySet::class) ? RepositorySet::class : Pool::class;
- $pool = new $pool($this->composer->getPackage()->getMinimumStability(), $this->composer->getPackage()->getStabilityFlags());
+ $pool = new RepositorySet($this->composer->getPackage()->getMinimumStability(), $this->composer->getPackage()->getStabilityFlags());
$pool->addRepository(new CompositeRepository($this->composer->getRepositoryManager()->getRepositories()));
$versionSelector = new VersionSelector($pool);
}
@@ -205,11 +202,7 @@ public function updateLock(Result $result, IOInterface $io): void
}
// force removal of files under vendor/
- if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
- $locker = new Locker($io, $lockFile, $this->composer->getRepositoryManager(), $this->composer->getInstallationManager(), $jsonContent);
- } else {
- $locker = new Locker($io, $lockFile, $this->composer->getInstallationManager(), $jsonContent);
- }
+ $locker = new Locker($io, $lockFile, $this->composer->getInstallationManager(), $jsonContent);
$this->composer->setLocker($locker);
}
}
diff --git a/tests/CacheTest.php b/tests/CacheTest.php
deleted file mode 100644
index 7c25a9ba8..000000000
--- a/tests/CacheTest.php
+++ /dev/null
@@ -1,146 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Flex\Tests;
-
-use Composer\Package\Link;
-use Composer\Package\RootPackage;
-use Composer\Semver\Constraint\Constraint;
-use PHPUnit\Framework\TestCase;
-use Symfony\Flex\Cache;
-
-class CacheTest extends TestCase
-{
- /**
- * @dataProvider provideRemoveLegacyTags
- */
- public function testRemoveLegacyTags(array $expected, array $packages, string $symfonyRequire, array $versions)
- {
- $downloader = $this->getMockBuilder('Symfony\Flex\Downloader')->disableOriginalConstructor()->getMock();
- $downloader->expects($this->once())
- ->method('getVersions')
- ->willReturn($versions);
-
- $rootPackage = new RootPackage('test/test', '1.0.0.0', '1.0');
- $rootPackage->setRequires([
- 'symfony/bar' => new Link('__root__', 'symfony/bar', new Constraint('>=', '3.0.0.0')),
- ]);
-
- $cache = (new \ReflectionClass(Cache::class))->newInstanceWithoutConstructor();
- $cache->setSymfonyRequire($symfonyRequire, $rootPackage, $downloader);
-
- $this->assertSame(['packages' => $expected], $cache->removeLegacyTags(['packages' => $packages]));
- }
-
- public function provideRemoveLegacyTags()
- {
- yield 'no-symfony/symfony' => [[123], [123], '~1', ['splits' => []]];
-
- $branchAlias = function ($versionAlias) {
- return [
- 'extra' => [
- 'branch-alias' => [
- 'dev-main' => $versionAlias.'-dev',
- ],
- ],
- ];
- };
-
- $packages = [
- 'foo/unrelated' => [
- '1.0.0' => [],
- ],
- 'symfony/symfony' => [
- '3.3.0' => ['version_normalized' => '3.3.0.0'],
- '3.4.0' => ['version_normalized' => '3.4.0.0'],
- 'dev-main' => $branchAlias('3.5'),
- ],
- 'symfony/foo' => [
- '3.3.0' => ['version_normalized' => '3.3.0.0'],
- '3.4.0' => ['version_normalized' => '3.4.0.0'],
- 'dev-main' => $branchAlias('3.5'),
- ],
- ];
-
- yield 'empty-intersection-ignores-2' => [$packages, $packages, '~2.0', ['splits' => [
- 'symfony/foo' => ['3.3', '3.4', '3.5'],
- ]]];
- yield 'empty-intersection-ignores-4' => [$packages, $packages, '~4.0', ['splits' => [
- 'symfony/foo' => ['3.3', '3.4', '3.5'],
- ]]];
-
- $expected = $packages;
- unset($expected['symfony/symfony']['3.3.0']);
- unset($expected['symfony/foo']['3.3.0']);
-
- yield 'non-empty-intersection-filters' => [$expected, $packages, '~3.4', ['splits' => [
- 'symfony/foo' => ['3.3', '3.4', '3.5'],
- ]]];
-
- unset($expected['symfony/symfony']['3.4.0']);
- unset($expected['symfony/foo']['3.4.0']);
-
- yield 'main-only' => [$expected, $packages, '~3.5', ['splits' => [
- 'symfony/foo' => ['3.4', '3.5'],
- ]]];
-
- $packages = [
- 'symfony/symfony' => [
- '2.8.0' => ['version_normalized' => '2.8.0.0'],
- ],
- 'symfony/legacy' => [
- '2.8.0' => ['version_normalized' => '2.8.0.0'],
- 'dev-main' => $branchAlias('2.8'),
- ],
- ];
-
- yield 'legacy-are-not-filtered' => [$packages, $packages, '~3.0', ['splits' => [
- 'symfony/legacy' => ['2.8'],
- 'symfony/foo' => ['2.8'],
- ]]];
-
- $packages = [
- 'symfony/symfony' => [
- '2.8.0' => ['version_normalized' => '2.8.0.0'],
- 'dev-main' => $branchAlias('3.0'),
- ],
- 'symfony/foo' => [
- '2.8.0' => ['version_normalized' => '2.8.0.0'],
- 'dev-main' => $branchAlias('3.0'),
- ],
- 'symfony/new' => [
- 'dev-main' => $branchAlias('3.0'),
- ],
- ];
-
- $expected = $packages;
- unset($expected['symfony/symfony']['dev-main']);
- unset($expected['symfony/foo']['dev-main']);
-
- yield 'main-is-filtered-only-when-in-range' => [$expected, $packages, '~2.8', ['splits' => [
- 'symfony/foo' => ['2.8', '3.0'],
- 'symfony/new' => ['3.0'],
- ]]];
-
- $packages = [
- 'symfony/symfony' => [
- '3.0.0' => ['version_normalized' => '3.0.0.0'],
- ],
- 'symfony/bar' => [
- '3.0.0' => ['version_normalized' => '3.0.0.0'],
- ],
- ];
-
- yield 'root-constraints-are-preserved' => [$packages, $packages, '~2.8', ['splits' => [
- 'symfony/bar' => ['2.8', '3.0'],
- ]]];
- }
-}