From c1ba2be345bd2556efa44891df9b9d7f296fae00 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Tue, 24 Jan 2012 22:09:41 -0800 Subject: [PATCH] Provide the ability to specify internally installed packages (i.e., embedded in phar) --- src/Composer/Command/InstallCommand.php | 33 ++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 3c338590e..d8dedb40e 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -78,7 +78,7 @@ EOT ); } - public function install(Composer $composer, EventDispatcher $eventDispatcher, InputInterface $input, OutputInterface $output, $update, $preferSource, $dryRun, $verbose, $noInstallRecommends, $installSuggests) + public function install(Composer $composer, EventDispatcher $eventDispatcher, InputInterface $input, OutputInterface $output, $update, $preferSource, $dryRun, $verbose, $noInstallRecommends, $installSuggests, $internallyInstalledPackages = null) { if ($dryRun) { $verbose = true; @@ -108,12 +108,31 @@ EOT // creating requirements request $request = new Request($pool); + $internallyInstalledPackagesMap = array(); + if ($internallyInstalledPackages) { + foreach ($internallyInstalledPackages as $package) { + $request->install($package->getName(), new VersionConstraint('=', $package->getVersion())); + $internallyInstalledPackagesMap[$package->getName()] = $package; + } + } if ($update) { $output->writeln('Updating dependencies'); $installedPackages = $installedRepo->getPackages(); $links = $this->collectLinks($input, $composer->getPackage(), $noInstallRecommends, $installSuggests); foreach ($links as $link) { + if (isset($internallyInstalledPackagesMap[$link->getTarget()])) { + $package = $internallyInstalledPackagesMap[$link->getTarget()]; + if (!$link->getConstraint()->matches(new VersionConstraint('=', $package->getVersion()))) { + // Solver was not handling this well so we will + // handle it here where we can do something + // nice in the way of output. + throw new \UnexpectedValueException('Package '.$package->getName().' can not be updated because its version constraint ('.$link->getPrettyConstraint().') is not compatible with previously installed version ('.$package->getPrettyVersion().')'); + } + // This package is installed internally, no need to + // install it again. + continue; + } foreach ($installedPackages as $package) { if ($package->getName() === $link->getTarget()) { $request->update($package->getName(), new VersionConstraint('=', $package->getVersion())); @@ -140,6 +159,18 @@ EOT $links = $this->collectLinks($input, $composer->getPackage(), $noInstallRecommends, $installSuggests); foreach ($links as $link) { + if (isset($internallyInstalledPackagesMap[$link->getTarget()])) { + $package = $internallyInstalledPackagesMap[$link->getTarget()]; + if (!$link->getConstraint()->matches(new VersionConstraint('=', $package->getVersion()))) { + // Solver was not handling this well so we will + // handle it here where we can do something + // nice in the way of output. + throw new \UnexpectedValueException('Package '.$package->getName().' can not be installed because its version constraint ('.$link->getPrettyConstraint().') is not compatible with previously installed version ('.$package->getPrettyVersion().')'); + } + // This package is installed internally, no need to + // install it again. + continue; + } $request->install($link->getTarget(), $link->getConstraint()); } }