13
13
14
14
use Composer \Command \BaseCommand ;
15
15
use Composer \IO \IOInterface ;
16
+ use Composer \Package \Package ;
16
17
use Composer \Util \ProcessExecutor ;
17
18
use Symfony \Component \Console \Exception \RuntimeException ;
18
19
use Symfony \Component \Console \Formatter \OutputFormatterStyle ;
@@ -122,7 +123,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
122
123
return 1 ;
123
124
}
124
125
125
- $ originalRecipe = $ this ->getRecipe ($ packageName , $ recipeRef , $ recipeVersion );
126
+ $ installedRepo = $ this ->getComposer ()->getRepositoryManager ()->getLocalRepository ();
127
+ $ package = $ installedRepo ->findPackage ($ packageName , '* ' ) ?? new Package ($ packageName , $ packageLockData ['version ' ], $ packageLockData ['version ' ]);
128
+ $ originalRecipe = $ this ->getRecipe ($ package , $ recipeRef , $ recipeVersion );
126
129
127
130
if (null === $ originalRecipe ) {
128
131
$ io ->writeError ([
@@ -134,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134
137
return 1 ;
135
138
}
136
139
137
- $ newRecipe = $ this ->getRecipe ($ packageName );
140
+ $ newRecipe = $ this ->getRecipe ($ package );
138
141
139
142
if ($ newRecipe ->getRef () === $ originalRecipe ->getRef ()) {
140
143
$ io ->write (sprintf ('This recipe for <info>%s</info> is already at the latest version. ' , $ packageName ));
@@ -259,13 +262,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
259
262
return 0 ;
260
263
}
261
264
262
- private function getRecipe (string $ packageName , string $ recipeRef = null , string $ recipeVersion = null ): ?Recipe
265
+ private function getRecipe (Package $ package , string $ recipeRef = null , string $ recipeVersion = null ): ?Recipe
263
266
{
264
- $ installedRepo = $ this ->getComposer ()->getRepositoryManager ()->getLocalRepository ();
265
- $ package = $ installedRepo ->findPackage ($ packageName , '* ' );
266
- if (null === $ package ) {
267
- throw new RuntimeException (sprintf ('Could not find package "%s". Try running "composer install". ' , $ packageName ));
268
- }
269
267
$ operation = new InformationOperation ($ package );
270
268
if (null !== $ recipeRef ) {
271
269
$ operation ->setSpecificRecipeVersion ($ recipeRef , $ recipeVersion );
@@ -278,10 +276,10 @@ private function getRecipe(string $packageName, string $recipeRef = null, string
278
276
279
277
return new Recipe (
280
278
$ package ,
281
- $ packageName ,
279
+ $ package -> getName () ,
282
280
$ operation ->getOperationType (),
283
- $ recipes ['manifests ' ][$ packageName ],
284
- $ recipes ['locks ' ][$ packageName ] ?? []
281
+ $ recipes ['manifests ' ][$ package -> getName () ],
282
+ $ recipes ['locks ' ][$ package -> getName () ] ?? []
285
283
);
286
284
}
287
285
@@ -358,19 +356,13 @@ private function generateChangelog(Recipe $originalRecipe): ?array
358
356
private function askForPackage (IOInterface $ io , Lock $ symfonyLock ): ?string
359
357
{
360
358
$ installedRepo = $ this ->getComposer ()->getRepositoryManager ()->getLocalRepository ();
361
- $ locker = $ this ->getComposer ()->getLocker ();
362
- $ lockData = $ locker ->getLockData ();
363
-
364
- // Merge all packages installed
365
- $ packages = array_merge ($ lockData ['packages ' ], $ lockData ['packages-dev ' ]);
366
359
367
360
$ operations = [];
368
- foreach ($ packages as $ value ) {
369
- if (null === $ pkg = $ installedRepo ->findPackage ($ value ['name ' ], '* ' )) {
370
- continue ;
361
+ foreach ($ symfonyLock ->all () as $ name => $ lock ) {
362
+ if (isset ($ lock ['recipe ' ]['ref ' ])) {
363
+ $ package = $ installedRepo ->findPackage ($ name , '* ' ) ?? new Package ($ name , $ lock ['version ' ], $ lock ['version ' ]);
364
+ $ operations [] = new InformationOperation ($ package );
371
365
}
372
-
373
- $ operations [] = new InformationOperation ($ pkg );
374
366
}
375
367
376
368
$ recipes = $ this ->flex ->fetchRecipes ($ operations , false );
0 commit comments