Skip to content
Merged
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
35 changes: 23 additions & 12 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Flex implements PluginInterface, EventSubscriberInterface
private $rfs;
private $progress = true;
private $dryRun = false;
private $reinstall;
private static $activated = true;
private static $repoReadingCommands = [
'create-project' => true,
Expand Down Expand Up @@ -346,6 +347,13 @@ public function configureProject(Event $event)
$this->updateComposerLock();
}

public function recordFlexInstall(PackageEvent $event)
{
if (null === $this->reinstall && 'symfony/flex' === $event->getOperation()->getPackage()->getName()) {
$this->reinstall = true;
}
}

public function record(PackageEvent $event)
{
if ($this->shouldRecordOperation($event->getOperation(), $event->isDevMode(), $event->getComposer())) {
Expand Down Expand Up @@ -388,7 +396,7 @@ public function update(Event $event, $operations = [])
$contents = file_get_contents($file);
$json = JsonFile::parseJson($contents);

if (!isset($json['flex-require']) && !isset($json['flex-require-dev'])) {
if (!$this->reinstall && !isset($json['flex-require']) && !isset($json['flex-require-dev'])) {
$this->unpack($event);

return;
Expand All @@ -400,17 +408,18 @@ public function update(Event $event, $operations = [])
$symfonyVersion = $json['extra']['symfony']['require'] ?? null;
$versions = $symfonyVersion ? $this->downloader->getVersions() : null;
foreach (['require', 'require-dev'] as $type) {
if (isset($json['flex-'.$type])) {
foreach ($json['flex-'.$type] as $package => $constraint) {
if ($symfonyVersion && '*' === $constraint && isset($versions['splits'][$package])) {
// replace unbounded constraints for symfony/* packages by extra.symfony.require
$constraint = $symfonyVersion;
}
$manipulator->addLink($type, $package, $constraint, $sortPackages);
if (!isset($json['flex-'.$type])) {
continue;
}
foreach ($json['flex-'.$type] as $package => $constraint) {
if ($symfonyVersion && '*' === $constraint && isset($versions['splits'][$package])) {
// replace unbounded constraints for symfony/* packages by extra.symfony.require
$constraint = $symfonyVersion;
}

$manipulator->removeMainKey('flex-'.$type);
$manipulator->addLink($type, $package, $constraint, $sortPackages);
}

$manipulator->removeMainKey('flex-'.$type);
}

file_put_contents($file, $manipulator->getContents());
Expand Down Expand Up @@ -891,7 +900,7 @@ private function formatOrigin(Recipe $recipe): string

private function shouldRecordOperation(OperationInterface $operation, bool $isDevMode, Composer $composer = null): bool
{
if ($this->dryRun) {
if ($this->dryRun || $this->reinstall) {
return false;
}

Expand Down Expand Up @@ -994,6 +1003,7 @@ private function unpack(Event $event)

private function reinstall(Event $event, bool $update)
{
$this->reinstall = false;
$event->stopPropagation();

$ed = $this->composer->getEventDispatcher();
Expand Down Expand Up @@ -1045,7 +1055,7 @@ public static function getSubscribedEvents(): array

if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
$events += [
PackageEvents::POST_PACKAGE_INSTALL => 'record',
PackageEvents::POST_PACKAGE_INSTALL => [['recordFlexInstall'], ['record']],
PackageEvents::POST_PACKAGE_UPDATE => [['record'], ['enableThanksReminder']],
PackageEvents::POST_PACKAGE_UNINSTALL => 'record',
InstallerEvents::PRE_DEPENDENCIES_SOLVING => [['populateProvidersCacheDir', \PHP_INT_MAX]],
Expand All @@ -1057,6 +1067,7 @@ public static function getSubscribedEvents(): array
} else {
$events += [
PackageEvents::POST_PACKAGE_UPDATE => 'enableThanksReminder',
PackageEvents::POST_PACKAGE_INSTALL => 'recordFlexInstall',
InstallerEvents::PRE_OPERATIONS_EXEC => 'recordOperations',
PluginEvents::PRE_POOL_CREATE => 'truncatePackages',
];
Expand Down