Skip to content

Commit ea2a03c

Browse files
bug #866 Fix BC with upgrading from flex < 1.18 (nicolas-grekas)
This PR was merged into the 1.x branch. Discussion ---------- Fix BC with upgrading from flex < 1.18 Fix #863 Commits ------- a0a2080 Fix BC with upgrading from flex < 1.18
2 parents 910a5c5 + a0a2080 commit ea2a03c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/Flex.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public function install(Event $event)
431431
foreach ($recipes as $recipe) {
432432
if ('install' === $recipe->getJob() && !$installContribs && $recipe->isContrib()) {
433433
$warning = $this->io->isInteractive() ? 'WARNING' : 'IGNORING';
434-
$this->io->writeError(sprintf(' - <warning> %s </> %s', $warning, $recipe->getFormattedOrigin()));
434+
$this->io->writeError(sprintf(' - <warning> %s </> %s', $warning, $this->formatOrigin($recipe)));
435435
$question = sprintf(' The recipe for this package comes from the "contrib" repository, which is open to community contributions.
436436
Review the recipe at %s
437437
@@ -474,7 +474,7 @@ function ($value) {
474474

475475
switch ($recipe->getJob()) {
476476
case 'install':
477-
$this->io->writeError(sprintf(' - Configuring %s', $recipe->getFormattedOrigin()));
477+
$this->io->writeError(sprintf(' - Configuring %s', $this->formatOrigin($recipe)));
478478
$this->configurator->install($recipe, $this->lock, [
479479
'force' => $event instanceof UpdateEvent && $event->force(),
480480
]);
@@ -491,7 +491,7 @@ function ($value) {
491491
case 'update':
492492
break;
493493
case 'uninstall':
494-
$this->io->writeError(sprintf(' - Unconfiguring %s', $recipe->getFormattedOrigin()));
494+
$this->io->writeError(sprintf(' - Unconfiguring %s', $this->formatOrigin($recipe)));
495495
$this->configurator->unconfigure($recipe, $this->lock);
496496
break;
497497
}
@@ -834,6 +834,23 @@ private function initOptions(): Options
834834
return new Options($options, $this->io);
835835
}
836836

837+
private function formatOrigin(Recipe $recipe): string
838+
{
839+
if (method_exists($recipe, 'getFormattedOrigin')) {
840+
return $recipe->getFormattedOrigin();
841+
}
842+
843+
// BC with upgrading from flex < 1.18
844+
$origin = $recipe->getOrigin();
845+
846+
// symfony/translation:[email protected]/symfony/recipes:branch
847+
if (!preg_match('/^([^:]++):([^@]++)@(.+)$/', $origin, $matches)) {
848+
return $origin;
849+
}
850+
851+
return sprintf('<info>%s</> (<comment>>=%s</>): From %s', $matches[1], $matches[2], 'auto-generated recipe' === $matches[3] ? '<comment>'.$matches[3].'</>' : $matches[3]);
852+
}
853+
837854
private function shouldRecordOperation(PackageEvent $event): bool
838855
{
839856
$operation = $event->getOperation();

0 commit comments

Comments
 (0)