1
0
Fork 0

Reflect latest refactoring changes in commands

pull/19/head
everzet 2011-09-25 21:00:44 +03:00
parent ef71836f30
commit 05ddfde868
4 changed files with 45 additions and 80 deletions

View File

@ -10,25 +10,34 @@ use Composer\Repository;
use Composer\Package; use Composer\Package;
use Composer\Console\Application as ComposerApplication; use Composer\Console\Application as ComposerApplication;
// initialize installer // initialize repository manager
$installer = new Installer\LibraryInstaller('vendor', $preferSource = true); $rm = new Repository\RepositoryManager();
$installer->setDownloader('git', new Downloader\GitDownloader()); $rm->setLocalRepository(new Repository\FilesystemRepository('.composer/installed.json'));
$installer->setDownloader('pear', new Downloader\PearDownloader()); $rm->setRepository('Platform', new Repository\PlatformRepository());
$installer->setDownloader('zip', new Downloader\ZipDownloader()); $rm->setRepository('Packagist', new Repository\ComposerRepository('http://packagist.org'));
// initialize composer // initialize download manager
$composer = new Composer(); $dm = new Downloader\DownloadManager($preferSource = false);
$composer->setInstaller('library', $installer); $dm->setDownloader('git', new Downloader\GitDownloader());
$composer->setRepository('Platform', new Repository\PlatformRepository()); $dm->setDownloader('pear', new Downloader\PearDownloader());
$composer->setRepository('Packagist', new Repository\ComposerRepository('http://packagist.org')); $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(); $loader = new Package\Loader\JsonLoader();
$package = $loader->load('composer.json'); $package = $loader->load('composer.json');
// initialize lock // initialize composer
$packageLock = new Package\PackageLock('composer.lock'); $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 // run the command application
$application = new ComposerApplication($composer, $package, $packageLock); $application = new ComposerApplication($composer);
$application->run(); $application->run();

View File

@ -34,33 +34,4 @@ abstract class Command extends BaseCommand
{ {
return $this->getApplication()->getComposer(); 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;
}
} }

View File

@ -15,6 +15,7 @@ namespace Composer\Command;
use Composer\DependencyResolver; use Composer\DependencyResolver;
use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Operation;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -44,13 +45,16 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
if ($this->getLock()->isLocked()) { $composer = $this->getComposer();
if ($composer->getPackageLock()->isLocked()) {
$output->writeln('<info>Found lockfile. Reading</info>'); $output->writeln('<info>Found lockfile. Reading</info>');
foreach ($this->getLock()->getLockedPackages() as $package) { $installationManager = $composer->getInstallationManager();
$installer = $this->getComposer()->getInstaller($package->getType()); foreach ($composer->getPackageLock()->getLockedPackages() as $package) {
if (!$installer->isInstalled($package)) { if (!$installationManager->isPackageInstalled($package)) {
$installer->install($package); $operation = new Operation\InstallOperation($package, 'lock resolving');
$installationManager->execute($operation);
} }
} }
@ -59,7 +63,7 @@ EOT
// creating repository pool // creating repository pool
$pool = new Pool; $pool = new Pool;
foreach ($this->getComposer()->getRepositories() as $repository) { foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
$pool->addRepository($repository); $pool->addRepository($repository);
} }
@ -70,22 +74,23 @@ EOT
} }
// prepare solver // prepare solver
$platform = $this->getComposer()->getRepository('Platform'); $installationManager = $composer->getInstallationManager();
$policy = new DependencyResolver\DefaultPolicy(); $localRepo = $composer->getRepositoryManager()->getLocalRepository();
$solver = new DependencyResolver\Solver($policy, $pool, $platform); $policy = new DependencyResolver\DefaultPolicy();
$solver = new DependencyResolver\Solver($policy, $pool, $localRepo);
// solve dependencies and execute operations // solve dependencies and execute operations
$operations = $this->solveDependencies($request, $solver); foreach ($solver->solve($request) as $operation) {
foreach ($operations as $operation) { $installationManager->execute($operation);
$operation->execute();
// TODO: collect installable packages into $installed
} }
$output->writeln('> Done');
if (false) { if (false) {
$config->lock($installed); $composer->getPackageLock()->lock($localRepo->getPackages());
$output->writeln('> Locked'); $output->writeln('> Locked');
} }
$localRepo->write();
$output->writeln('> Done');
} }
} }

View File

@ -29,16 +29,12 @@ use Composer\Package\PackageLock;
class Application extends BaseApplication class Application extends BaseApplication
{ {
private $composer; 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); parent::__construct('Composer', Composer::VERSION);
$this->composer = $composer; $this->composer = $composer;
$this->package = $package;
$this->lock = $lock;
} }
/** /**
@ -64,22 +60,6 @@ class Application extends BaseApplication
return $this->composer; 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 * Looks for all *Command files in Composer's Command directory
*/ */