From 201cde05be39692bd2a1c0f2e0d395714dc7cfb1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 27 Apr 2013 00:11:06 +0200 Subject: [PATCH] Show reasons why an operation is executed in -vv mode, fixes #1063 --- src/Composer/DependencyResolver/Rule.php | 17 +++++++++++++++-- src/Composer/Installer.php | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index a69d3bc10..4e3dfc14d 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -82,6 +82,16 @@ class Rule return $this->job; } + public function getReason() + { + return $this->reason; + } + + public function getReasonData() + { + return $this->reasonData; + } + public function getRequiredPackage() { if ($this->reason === self::RULE_JOB_INSTALL) { @@ -200,9 +210,12 @@ class Rule if ($requires) { $requireText = array(); foreach ($requires as $require) { - $requireText[] = $require->getPrettyString(); + $requireText[$require->getName()][] = $require->getPrettyVersion(); } - $text .= ' -> satisfiable by '.implode(', ', $requireText).'.'; + foreach ($requireText as $name => $versions) { + $requireText[$name] = $name.'['.implode(', ', $versions).']'; + } + $text .= ' -> satisfiable by '.implode(', ', $requireText); } else { $targetName = $this->reasonData->getTarget(); diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 2970a9cb3..fc5a7c044 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -18,6 +18,7 @@ use Composer\DependencyResolver\Operation\UpdateOperation; use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Request; +use Composer\DependencyResolver\Rule; use Composer\DependencyResolver\Solver; use Composer\DependencyResolver\SolverProblemsException; use Composer\Downloader\DownloadManager; @@ -496,6 +497,21 @@ class Installer $this->installationManager->execute($localRepo, $operation); + // output reasons why the operation was ran + if ($this->verbose && $this->io->isVeryVerbose()) { + $reason = $operation->getReason(); + if ($reason instanceof Rule) { + switch ($reason->getReason()) { + case Rule::RULE_JOB_INSTALL: + $this->io->write(' REASON: Required to be installed: '.$reason->getRequiredPackage()); + break; + case Rule::RULE_PACKAGE_REQUIRES: + $this->io->write(' REASON: '.$reason->getPrettyString()); + break; + } + } + } + $event = 'Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType()); if (defined($event) && $this->runScripts) { $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $operation);