@@ -76,6 +76,7 @@ class Flex implements PluginInterface, EventSubscriberInterface
76
76
private $ lock ;
77
77
private $ displayThanksReminder = 0 ;
78
78
private $ dryRun = false ;
79
+ private $ reinstall ;
79
80
private static $ activated = true ;
80
81
private static $ aliasResolveCommands = [
81
82
'require ' => true ,
@@ -117,8 +118,12 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
117
118
$ this ->filter = new PackageFilter ($ io , $ symfonyRequire , $ this ->downloader );
118
119
}
119
120
121
+ $ composerFile = Factory::getComposerFile ();
122
+ $ composerLock = 'json ' === pathinfo ($ composerFile , \PATHINFO_EXTENSION ) ? substr ($ composerFile , 0 , -4 ).'lock ' : $ composerFile .'.lock ' ;
123
+ $ symfonyLock = str_replace ('composer ' , 'symfony ' , basename ($ composerLock ));
124
+
120
125
$ this ->configurator = new Configurator ($ composer , $ io , $ this ->options );
121
- $ this ->lock = new Lock (getenv ('SYMFONY_LOCKFILE ' ) ?: str_replace ( ' composer.json ' , 'symfony.lock ' , Factory:: getComposerFile () ));
126
+ $ this ->lock = new Lock (getenv ('SYMFONY_LOCKFILE ' ) ?: \dirname ( $ composerLock ). ' / ' .( basename ( $ composerLock ) !== $ symfonyLock ? $ symfonyLock : 'symfony.lock ' ));
122
127
123
128
$ disable = true ;
124
129
foreach (array_merge ($ composer ->getPackage ()->getRequires () ?? [], $ composer ->getPackage ()->getDevRequires () ?? []) as $ link ) {
@@ -244,6 +249,13 @@ public function configureProject(Event $event)
244
249
$ this ->updateComposerLock ();
245
250
}
246
251
252
+ public function recordFlexInstall (PackageEvent $ event )
253
+ {
254
+ if (null === $ this ->reinstall && 'symfony/flex ' === $ event ->getOperation ()->getPackage ()->getName ()) {
255
+ $ this ->reinstall = true ;
256
+ }
257
+ }
258
+
247
259
public function record (PackageEvent $ event )
248
260
{
249
261
if ($ this ->shouldRecordOperation ($ event ->getOperation (), $ event ->isDevMode (), $ event ->getComposer ())) {
@@ -286,7 +298,7 @@ public function update(Event $event, $operations = [])
286
298
$ contents = file_get_contents ($ file );
287
299
$ json = JsonFile::parseJson ($ contents );
288
300
289
- if (!isset ($ json ['flex-require ' ]) && !isset ($ json ['flex-require-dev ' ])) {
301
+ if (!$ this -> reinstall && ! isset ($ json ['flex-require ' ]) && !isset ($ json ['flex-require-dev ' ])) {
290
302
$ this ->unpack ($ event );
291
303
292
304
return ;
@@ -298,17 +310,18 @@ public function update(Event $event, $operations = [])
298
310
$ symfonyVersion = $ json ['extra ' ]['symfony ' ]['require ' ] ?? null ;
299
311
$ versions = $ symfonyVersion ? $ this ->downloader ->getVersions () : null ;
300
312
foreach (['require ' , 'require-dev ' ] as $ type ) {
301
- if (isset ($ json ['flex- ' .$ type ])) {
302
- foreach ( $ json [ ' flex- ' . $ type ] as $ package => $ constraint ) {
303
- if ( $ symfonyVersion && ' * ' === $ constraint && isset ( $ versions [ ' splits ' ][ $ package ])) {
304
- // replace unbounded constraints for symfony/* packages by extra.symfony.require
305
- $ constraint = $ symfonyVersion ;
306
- }
307
- $ manipulator -> addLink ( $ type , $ package , $ constraint , $ sortPackages ) ;
313
+ if (! isset ($ json ['flex- ' .$ type ])) {
314
+ continue ;
315
+ }
316
+ foreach ( $ json [ ' flex- ' . $ type ] as $ package => $ constraint ) {
317
+ if ( $ symfonyVersion && ' * ' === $ constraint && isset ( $ versions [ ' splits ' ][ $ package ])) {
318
+ // replace unbounded constraints for symfony/* packages by extra.symfony.require
319
+ $ constraint = $ symfonyVersion ;
308
320
}
309
-
310
- $ manipulator ->removeMainKey ('flex- ' .$ type );
321
+ $ manipulator ->addLink ($ type , $ package , $ constraint , $ sortPackages );
311
322
}
323
+
324
+ $ manipulator ->removeMainKey ('flex- ' .$ type );
312
325
}
313
326
314
327
file_put_contents ($ file , $ manipulator ->getContents ());
@@ -671,7 +684,7 @@ private function formatOrigin(Recipe $recipe): string
671
684
672
685
private function shouldRecordOperation (OperationInterface $ operation , bool $ isDevMode , Composer $ composer = null ): bool
673
686
{
674
- if ($ this ->dryRun ) {
687
+ if ($ this ->dryRun || $ this -> reinstall ) {
675
688
return false ;
676
689
}
677
690
@@ -746,6 +759,7 @@ private function unpack(Event $event)
746
759
747
760
private function reinstall (Event $ event , bool $ update )
748
761
{
762
+ $ this ->reinstall = false ;
749
763
$ event ->stopPropagation ();
750
764
751
765
$ ed = $ this ->composer ->getEventDispatcher ();
@@ -783,6 +797,7 @@ public static function getSubscribedEvents(): array
783
797
784
798
$ events = [
785
799
PackageEvents::POST_PACKAGE_UPDATE => 'enableThanksReminder ' ,
800
+ PackageEvents::POST_PACKAGE_INSTALL => 'recordFlexInstall ' ,
786
801
InstallerEvents::PRE_OPERATIONS_EXEC => 'recordOperations ' ,
787
802
PluginEvents::PRE_POOL_CREATE => 'truncatePackages ' ,
788
803
ScriptEvents::POST_CREATE_PROJECT_CMD => 'configureProject ' ,
0 commit comments