@@ -46,9 +46,11 @@ class Downloader
4646 private $ degradedMode = false ;
4747 private $ endpoints ;
4848 private $ index ;
49+ private $ conflicts ;
4950 private $ legacyEndpoint ;
5051 private $ caFile ;
5152 private $ enabled = true ;
53+ private $ composer ;
5254
5355 public function __construct (Composer $ composer , IoInterface $ io , $ rfs )
5456 {
@@ -91,6 +93,7 @@ public function __construct(Composer $composer, IoInterface $io, $rfs)
9193 $ this ->rfs = $ rfs ;
9294 $ this ->cache = new ComposerCache ($ io , $ config ->get ('cache-repo-dir ' ).'/flex ' );
9395 $ this ->sess = bin2hex (random_bytes (16 ));
96+ $ this ->composer = $ composer ;
9497 }
9598
9699 public function getSessionId (): string
@@ -136,6 +139,22 @@ public function getRecipes(array $operations): array
136139 {
137140 $ this ->initialize ();
138141
142+ if ($ this ->conflicts ) {
143+ $ lockedRepository = $ this ->composer ->getLocker ()->getLockedRepository ();
144+ foreach ($ this ->conflicts as $ conflicts ) {
145+ foreach ($ conflicts as $ package => $ versions ) {
146+ foreach ($ versions as $ version => $ conflicts ) {
147+ foreach ($ conflicts as $ conflictingPackage => $ constraint ) {
148+ if ($ lockedRepository ->findPackage ($ conflictingPackage , $ constraint )) {
149+ unset($ this ->index [$ package ][$ version ]);
150+ }
151+ }
152+ }
153+ }
154+ }
155+ $ this ->conflicts = [];
156+ }
157+
139158 $ data = [];
140159 $ urls = [];
141160 $ chunk = '' ;
@@ -210,6 +229,10 @@ public function getRecipes(array $operations): array
210229 continue ;
211230 }
212231
232+ if (\is_array ($ recipeVersions )) {
233+ $ data ['conflicts ' ][$ package ->getName ()] = true ;
234+ }
235+
213236 if (null !== $ this ->endpoints ) {
214237 $ data ['locks ' ][$ package ->getName ()]['version ' ] = $ version ;
215238 continue ;
@@ -434,11 +457,14 @@ private function initialize()
434457 foreach ($ config ['recipes ' ] ?? [] as $ package => $ versions ) {
435458 $ this ->index [$ package ] = $ this ->index [$ package ] ?? array_fill_keys ($ versions , $ endpoint );
436459 }
460+ $ this ->conflicts [] = $ config ['recipe-conflicts ' ] ?? [];
437461 self ::$ versions += $ config ['versions ' ] ?? [];
438462 self ::$ aliases += $ config ['aliases ' ] ?? [];
439- unset($ config ['recipes ' ], $ config ['versions ' ], $ config ['aliases ' ]);
463+ unset($ config ['recipes ' ], $ config ['recipe-conflicts ' ], $ config [ ' versions ' ], $ config ['aliases ' ]);
440464 $ this ->endpoints [$ endpoint ] = $ config ;
441465 }
466+
467+ return false ;
442468 }
443469
444470 private static function generateCacheKey (string $ url ): string
0 commit comments