Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Flex;

use Composer\Command\BaseConfigCommand;
use Composer\Command\GlobalCommand;
use Composer\Composer;
use Composer\Console\Application;
Expand Down Expand Up @@ -76,7 +77,7 @@ class Flex implements PluginInterface, EventSubscriberInterface
private $operations = [];
private $lock;
private $displayThanksReminder = 0;
private $ignoreUnstableReleases = false;
private $ignorePreleases = false;
private $reinstall;
private static $activated = true;
private static $aliasResolveCommands = [
Expand Down Expand Up @@ -182,7 +183,12 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
}
}

$this->ignoreUnstableReleases = $input->hasParameterOption('--prefer-lowest', true) && $input->hasParameterOption('--prefer-stable', true);
if (class_exists(BaseConfigCommand::class)) {
// composer 2.9+
$_SERVER['COMPOSER_PREFER_DEV_OVER_PRERELEASE'] = '1';
} else {
$this->ignorePreleases = $input->hasParameterOption('--prefer-lowest', true) && $input->hasParameterOption('--prefer-stable', true);
}

$addCommand = 'add'.(method_exists($app, 'addCommand') ? 'Command' : '');
$app->$addCommand(new Command\RecipesCommand($this, $this->lock, $rfs));
Expand All @@ -195,8 +201,8 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)

$symfonyRequire = preg_replace('/\.x$/', '.x-dev', getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? ''));

if ($symfonyRequire || $this->ignoreUnstableReleases) {
$this->filter = new PackageFilter($io, $symfonyRequire, $this->downloader, $this->ignoreUnstableReleases);
if ($symfonyRequire || $this->ignorePreleases) {
$this->filter = new PackageFilter($io, $symfonyRequire, $this->downloader, $this->ignorePreleases);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/PackageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ class PackageFilter
private $symfonyConstraints;
private $downloader;
private $io;
private $ignoreUnstableReleases;
private $ignorePreleases;

public function __construct(IOInterface $io, string $symfonyRequire, Downloader $downloader, bool $ignoreUnstableReleases = false)
public function __construct(IOInterface $io, string $symfonyRequire, Downloader $downloader, bool $ignorePreleases = false)
{
$this->versionParser = new VersionParser();
$this->symfonyRequire = $symfonyRequire;
$this->symfonyConstraints = '' !== $symfonyRequire ? $this->versionParser->parseConstraints($symfonyRequire) : null;
$this->downloader = $downloader;
$this->io = $io;
$this->ignoreUnstableReleases = $ignoreUnstableReleases;
$this->ignorePreleases = $ignorePreleases;
}

/**
Expand All @@ -50,7 +50,7 @@ public function __construct(IOInterface $io, string $symfonyRequire, Downloader
*/
public function removeLegacyPackages(array $data, RootPackageInterface $rootPackage, array $lockedPackages): array
{
if ($this->ignoreUnstableReleases) {
if ($this->ignorePreleases) {
$filteredPackages = [];
foreach ($data as $package) {
if (\in_array($package->getStability(), ['stable', 'dev'], true)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/PackageFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function provideRemoveLegacyPackages()
]]];
}

public function testIgnoreUnstableReleasesFiltersPreReleases()
public function testIgnorePreleases()
{
$io = new NullIO();
$downloader = $this->getMockBuilder(Downloader::class)->disableOriginalConstructor()->getMock();
Expand All @@ -229,7 +229,7 @@ public function testIgnoreUnstableReleasesFiltersPreReleases()
$this->assertSame([$stablePkg, $devPkg], $result);
}

public function testWithoutIgnoreUnstableReleasesKeepsAll()
public function testWithoutIgnorePreleases()
{
$io = new NullIO();
$downloader = $this->getMockBuilder(Downloader::class)->disableOriginalConstructor()->getMock();
Expand Down
Loading