Reflect latest refactoring changes in commands
parent
ef71836f30
commit
05ddfde868
37
bin/composer
37
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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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('<info>Found lockfile. Reading</info>');
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue