@@ -87,6 +87,7 @@ class Flex implements PluginInterface, EventSubscriberInterface
8787 private $ rfs ;
8888 private $ progress = true ;
8989 private $ dryRun = false ;
90+ private $ reinstall ;
9091 private static $ activated = true ;
9192 private static $ repoReadingCommands = [
9293 'create-project ' => true ,
@@ -346,6 +347,13 @@ public function configureProject(Event $event)
346347 $ this ->updateComposerLock ();
347348 }
348349
350+ public function recordFlexInstall (PackageEvent $ event )
351+ {
352+ if (null === $ this ->reinstall && 'symfony/flex ' === $ event ->getOperation ()->getPackage ()->getName ()) {
353+ $ this ->reinstall = true ;
354+ }
355+ }
356+
349357 public function record (PackageEvent $ event )
350358 {
351359 if ($ this ->shouldRecordOperation ($ event ->getOperation (), $ event ->isDevMode (), $ event ->getComposer ())) {
@@ -388,7 +396,7 @@ public function update(Event $event, $operations = [])
388396 $ contents = file_get_contents ($ file );
389397 $ json = JsonFile::parseJson ($ contents );
390398
391- if (!isset ($ json ['flex-require ' ]) && !isset ($ json ['flex-require-dev ' ])) {
399+ if (!$ this -> reinstall && ! isset ($ json ['flex-require ' ]) && !isset ($ json ['flex-require-dev ' ])) {
392400 $ this ->unpack ($ event );
393401
394402 return ;
@@ -400,17 +408,18 @@ public function update(Event $event, $operations = [])
400408 $ symfonyVersion = $ json ['extra ' ]['symfony ' ]['require ' ] ?? null ;
401409 $ versions = $ symfonyVersion ? $ this ->downloader ->getVersions () : null ;
402410 foreach (['require ' , 'require-dev ' ] as $ type ) {
403- if (isset ($ json ['flex- ' .$ type ])) {
404- foreach ( $ json [ ' flex- ' . $ type ] as $ package => $ constraint ) {
405- if ( $ symfonyVersion && ' * ' === $ constraint && isset ( $ versions [ ' splits ' ][ $ package ])) {
406- // replace unbounded constraints for symfony/* packages by extra.symfony.require
407- $ constraint = $ symfonyVersion ;
408- }
409- $ manipulator -> addLink ( $ type , $ package , $ constraint , $ sortPackages ) ;
411+ if (! isset ($ json ['flex- ' .$ type ])) {
412+ continue ;
413+ }
414+ foreach ( $ json [ ' flex- ' . $ type ] as $ package => $ constraint ) {
415+ if ( $ symfonyVersion && ' * ' === $ constraint && isset ( $ versions [ ' splits ' ][ $ package ])) {
416+ // replace unbounded constraints for symfony/* packages by extra.symfony.require
417+ $ constraint = $ symfonyVersion ;
410418 }
411-
412- $ manipulator ->removeMainKey ('flex- ' .$ type );
419+ $ manipulator ->addLink ($ type , $ package , $ constraint , $ sortPackages );
413420 }
421+
422+ $ manipulator ->removeMainKey ('flex- ' .$ type );
414423 }
415424
416425 file_put_contents ($ file , $ manipulator ->getContents ());
@@ -891,7 +900,7 @@ private function formatOrigin(Recipe $recipe): string
891900
892901 private function shouldRecordOperation (OperationInterface $ operation , bool $ isDevMode , Composer $ composer = null ): bool
893902 {
894- if ($ this ->dryRun ) {
903+ if ($ this ->dryRun || $ this -> reinstall ) {
895904 return false ;
896905 }
897906
@@ -994,6 +1003,7 @@ private function unpack(Event $event)
9941003
9951004 private function reinstall (Event $ event , bool $ update )
9961005 {
1006+ $ this ->reinstall = false ;
9971007 $ event ->stopPropagation ();
9981008
9991009 $ ed = $ this ->composer ->getEventDispatcher ();
@@ -1045,7 +1055,7 @@ public static function getSubscribedEvents(): array
10451055
10461056 if (version_compare ('2.0.0 ' , PluginInterface::PLUGIN_API_VERSION , '> ' )) {
10471057 $ events += [
1048- PackageEvents::POST_PACKAGE_INSTALL => ' record ' ,
1058+ PackageEvents::POST_PACKAGE_INSTALL => [[ ' recordFlexInstall ' ], [ ' record ']] ,
10491059 PackageEvents::POST_PACKAGE_UPDATE => [['record ' ], ['enableThanksReminder ' ]],
10501060 PackageEvents::POST_PACKAGE_UNINSTALL => 'record ' ,
10511061 InstallerEvents::PRE_DEPENDENCIES_SOLVING => [['populateProvidersCacheDir ' , \PHP_INT_MAX ]],
@@ -1057,6 +1067,7 @@ public static function getSubscribedEvents(): array
10571067 } else {
10581068 $ events += [
10591069 PackageEvents::POST_PACKAGE_UPDATE => 'enableThanksReminder ' ,
1070+ PackageEvents::POST_PACKAGE_INSTALL => 'recordFlexInstall ' ,
10601071 InstallerEvents::PRE_OPERATIONS_EXEC => 'recordOperations ' ,
10611072 PluginEvents::PRE_POOL_CREATE => 'truncatePackages ' ,
10621073 ];
0 commit comments