From 0f9dcc961834ffd6f1d1fe8f140b6b8d440f1cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pluchino?= Date: Mon, 16 Jan 2012 20:44:06 +0100 Subject: [PATCH] Remplace all echo with writeln method of IO --- src/Composer/Command/InstallCommand.php | 2 +- src/Composer/Console/Application.php | 12 +++++++++-- src/Composer/DependencyResolver/Solver.php | 20 +++++++++++-------- src/Composer/Installer/InstallerInstaller.php | 6 ++++-- src/Composer/Installer/LibraryInstaller.php | 8 ++++++-- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index bf8bca726..086108698 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -123,7 +123,7 @@ EOT // prepare solver $installationManager = $composer->getInstallationManager(); $policy = new DependencyResolver\DefaultPolicy(); - $solver = new DependencyResolver\Solver($policy, $pool, $installedRepo); + $solver = new DependencyResolver\Solver($policy, $pool, $installedRepo, $this->getApplication()->getIO()); // solve dependencies $operations = $solver->solve($request); diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 60c8db7c3..2ba59d27b 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -84,6 +84,14 @@ class Application extends BaseApplication return $this->composer; } + /** + * @return IOInterface + */ + public function getIO() + { + return $this->io; + } + /** * Bootstraps a Composer instance * @@ -144,8 +152,8 @@ class Application extends BaseApplication // initialize installation manager $im = new Installer\InstallationManager($vendorDir); - $im->addInstaller(new Installer\LibraryInstaller($vendorDir, $binDir, $dm, $rm->getLocalRepository(), null)); - $im->addInstaller(new Installer\InstallerInstaller($vendorDir, $binDir, $dm, $rm->getLocalRepository(), $im)); + $im->addInstaller(new Installer\LibraryInstaller($vendorDir, $binDir, $dm, $rm->getLocalRepository(), $io, null)); + $im->addInstaller(new Installer\InstallerInstaller($vendorDir, $binDir, $dm, $rm->getLocalRepository(), $io, $im)); // load package $loader = new Package\Loader\RootPackageLoader($rm); diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 2b6498965..9afb231fa 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -12,6 +12,7 @@ namespace Composer\DependencyResolver; +use Composer\IO\IOInterface; use Composer\Repository\RepositoryInterface; use Composer\Package\PackageInterface; use Composer\DependencyResolver\Operation; @@ -55,12 +56,15 @@ class Solver protected $packageToUpdateRule = array(); protected $packageToFeatureRule = array(); - public function __construct(PolicyInterface $policy, Pool $pool, RepositoryInterface $installed) + protected $io; + + public function __construct(PolicyInterface $policy, Pool $pool, RepositoryInterface $installed, IOInterface $io) { $this->policy = $policy; $this->pool = $pool; $this->installed = $installed; $this->rules = new RuleSet; + $this->io = $io; } /** @@ -2046,26 +2050,26 @@ class Solver public function printDecisionMap() { - echo "\nDecisionMap: \n"; + $this->io->writeln("\nDecisionMap: "); foreach ($this->decisionMap as $packageId => $level) { if ($packageId === 0) { continue; } if ($level > 0) { - echo ' +' . $this->pool->packageById($packageId) . "\n"; + $this->io->writeln(' +' . $this->pool->packageById($packageId)); } else { - echo ' -' . $this->pool->packageById($packageId) . "\n"; + $this->io->writeln(' -' . $this->pool->packageById($packageId)); } } - echo "\n"; + $this->io->writeln(''); } public function printDecisionQueue() { - echo "DecisionQueue: \n"; + $this->io->writeln("DecisionQueue: "); foreach ($this->decisionQueue as $i => $literal) { - echo ' ' . $literal . ' ' . $this->decisionQueueWhy[$i] . "\n"; + $this->io->writeln(' ' . $literal . ' ' . $this->decisionQueueWhy[$i]); } - echo "\n"; + $this->io->writeln(''); } } diff --git a/src/Composer/Installer/InstallerInstaller.php b/src/Composer/Installer/InstallerInstaller.php index 7c688ee34..520bde273 100644 --- a/src/Composer/Installer/InstallerInstaller.php +++ b/src/Composer/Installer/InstallerInstaller.php @@ -12,6 +12,7 @@ namespace Composer\Installer; +use Composer\IO\IOInterface; use Composer\Autoload\AutoloadGenerator; use Composer\Downloader\DownloadManager; use Composer\Repository\WritableRepositoryInterface; @@ -33,10 +34,11 @@ class InstallerInstaller extends LibraryInstaller * @param string $binDir relative path for binaries * @param DownloadManager $dm download manager * @param WritableRepositoryInterface $repository repository controller + * @param IOInterface $io io instance */ - public function __construct($vendorDir, $binDir, DownloadManager $dm, WritableRepositoryInterface $repository, InstallationManager $im) + public function __construct($vendorDir, $binDir, DownloadManager $dm, WritableRepositoryInterface $repository, IOInterface $io, InstallationManager $im) { - parent::__construct($vendorDir, $binDir, $dm, $repository, 'composer-installer'); + parent::__construct($vendorDir, $binDir, $dm, $repository, $io, 'composer-installer'); $this->installationManager = $im; foreach ($repository->getPackages() as $package) { diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index d9d7ddd76..25f77e73c 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -12,6 +12,7 @@ namespace Composer\Installer; +use Composer\IO\IOInterface; use Composer\Downloader\DownloadManager; use Composer\Repository\WritableRepositoryInterface; use Composer\DependencyResolver\Operation\OperationInterface; @@ -30,6 +31,7 @@ class LibraryInstaller implements InstallerInterface protected $binDir; protected $downloadManager; protected $repository; + protected $io; private $type; private $filesystem; @@ -40,12 +42,14 @@ class LibraryInstaller implements InstallerInterface * @param string $binDir relative path for binaries * @param DownloadManager $dm download manager * @param WritableRepositoryInterface $repository repository controller + * @param IOInterface $io io instance * @param string $type package type that this installer handles */ - public function __construct($vendorDir, $binDir, DownloadManager $dm, WritableRepositoryInterface $repository, $type = 'library') + public function __construct($vendorDir, $binDir, DownloadManager $dm, WritableRepositoryInterface $repository, IOInterface $io, $type = 'library') { $this->downloadManager = $dm; $this->repository = $repository; + $this->io = $io; $this->type = $type; $this->filesystem = new Filesystem(); @@ -136,7 +140,7 @@ class LibraryInstaller implements InstallerInterface foreach ($package->getBinaries() as $bin) { $link = $this->binDir.'/'.basename($bin); if (file_exists($link)) { - echo 'Skipped installation of '.$bin.' for package '.$package->getName().', name conflicts with an existing file'.PHP_EOL; + $this->io->writeln('Skipped installation of '.$bin.' for package '.$package->getName().', name conflicts with an existing file'); continue; } $bin = $this->getInstallPath($package).'/'.$bin;