1
0
Fork 0

Simplify install() signature

pull/281/head
Jordi Boggiano 2012-02-06 13:43:33 +01:00
parent 162a6e5781
commit f761bf8d99
2 changed files with 18 additions and 19 deletions

View File

@ -31,6 +31,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Composer\DependencyResolver\Operation\InstallOperation; use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Solver; use Composer\DependencyResolver\Solver;
use Composer\IO\IOInterface;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
@ -67,12 +68,11 @@ EOT
$composer = $this->getComposer(); $composer = $this->getComposer();
$io = $this->getApplication()->getIO(); $io = $this->getApplication()->getIO();
$eventDispatcher = new EventDispatcher($composer, $io); $eventDispatcher = new EventDispatcher($composer, $io);
return $this->install( return $this->install(
$io,
$composer, $composer,
$eventDispatcher, $eventDispatcher,
$input,
$output,
false,
(Boolean)$input->getOption('dev'), (Boolean)$input->getOption('dev'),
(Boolean)$input->getOption('dry-run'), (Boolean)$input->getOption('dry-run'),
(Boolean)$input->getOption('verbose'), (Boolean)$input->getOption('verbose'),
@ -81,7 +81,7 @@ EOT
); );
} }
public function install(Composer $composer, EventDispatcher $eventDispatcher, InputInterface $input, OutputInterface $output, $update, $preferSource, $dryRun, $verbose, $noInstallRecommends, $installSuggests, RepositoryInterface $additionalInstalledRepository = null) public function install(IOInterface $io, Composer $composer, EventDispatcher $eventDispatcher, $preferSource = false, $dryRun = false, $verbose = false, $noInstallRecommends = false, $installSuggests = false, $update = false, RepositoryInterface $additionalInstalledRepository = null)
{ {
if ($dryRun) { if ($dryRun) {
$verbose = true; $verbose = true;
@ -115,9 +115,9 @@ EOT
// creating requirements request // creating requirements request
$request = new Request($pool); $request = new Request($pool);
if ($update) { if ($update) {
$output->writeln('<info>Updating dependencies</info>'); $io->write('<info>Updating dependencies</info>');
$installedPackages = $installedRepo->getPackages(); $installedPackages = $installedRepo->getPackages();
$links = $this->collectLinks($input, $composer->getPackage(), $noInstallRecommends, $installSuggests); $links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
foreach ($links as $link) { foreach ($links as $link) {
foreach ($installedPackages as $package) { foreach ($installedPackages as $package) {
@ -130,10 +130,10 @@ EOT
$request->install($link->getTarget(), $link->getConstraint()); $request->install($link->getTarget(), $link->getConstraint());
} }
} elseif ($composer->getLocker()->isLocked()) { } elseif ($composer->getLocker()->isLocked()) {
$output->writeln('<info>Installing from lock file</info>'); $io->write('<info>Installing from lock file</info>');
if (!$composer->getLocker()->isFresh()) { if (!$composer->getLocker()->isFresh()) {
$output->writeln('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>'); $io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>');
} }
foreach ($composer->getLocker()->getLockedPackages() as $package) { foreach ($composer->getLocker()->getLockedPackages() as $package) {
@ -141,9 +141,9 @@ EOT
$request->install($package->getName(), $constraint); $request->install($package->getName(), $constraint);
} }
} else { } else {
$output->writeln('<info>Installing dependencies</info>'); $io->write('<info>Installing dependencies</info>');
$links = $this->collectLinks($input, $composer->getPackage(), $noInstallRecommends, $installSuggests); $links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
foreach ($links as $link) { foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint()); $request->install($link->getTarget(), $link->getConstraint());
@ -188,11 +188,11 @@ EOT
// execute operations // execute operations
if (!$operations) { if (!$operations) {
$output->writeln('<info>Nothing to install/update</info>'); $io->write('<info>Nothing to install/update</info>');
} }
foreach ($operations as $operation) { foreach ($operations as $operation) {
if ($verbose) { if ($verbose) {
$output->writeln((string) $operation); $io->write((string) $operation);
} }
if (!$dryRun) { if (!$dryRun) {
$eventDispatcher->dispatchPackageEvent(constant('Composer\Script\ScriptEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType())), $operation); $eventDispatcher->dispatchPackageEvent(constant('Composer\Script\ScriptEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType())), $operation);
@ -204,12 +204,12 @@ EOT
if (!$dryRun) { if (!$dryRun) {
if ($update || !$composer->getLocker()->isLocked()) { if ($update || !$composer->getLocker()->isLocked()) {
$composer->getLocker()->lockPackages($localRepo->getPackages()); $composer->getLocker()->lockPackages($localRepo->getPackages());
$output->writeln('<info>Writing lock file</info>'); $io->write('<info>Writing lock file</info>');
} }
$localRepo->write(); $localRepo->write();
$output->writeln('<info>Generating autoload files</info>'); $io->write('<info>Generating autoload files</info>');
$generator = new AutoloadGenerator; $generator = new AutoloadGenerator;
$generator->dump($localRepo, $composer->getPackage(), $installationManager, $installationManager->getVendorPath().'/.composer'); $generator->dump($localRepo, $composer->getPackage(), $installationManager, $installationManager->getVendorPath().'/.composer');
@ -219,7 +219,7 @@ EOT
} }
} }
private function collectLinks(InputInterface $input, PackageInterface $package, $noInstallRecommends, $installSuggests) private function collectLinks(PackageInterface $package, $noInstallRecommends, $installSuggests)
{ {
$links = $package->getRequires(); $links = $package->getRequires();

View File

@ -60,16 +60,15 @@ EOT
$eventDispatcher = new EventDispatcher($composer, $io); $eventDispatcher = new EventDispatcher($composer, $io);
return $installCommand->install( return $installCommand->install(
$io,
$composer, $composer,
$eventDispatcher, $eventDispatcher,
$input,
$output,
true,
(Boolean)$input->getOption('dev'), (Boolean)$input->getOption('dev'),
(Boolean)$input->getOption('dry-run'), (Boolean)$input->getOption('dry-run'),
(Boolean)$input->getOption('verbose'), (Boolean)$input->getOption('verbose'),
(Boolean)$input->getOption('no-install-recommends'), (Boolean)$input->getOption('no-install-recommends'),
(Boolean)$input->getOption('install-suggests') (Boolean)$input->getOption('install-suggests'),
true
); );
} }
} }