Make install method self contained

Experimental: Updated `install()` method to accept its Composer
and input option dependencies as method arguments.
main
Beau Simensen 13 years ago
parent 385075cda3
commit c94d867c07

@ -15,6 +15,7 @@ namespace Composer\Command;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Script\EventDispatcher; use Composer\Script\EventDispatcher;
use Composer\Autoload\AutoloadGenerator; use Composer\Autoload\AutoloadGenerator;
use Composer\Composer;
use Composer\DependencyResolver; use Composer\DependencyResolver;
use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
@ -60,17 +61,28 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
return $this->install($input, $output); $composer = $this->getComposer();
$io = $this->getApplication()->getIO();
$eventDispatcher = new EventDispatcher($composer, $io);
return $this->install(
$composer,
$eventDispatcher,
$input,
$output,
false,
(Boolean)$input->getOption('dev'),
(Boolean)$input->getOption('dry-run'),
(Boolean)$input->getOption('verbose'),
(Boolean)$input->getOption('no-install-recommends'),
(Boolean)$input->getOption('install-suggests')
);
} }
public function install(InputInterface $input, OutputInterface $output, $update = false) public function install(Composer $composer, EventDispatcher $eventDispatcher, InputInterface $input, OutputInterface $output, $update, $preferSource, $dryRun, $verbose, $noInstallRecommends, $installSuggests)
{ {
$preferSource = (Boolean) $input->getOption('dev'); if ($dryRun) {
$dryRun = (Boolean) $input->getOption('dry-run'); $verbose = true;
$verbose = $dryRun || $input->getOption('verbose'); }
$composer = $this->getComposer();
$io = $this->getApplication()->getIO();
$dispatcher = new EventDispatcher($this->getComposer(), $io);
if ($preferSource) { if ($preferSource) {
$composer->getDownloadManager()->setPreferSource(true); $composer->getDownloadManager()->setPreferSource(true);
@ -91,7 +103,7 @@ EOT
// dispatch pre event // dispatch pre event
if (!$dryRun) { if (!$dryRun) {
$eventName = $update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD; $eventName = $update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
$dispatcher->dispatchCommandEvent($eventName); $eventDispatcher->dispatchCommandEvent($eventName);
} }
// creating requirements request // creating requirements request
@ -99,7 +111,7 @@ EOT
if ($update) { if ($update) {
$output->writeln('<info>Updating dependencies</info>'); $output->writeln('<info>Updating dependencies</info>');
$installedPackages = $installedRepo->getPackages(); $installedPackages = $installedRepo->getPackages();
$links = $this->collectLinks($input, $composer->getPackage()); $links = $this->collectLinks($input, $composer->getPackage(), $noInstallRecommends, $installSuggests);
foreach ($links as $link) { foreach ($links as $link) {
foreach ($installedPackages as $package) { foreach ($installedPackages as $package) {
@ -125,7 +137,7 @@ EOT
} else { } else {
$output->writeln('<info>Installing dependencies</info>'); $output->writeln('<info>Installing dependencies</info>');
$links = $this->collectLinks($input, $composer->getPackage()); $links = $this->collectLinks($input, $composer->getPackage(), $noInstallRecommends, $installSuggests);
foreach ($links as $link) { foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint()); $request->install($link->getTarget(), $link->getConstraint());
@ -177,9 +189,9 @@ EOT
$output->writeln((string) $operation); $output->writeln((string) $operation);
} }
if (!$dryRun) { if (!$dryRun) {
$dispatcher->dispatchPackageEvent(constant('Composer\Script\ScriptEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType())), $operation); $eventDispatcher->dispatchPackageEvent(constant('Composer\Script\ScriptEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType())), $operation);
$installationManager->execute($operation); $installationManager->execute($operation);
$dispatcher->dispatchPackageEvent(constant('Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType())), $operation); $eventDispatcher->dispatchPackageEvent(constant('Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType())), $operation);
} }
} }
@ -197,19 +209,19 @@ EOT
// dispatch post event // dispatch post event
$eventName = $update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD; $eventName = $update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
$dispatcher->dispatchCommandEvent($eventName); $eventDispatcher->dispatchCommandEvent($eventName);
} }
} }
private function collectLinks(InputInterface $input, PackageInterface $package) private function collectLinks(InputInterface $input, PackageInterface $package, $noInstallRecommends, $installSuggests)
{ {
$links = $package->getRequires(); $links = $package->getRequires();
if (!$input->getOption('no-install-recommends')) { if (!$noInstallRecommends) {
$links = array_merge($links, $package->getRecommends()); $links = array_merge($links, $package->getRecommends());
} }
if ($input->getOption('install-suggests')) { if ($installSuggests) {
$links = array_merge($links, $package->getSuggests()); $links = array_merge($links, $package->getSuggests());
} }

@ -19,6 +19,7 @@ use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Operation; use Composer\DependencyResolver\Operation;
use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Script\EventDispatcher;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -54,7 +55,21 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$installCommand = $this->getApplication()->find('install'); $installCommand = $this->getApplication()->find('install');
$composer = $this->getComposer();
$io = $this->getApplication()->getIO();
$eventDispatcher = new EventDispatcher($composer, $io);
return $installCommand->install($input, $output, true); return $installCommand->install(
$composer,
$eventDispatcher,
$input,
$output,
true,
(Boolean)$input->getOption('dev'),
(Boolean)$input->getOption('dry-run'),
(Boolean)$input->getOption('verbose'),
(Boolean)$input->getOption('no-install-recommends'),
(Boolean)$input->getOption('install-suggests')
);
} }
} }

Loading…
Cancel
Save