From 05ddfde868b24e4c72fd00caaf0eb1b024a4bae7 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 25 Sep 2011 21:00:44 +0300 Subject: [PATCH] Reflect latest refactoring changes in commands --- bin/composer | 37 +++++++++++++++---------- src/Composer/Command/Command.php | 29 ------------------- src/Composer/Command/InstallCommand.php | 37 ++++++++++++++----------- src/Composer/Console/Application.php | 22 +-------------- 4 files changed, 45 insertions(+), 80 deletions(-) diff --git a/bin/composer b/bin/composer index 12fbab8d6..06d40f904 100755 --- a/bin/composer +++ b/bin/composer @@ -10,25 +10,34 @@ use Composer\Repository; use Composer\Package; use Composer\Console\Application as ComposerApplication; -// initialize installer -$installer = new Installer\LibraryInstaller('vendor', $preferSource = true); -$installer->setDownloader('git', new Downloader\GitDownloader()); -$installer->setDownloader('pear', new Downloader\PearDownloader()); -$installer->setDownloader('zip', new Downloader\ZipDownloader()); +// initialize repository manager +$rm = new Repository\RepositoryManager(); +$rm->setLocalRepository(new Repository\FilesystemRepository('.composer/installed.json')); +$rm->setRepository('Platform', new Repository\PlatformRepository()); +$rm->setRepository('Packagist', new Repository\ComposerRepository('http://packagist.org')); -// initialize composer -$composer = new Composer(); -$composer->setInstaller('library', $installer); -$composer->setRepository('Platform', new Repository\PlatformRepository()); -$composer->setRepository('Packagist', new Repository\ComposerRepository('http://packagist.org')); +// initialize download manager +$dm = new Downloader\DownloadManager($preferSource = false); +$dm->setDownloader('git', new Downloader\GitDownloader()); +$dm->setDownloader('pear', new Downloader\PearDownloader()); +$dm->setDownloader('zip', new Downloader\ZipDownloader()); -// initialize package +// initialize installation manager +$im = new Installer\InstallationManager(); +$im->setInstaller('vendor', new Installer\LibraryInstaller('vendor', $dm, $rm->getLocalRepository())); + +// load package $loader = new Package\Loader\JsonLoader(); $package = $loader->load('composer.json'); -// initialize lock -$packageLock = new Package\PackageLock('composer.lock'); +// initialize composer +$composer = new Composer(); +$composer->setPackage($package); +$composer->setPackageLock(new Package\PackageLock('composer.lock')); +$composer->setRepositoryManager($rm); +$composer->setDownloadManager($dm); +$composer->setInstallationManager($im); // run the command application -$application = new ComposerApplication($composer, $package, $packageLock); +$application = new ComposerApplication($composer); $application->run(); diff --git a/src/Composer/Command/Command.php b/src/Composer/Command/Command.php index 54f44c9d3..946d775b8 100644 --- a/src/Composer/Command/Command.php +++ b/src/Composer/Command/Command.php @@ -34,33 +34,4 @@ abstract class Command extends BaseCommand { return $this->getApplication()->getComposer(); } - - /** - * @return \Composer\Package\PackageInterface - */ - protected function getPackage() - { - return $this->getApplication()->getPackage(); - } - - /** - * @return \Composer\Package\PackageLock - */ - protected function getLock() - { - return $this->getApplication()->getLock(); - } - - protected function solveDependencies(Request $request, Solver $solver) - { - $operations = array(); - foreach ($solver->solve($request) as $task) { - $installer = $this->getComposer()->getInstaller($task['package']->getType()); - $operation = new Operation($installer, $task['job'], $task['package']); - - $operations[] = $operation; - } - - return $operations; - } } diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index b2e41a522..d93ef434d 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -15,6 +15,7 @@ namespace Composer\Command; use Composer\DependencyResolver; use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Request; +use Composer\DependencyResolver\Operation; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -44,13 +45,16 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { - if ($this->getLock()->isLocked()) { + $composer = $this->getComposer(); + + if ($composer->getPackageLock()->isLocked()) { $output->writeln('Found lockfile. Reading'); - foreach ($this->getLock()->getLockedPackages() as $package) { - $installer = $this->getComposer()->getInstaller($package->getType()); - if (!$installer->isInstalled($package)) { - $installer->install($package); + $installationManager = $composer->getInstallationManager(); + foreach ($composer->getPackageLock()->getLockedPackages() as $package) { + if (!$installationManager->isPackageInstalled($package)) { + $operation = new Operation\InstallOperation($package, 'lock resolving'); + $installationManager->execute($operation); } } @@ -59,7 +63,7 @@ EOT // creating repository pool $pool = new Pool; - foreach ($this->getComposer()->getRepositories() as $repository) { + foreach ($composer->getRepositoryManager()->getRepositories() as $repository) { $pool->addRepository($repository); } @@ -70,22 +74,23 @@ EOT } // prepare solver - $platform = $this->getComposer()->getRepository('Platform'); - $policy = new DependencyResolver\DefaultPolicy(); - $solver = new DependencyResolver\Solver($policy, $pool, $platform); + $installationManager = $composer->getInstallationManager(); + $localRepo = $composer->getRepositoryManager()->getLocalRepository(); + $policy = new DependencyResolver\DefaultPolicy(); + $solver = new DependencyResolver\Solver($policy, $pool, $localRepo); // solve dependencies and execute operations - $operations = $this->solveDependencies($request, $solver); - foreach ($operations as $operation) { - $operation->execute(); - // TODO: collect installable packages into $installed + foreach ($solver->solve($request) as $operation) { + $installationManager->execute($operation); } - $output->writeln('> Done'); - if (false) { - $config->lock($installed); + $composer->getPackageLock()->lock($localRepo->getPackages()); $output->writeln('> Locked'); } + + $localRepo->write(); + + $output->writeln('> Done'); } } diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index c61a8cdf2..c792cdd5a 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -29,16 +29,12 @@ use Composer\Package\PackageLock; class Application extends BaseApplication { private $composer; - private $package; - private $lock; - public function __construct(Composer $composer, PackageInterface $package, PackageLock $lock) + public function __construct(Composer $composer) { parent::__construct('Composer', Composer::VERSION); $this->composer = $composer; - $this->package = $package; - $this->lock = $lock; } /** @@ -64,22 +60,6 @@ class Application extends BaseApplication return $this->composer; } - /** - * @return PackageInterface - */ - public function getPackage() - { - return $this->package; - } - - /** - * @return PackageLock - */ - public function getLock() - { - return $this->lock; - } - /** * Looks for all *Command files in Composer's Command directory */