diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php
index 6c12a7a72..2b7fd4846 100644
--- a/src/Composer/Command/ConfigCommand.php
+++ b/src/Composer/Command/ConfigCommand.php
@@ -464,6 +464,7 @@ EOT
protected function listConfiguration(array $contents, array $rawContents, OutputInterface $output, $k = null)
{
$origK = $k;
+ $io = $this->getIO();
foreach ($contents as $key => $value) {
if ($k === null && !in_array($key, array('config', 'repositories'))) {
continue;
@@ -498,9 +499,9 @@ EOT
}
if (is_string($rawVal) && $rawVal != $value) {
- $this->getIO()->write('[' . $k . $key . '] ' . $rawVal . ' (' . $value . ')');
+ $io->write('[' . $k . $key . '] ' . $rawVal . ' (' . $value . ')');
} else {
- $this->getIO()->write('[' . $k . $key . '] ' . $value . '');
+ $io->write('[' . $k . $key . '] ' . $value . '');
}
}
}
diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php
index d6c68a94f..54cd63538 100644
--- a/src/Composer/Command/CreateProjectCommand.php
+++ b/src/Composer/Command/CreateProjectCommand.php
@@ -100,16 +100,17 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = Factory::createConfig();
+ $io = $this->getIO();
$this->updatePreferredOptions($config, $input, $preferSource, $preferDist, true);
if ($input->getOption('no-custom-installers')) {
- $this->getIO()->writeError('You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.');
+ $io->writeError('You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.');
$input->setOption('no-plugins', true);
}
return $this->installProject(
- $this->getIO(),
+ $io,
$config,
$input->getArgument('package'),
$input->getArgument('directory'),
diff --git a/src/Composer/Command/DependsCommand.php b/src/Composer/Command/DependsCommand.php
index 97b9d0f39..b4017c2fe 100644
--- a/src/Composer/Command/DependsCommand.php
+++ b/src/Composer/Command/DependsCommand.php
@@ -81,6 +81,7 @@ EOT
$messages = array();
$outputPackages = array();
+ $io = $this->getIO();
foreach ($repo->getPackages() as $package) {
foreach ($types as $type) {
foreach ($package->{'get'.$linkTypes[$type][0]}() as $link) {
@@ -96,9 +97,9 @@ EOT
if ($messages) {
sort($messages);
- $this->getIO()->write($messages);
+ $io->write($messages);
} else {
- $this->getIO()->writeError('There is no installed package depending on "'.$needle.'".');
+ $io->writeError('There is no installed package depending on "'.$needle.'".');
}
}
}
diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php
index 860f85948..30d38b0c1 100644
--- a/src/Composer/Command/DiagnoseCommand.php
+++ b/src/Composer/Command/DiagnoseCommand.php
@@ -57,12 +57,13 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer(false);
+ $io = $this->getIO();
if ($composer) {
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'diagnose', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
- $this->getIO()->write('Checking composer.json: ', false);
+ $io->write('Checking composer.json: ', false);
$this->outputResult($this->checkComposerSchema());
}
@@ -72,44 +73,44 @@ EOT
$config = Factory::createConfig();
}
- $this->rfs = new RemoteFilesystem($this->getIO(), $config);
- $this->process = new ProcessExecutor($this->getIO());
+ $this->rfs = new RemoteFilesystem($io, $config);
+ $this->process = new ProcessExecutor($io);
- $this->getIO()->write('Checking platform settings: ', false);
+ $io->write('Checking platform settings: ', false);
$this->outputResult($this->checkPlatform());
- $this->getIO()->write('Checking git settings: ', false);
+ $io->write('Checking git settings: ', false);
$this->outputResult($this->checkGit());
- $this->getIO()->write('Checking http connectivity to packagist: ', false);
+ $io->write('Checking http connectivity to packagist: ', false);
$this->outputResult($this->checkHttp('http'));
- $this->getIO()->write('Checking https connectivity to packagist: ', false);
+ $io->write('Checking https connectivity to packagist: ', false);
$this->outputResult($this->checkHttp('https'));
$opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org'));
if (!empty($opts['http']['proxy'])) {
- $this->getIO()->write('Checking HTTP proxy: ', false);
+ $io->write('Checking HTTP proxy: ', false);
$this->outputResult($this->checkHttpProxy());
- $this->getIO()->write('Checking HTTP proxy support for request_fulluri: ', false);
+ $io->write('Checking HTTP proxy support for request_fulluri: ', false);
$this->outputResult($this->checkHttpProxyFullUriRequestParam());
- $this->getIO()->write('Checking HTTPS proxy support for request_fulluri: ', false);
+ $io->write('Checking HTTPS proxy support for request_fulluri: ', false);
$this->outputResult($this->checkHttpsProxyFullUriRequestParam());
}
if ($oauth = $config->get('github-oauth')) {
foreach ($oauth as $domain => $token) {
- $this->getIO()->write('Checking '.$domain.' oauth access: ', false);
+ $io->write('Checking '.$domain.' oauth access: ', false);
$this->outputResult($this->checkGithubOauth($domain, $token));
}
} else {
- $this->getIO()->write('Checking github.com rate limit: ', false);
+ $io->write('Checking github.com rate limit: ', false);
try {
$rate = $this->getGithubRateLimit('github.com');
$this->outputResult(true);
if (10 > $rate['remaining']) {
- $this->getIO()->write('WARNING');
- $this->getIO()->write(sprintf(
+ $io->write('WARNING');
+ $io->write(sprintf(
'Github has a rate limit on their API. '
. 'You currently have %u '
. 'out of %u requests left.' . PHP_EOL
@@ -128,10 +129,10 @@ EOT
}
}
- $this->getIO()->write('Checking disk free space: ', false);
+ $io->write('Checking disk free space: ', false);
$this->outputResult($this->checkDiskSpace($config));
- $this->getIO()->write('Checking composer version: ', false);
+ $io->write('Checking composer version: ', false);
$this->outputResult($this->checkVersion());
return $this->failures;
@@ -322,15 +323,16 @@ EOT
*/
private function outputResult($result)
{
+ $io = $this->getIO();
if (true === $result) {
- $this->getIO()->write('OK');
+ $io->write('OK');
} else {
$this->failures++;
- $this->getIO()->write('FAIL');
+ $io->write('FAIL');
if ($result instanceof \Exception) {
- $this->getIO()->write('['.get_class($result).'] '.$result->getMessage());
+ $io->write('['.get_class($result).'] '.$result->getMessage());
} elseif ($result) {
- $this->getIO()->write(trim($result));
+ $io->write(trim($result));
}
}
}
diff --git a/src/Composer/Command/HomeCommand.php b/src/Composer/Command/HomeCommand.php
index e742cadf5..fff1f86eb 100644
--- a/src/Composer/Command/HomeCommand.php
+++ b/src/Composer/Command/HomeCommand.php
@@ -57,6 +57,7 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$repos = $this->initializeRepos();
+ $io = $this->getIO();
$return = 0;
foreach ($input->getArgument('packages') as $packageName) {
@@ -74,12 +75,12 @@ EOT
if (!$packageExists) {
$return = 1;
- $this->getIO()->writeError('Package '.$packageName.' not found');
+ $io->writeError('Package '.$packageName.' not found');
}
if (!$handled) {
$return = 1;
- $this->getIO()->writeError(''.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.'');
+ $io->writeError(''.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.'');
}
}
diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php
index 971477306..112c10129 100644
--- a/src/Composer/Command/InitCommand.php
+++ b/src/Composer/Command/InitCommand.php
@@ -106,11 +106,12 @@ EOT
$file = new JsonFile('composer.json');
$json = $file->encode($options);
+ $io = $this->getIO();
if ($input->isInteractive()) {
- $this->getIO()->writeError(array('', $json, ''));
- if (!$this->getIO()->askConfirmation('Do you confirm generation [yes]? ', true)) {
- $this->getIO()->writeError('Command aborted');
+ $io->writeError(array('', $json, ''));
+ if (!$io->askConfirmation('Do you confirm generation [yes]? ', true)) {
+ $io->writeError('Command aborted');
return 1;
}
@@ -128,7 +129,7 @@ EOT
if (!$this->hasVendorIgnore($ignoreFile)) {
$question = 'Would you like the vendor directory added to your .gitignore [yes]? ';
- if ($this->getIO()->askConfirmation($question, true)) {
+ if ($io->askConfirmation($question, true)) {
$this->addVendorIgnore($ignoreFile);
}
}
@@ -141,17 +142,17 @@ EOT
protected function interact(InputInterface $input, OutputInterface $output)
{
$git = $this->getGitConfig();
-
+ $io = $this->getIO();
$formatter = $this->getHelperSet()->get('formatter');
- $this->getIO()->writeError(array(
+ $io->writeError(array(
'',
$formatter->formatBlock('Welcome to the Composer config generator', 'bg=blue;fg=white', true),
''
));
// namespace
- $this->getIO()->writeError(array(
+ $io->writeError(array(
'',
'This command will guide you through creating your composer.json config.',
'',
@@ -181,7 +182,7 @@ EOT
}
}
- $name = $this->getIO()->askAndValidate(
+ $name = $io->askAndValidate(
'Package name (/) ['.$name.']: ',
function ($value) use ($name) {
if (null === $value) {
@@ -202,7 +203,7 @@ EOT
$input->setOption('name', $name);
$description = $input->getOption('description') ?: false;
- $description = $this->getIO()->ask(
+ $description = $io->ask(
'Description ['.$description.']: ',
$description
);
@@ -215,7 +216,7 @@ EOT
}
$self = $this;
- $author = $this->getIO()->askAndValidate(
+ $author = $io->askAndValidate(
'Author ['.$author.']: ',
function ($value) use ($self, $author) {
$value = $value ?: $author;
@@ -229,7 +230,7 @@ EOT
$input->setOption('author', $author);
$minimumStability = $input->getOption('stability') ?: null;
- $minimumStability = $this->getIO()->askAndValidate(
+ $minimumStability = $io->askAndValidate(
'Minimum Stability ['.$minimumStability.']: ',
function ($value) use ($self, $minimumStability) {
if (null === $value) {
@@ -251,31 +252,31 @@ EOT
$input->setOption('stability', $minimumStability);
$type = $input->getOption('type') ?: false;
- $type = $this->getIO()->ask(
+ $type = $io->ask(
'Package Type ['.$type.']: ',
$type
);
$input->setOption('type', $type);
$license = $input->getOption('license') ?: false;
- $license = $this->getIO()->ask(
+ $license = $io->ask(
'License ['.$license.']: ',
$license
);
$input->setOption('license', $license);
- $this->getIO()->writeError(array('', 'Define your dependencies.', ''));
+ $io->writeError(array('', 'Define your dependencies.', ''));
$question = 'Would you like to define your dependencies (require) interactively [yes]? ';
$requirements = array();
- if ($this->getIO()->askConfirmation($question, true)) {
+ if ($io->askConfirmation($question, true)) {
$requirements = $this->determineRequirements($input, $output, $input->getOption('require'));
}
$input->setOption('require', $requirements);
$question = 'Would you like to define your dev dependencies (require-dev) interactively [yes]? ';
$devRequirements = array();
- if ($this->getIO()->askConfirmation($question, true)) {
+ if ($io->askConfirmation($question, true)) {
$devRequirements = $this->determineRequirements($input, $output, $input->getOption('require-dev'));
}
$input->setOption('require-dev', $devRequirements);
@@ -325,6 +326,7 @@ EOT
if ($requires) {
$requires = $this->normalizeRequirements($requires);
$result = array();
+ $io = $this->getIO();
foreach ($requires as $requirement) {
if (!isset($requirement['version'])) {
@@ -332,7 +334,7 @@ EOT
$version = $this->findBestVersionForPackage($input, $requirement['name']);
$requirement['version'] = $version;
- $this->getIO()->writeError(sprintf(
+ $io->writeError(sprintf(
'Using version %s for %s',
$requirement['version'],
$requirement['name']
@@ -346,7 +348,8 @@ EOT
}
$versionParser = new VersionParser();
- while (null !== $package = $this->getIO()->ask('Search for a package: ')) {
+ $io = $this->getIO();
+ while (null !== $package = $io->ask('Search for a package: ')) {
$matches = $this->findPackages($package);
if (count($matches)) {
@@ -362,14 +365,14 @@ EOT
// no match, prompt which to pick
if (!$exactMatch) {
- $this->getIO()->writeError(array(
+ $io->writeError(array(
'',
sprintf('Found %s packages matching %s', count($matches), $package),
''
));
- $this->getIO()->writeError($choices);
- $this->getIO()->writeError('');
+ $io->writeError($choices);
+ $io->writeError('');
$validator = function ($selection) use ($matches, $versionParser) {
if ('' === $selection) {
@@ -399,7 +402,7 @@ EOT
throw new \Exception('Not a valid selection');
};
- $package = $this->getIO()->askAndValidate(
+ $package = $io->askAndValidate(
'Enter package # to add, or the complete package name if it is not listed: ',
$validator,
3,
@@ -415,7 +418,7 @@ EOT
return $input ?: false;
};
- $constraint = $this->getIO()->askAndValidate(
+ $constraint = $io->askAndValidate(
'Enter the version constraint to require (or leave blank to use the latest version): ',
$validator,
3,
@@ -425,7 +428,7 @@ EOT
if (false === $constraint) {
$constraint = $this->findBestVersionForPackage($input, $package);
- $this->getIO()->writeError(sprintf(
+ $io->writeError(sprintf(
'Using version %s for %s',
$constraint,
$package
diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php
index e548b8d69..b8708611d 100644
--- a/src/Composer/Command/InstallCommand.php
+++ b/src/Composer/Command/InstallCommand.php
@@ -64,24 +64,24 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
+ $io = $this->getIO();
if ($args = $input->getArgument('packages')) {
- $this->getIO()->writeError('Invalid argument '.implode(' ', $args).'. Use "composer require '.implode(' ', $args).'" instead to add packages to your composer.json.');
+ $io->writeError('Invalid argument '.implode(' ', $args).'. Use "composer require '.implode(' ', $args).'" instead to add packages to your composer.json.');
return 1;
}
if ($input->getOption('no-custom-installers')) {
- $this->getIO()->writeError('You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.');
+ $io->writeError('You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.');
$input->setOption('no-plugins', true);
}
if ($input->getOption('dev')) {
- $this->getIO()->writeError('You are using the deprecated option "dev". Dev packages are installed by default now.');
+ $io->writeError('You are using the deprecated option "dev". Dev packages are installed by default now.');
}
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
- $io = $this->getIO();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'install', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php
index 4ba8ed09d..b542c3fe6 100644
--- a/src/Composer/Command/LicensesCommand.php
+++ b/src/Composer/Command/LicensesCommand.php
@@ -62,14 +62,15 @@ EOT
}
ksort($packages);
+ $io = $this->getIO();
switch ($format = $input->getOption('format')) {
case 'text':
- $this->getIO()->write('Name: '.$root->getPrettyName().'');
- $this->getIO()->write('Version: '.$root->getFullPrettyVersion().'');
- $this->getIO()->write('Licenses: '.(implode(', ', $root->getLicense()) ?: 'none').'');
- $this->getIO()->write('Dependencies:');
- $this->getIO()->write('');
+ $io->write('Name: '.$root->getPrettyName().'');
+ $io->write('Version: '.$root->getFullPrettyVersion().'');
+ $io->write('Licenses: '.(implode(', ', $root->getLicense()) ?: 'none').'');
+ $io->write('Dependencies:');
+ $io->write('');
$table = new Table($output);
$table->setStyle('compact');
@@ -94,7 +95,7 @@ EOT
);
}
- $this->getIO()->write(JsonFile::encode(array(
+ $io->write(JsonFile::encode(array(
'name' => $root->getPrettyName(),
'version' => $root->getFullPrettyVersion(),
'license' => $root->getLicense(),
diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php
index 3779b09e9..fdbd146bb 100644
--- a/src/Composer/Command/RemoveCommand.php
+++ b/src/Composer/Command/RemoveCommand.php
@@ -68,19 +68,20 @@ EOT
$type = $input->getOption('dev') ? 'require-dev' : 'require';
$altType = !$input->getOption('dev') ? 'require-dev' : 'require';
+ $io = $this->getIO();
foreach ($packages as $package) {
if (isset($composer[$type][$package])) {
$json->removeLink($type, $package);
} elseif (isset($composer[$altType][$package])) {
- $this->getIO()->writeError(''.$package.' could not be found in '.$type.' but it is present in '.$altType.'');
- if ($this->getIO()->isInteractive()) {
- if ($this->getIO()->askConfirmation('Do you want to remove it from '.$altType.' [yes]? ', true)) {
+ $io->writeError(''.$package.' could not be found in '.$type.' but it is present in '.$altType.'');
+ if ($io->isInteractive()) {
+ if ($io->askConfirmation('Do you want to remove it from '.$altType.' [yes]? ', true)) {
$json->removeLink($altType, $package);
}
}
} else {
- $this->getIO()->writeError(''.$package.' is not required in your composer.json and has not been removed');
+ $io->writeError(''.$package.' is not required in your composer.json and has not been removed');
}
}
@@ -91,7 +92,6 @@ EOT
// Update packages
$composer = $this->getComposer();
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
- $io = $this->getIO();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'remove', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
@@ -110,7 +110,7 @@ EOT
$status = $install->run();
if ($status !== 0) {
- $this->getIO()->writeError("\n".'Removal failed, reverting '.$file.' to its original content.');
+ $io->writeError("\n".'Removal failed, reverting '.$file.' to its original content.');
file_put_contents($jsonFile->getPath(), $composerBackup);
}
diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php
index 82401ffb2..6be23102a 100644
--- a/src/Composer/Command/RequireCommand.php
+++ b/src/Composer/Command/RequireCommand.php
@@ -64,20 +64,21 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$file = Factory::getComposerFile();
+ $io = $this->getIO();
$newlyCreated = !file_exists($file);
if (!file_exists($file) && !file_put_contents($file, "{\n}\n")) {
- $this->getIO()->writeError(''.$file.' could not be created.');
+ $io->writeError(''.$file.' could not be created.');
return 1;
}
if (!is_readable($file)) {
- $this->getIO()->writeError(''.$file.' is not readable.');
+ $io->writeError(''.$file.' is not readable.');
return 1;
}
if (!is_writable($file)) {
- $this->getIO()->writeError(''.$file.' is not writable.');
+ $io->writeError(''.$file.' is not writable.');
return 1;
}
@@ -126,7 +127,7 @@ EOT
$json->write($composerDefinition);
}
- $this->getIO()->writeError(''.$file.' has been '.($newlyCreated ? 'created' : 'updated').'');
+ $io->writeError(''.$file.' has been '.($newlyCreated ? 'created' : 'updated').'');
if ($input->getOption('no-update')) {
return 0;
@@ -137,7 +138,6 @@ EOT
$this->resetComposer();
$composer = $this->getComposer();
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
- $io = $this->getIO();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'require', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
@@ -158,10 +158,10 @@ EOT
$status = $install->run();
if ($status !== 0) {
if ($newlyCreated) {
- $this->getIO()->writeError("\n".'Installation failed, deleting '.$file.'.');
+ $io->writeError("\n".'Installation failed, deleting '.$file.'.');
unlink($json->getPath());
} else {
- $this->getIO()->writeError("\n".'Installation failed, reverting '.$file.' to its original content.');
+ $io->writeError("\n".'Installation failed, reverting '.$file.' to its original content.');
file_put_contents($json->getPath(), $composerBackup);
}
}
diff --git a/src/Composer/Command/RunScriptCommand.php b/src/Composer/Command/RunScriptCommand.php
index 8b5b13d2a..5ad87bf40 100644
--- a/src/Composer/Command/RunScriptCommand.php
+++ b/src/Composer/Command/RunScriptCommand.php
@@ -104,9 +104,10 @@ EOT
return 0;
}
- $this->getIO()->writeError('scripts:');
+ $io = $this->getIO();
+ $io->writeError('scripts:');
foreach ($scripts as $name => $script) {
- $this->getIO()->write(' ' . $name);
+ $io->write(' ' . $name);
}
return 0;
diff --git a/src/Composer/Command/SearchCommand.php b/src/Composer/Command/SearchCommand.php
index 54990f30d..e636fc4d0 100644
--- a/src/Composer/Command/SearchCommand.php
+++ b/src/Composer/Command/SearchCommand.php
@@ -56,13 +56,14 @@ EOT
{
// init repos
$platformRepo = new PlatformRepository;
+ $io = $this->getIO();
if ($composer = $this->getComposer(false)) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
- $defaultRepos = Factory::createDefaultRepositories($this->getIO());
- $this->getIO()->writeError('No composer.json found in the current directory, showing packages from ' . implode(', ', array_keys($defaultRepos)));
+ $defaultRepos = Factory::createDefaultRepositories($io);
+ $io->writeError('No composer.json found in the current directory, showing packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = $platformRepo;
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
}
@@ -78,7 +79,7 @@ EOT
$results = $repos->search(implode(' ', $input->getArgument('tokens')), $flags);
foreach ($results as $result) {
- $this->getIO()->write($result['name'] . (isset($result['description']) ? ' '. $result['description'] : ''));
+ $io->write($result['name'] . (isset($result['description']) ? ' '. $result['description'] : ''));
}
}
}
diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php
index e4e96e8f4..35c1b85ce 100644
--- a/src/Composer/Command/SelfUpdateCommand.php
+++ b/src/Composer/Command/SelfUpdateCommand.php
@@ -60,7 +60,8 @@ EOT
{
$baseUrl = (extension_loaded('openssl') ? 'https' : 'http') . '://' . self::HOMEPAGE;
$config = Factory::createConfig();
- $remoteFilesystem = new RemoteFilesystem($this->getIO(), $config);
+ $io = $this->getIO();
+ $remoteFilesystem = new RemoteFilesystem($io, $config);
$cacheDir = $config->get('cache-dir');
$rollbackDir = $config->get('home');
$localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
@@ -84,13 +85,13 @@ EOT
$updateVersion = $input->getArgument('version') ?: $latestVersion;
if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
- $this->getIO()->writeError('You can not update to a specific SHA-1 as those phars are not available for download');
+ $io->writeError('You can not update to a specific SHA-1 as those phars are not available for download');
return 1;
}
if (Composer::VERSION === $updateVersion) {
- $this->getIO()->writeError('You are already using composer version '.$updateVersion.'.');
+ $io->writeError('You are already using composer version '.$updateVersion.'.');
return 0;
}
@@ -104,11 +105,11 @@ EOT
self::OLD_INSTALL_EXT
);
- $this->getIO()->writeError(sprintf("Updating to version %s.", $updateVersion));
+ $io->writeError(sprintf("Updating to version %s.", $updateVersion));
$remoteFilename = $baseUrl . (preg_match('{^[0-9a-f]{40}$}', $updateVersion) ? '/composer.phar' : "/download/{$updateVersion}/composer.phar");
$remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename, !$input->getOption('no-progress'));
if (!file_exists($tempFilename)) {
- $this->getIO()->writeError('The download of the new composer version failed for an unexpected reason');
+ $io->writeError('The download of the new composer version failed for an unexpected reason');
return 1;
}
@@ -120,22 +121,22 @@ EOT
$fs = new Filesystem;
foreach ($finder as $file) {
$file = (string) $file;
- $this->getIO()->writeError('Removing: '.$file.'');
+ $io->writeError('Removing: '.$file.'');
$fs->remove($file);
}
}
if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
- $this->getIO()->writeError('The file is corrupted ('.$err->getMessage().').');
- $this->getIO()->writeError('Please re-run the self-update command to try again.');
+ $io->writeError('The file is corrupted ('.$err->getMessage().').');
+ $io->writeError('Please re-run the self-update command to try again.');
return 1;
}
if (file_exists($backupFile)) {
- $this->getIO()->writeError('Use composer self-update --rollback to return to version '.Composer::VERSION);
+ $io->writeError('Use composer self-update --rollback to return to version '.Composer::VERSION);
} else {
- $this->getIO()->writeError('A backup of the current version could not be written to '.$backupFile.', no rollback possible');
+ $io->writeError('A backup of the current version could not be written to '.$backupFile.', no rollback possible');
}
}
@@ -160,9 +161,10 @@ EOT
}
$oldFile = $rollbackDir . "/{$rollbackVersion}" . self::OLD_INSTALL_EXT;
- $this->getIO()->writeError(sprintf("Rolling back to version %s.", $rollbackVersion));
+ $io = $this->getIO();
+ $io->writeError(sprintf("Rolling back to version %s.", $rollbackVersion));
if ($err = $this->setLocalPhar($localFilename, $oldFile)) {
- $this->getIO()->writeError('The backup file was corrupted ('.$err->getMessage().') and has been removed.');
+ $io->writeError('The backup file was corrupted ('.$err->getMessage().') and has been removed.');
return 1;
}
diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php
index 92811f07a..30d8797c8 100644
--- a/src/Composer/Command/ShowCommand.php
+++ b/src/Composer/Command/ShowCommand.php
@@ -71,6 +71,7 @@ EOT
$platformRepo = new PlatformRepository;
$composer = $this->getComposer(false);
+ $io = $this->getIO();
if ($input->getOption('self')) {
$package = $this->getComposer()->getPackage();
$repos = $installedRepo = new ArrayRepository(array($package));
@@ -83,17 +84,17 @@ EOT
if ($composer) {
$repos = new CompositeRepository($composer->getRepositoryManager()->getRepositories());
} else {
- $defaultRepos = Factory::createDefaultRepositories($this->getIO());
+ $defaultRepos = Factory::createDefaultRepositories($io);
$repos = new CompositeRepository($defaultRepos);
- $this->getIO()->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
+ $io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
}
} elseif ($composer) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
- $defaultRepos = Factory::createDefaultRepositories($this->getIO());
- $this->getIO()->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
+ $defaultRepos = Factory::createDefaultRepositories($io);
+ $io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = $platformRepo;
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
}
@@ -120,9 +121,9 @@ EOT
$this->printLinks($package, 'requires');
$this->printLinks($package, 'devRequires', 'requires (dev)');
if ($package->getSuggests()) {
- $this->getIO()->write("\nsuggests");
+ $io->write("\nsuggests");
foreach ($package->getSuggests() as $suggested => $reason) {
- $this->getIO()->write($suggested . ' ' . $reason . '');
+ $io->write($suggested . ' ' . $reason . '');
}
}
$this->printLinks($package, 'provides');
@@ -173,7 +174,7 @@ EOT
foreach (array('platform:' => true, 'available:' => false, 'installed:' => true) as $type => $showVersion) {
if (isset($packages[$type])) {
if ($tree) {
- $this->getIO()->write($type);
+ $io->write($type);
}
ksort($packages[$type]);
@@ -197,7 +198,7 @@ EOT
}
if ($input->getOption('path') && null === $composer) {
- $this->getIO()->writeError('No composer.json found in the current directory, disabling "path" option');
+ $io->writeError('No composer.json found in the current directory, disabling "path" option');
$input->setOption('path', false);
}
@@ -228,10 +229,10 @@ EOT
} else {
$output->write($indent . $package);
}
- $this->getIO()->write('');
+ $io->write('');
}
if ($tree) {
- $this->getIO()->write('');
+ $io->write('');
}
}
}
@@ -291,53 +292,54 @@ EOT
*/
protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo)
{
- $this->getIO()->write('name : ' . $package->getPrettyName());
- $this->getIO()->write('descrip. : ' . $package->getDescription());
- $this->getIO()->write('keywords : ' . join(', ', $package->getKeywords() ?: array()));
+ $io = $this->getIO();
+ $io->write('name : ' . $package->getPrettyName());
+ $io->write('descrip. : ' . $package->getDescription());
+ $io->write('keywords : ' . join(', ', $package->getKeywords() ?: array()));
$this->printVersions($package, $versions, $installedRepo);
- $this->getIO()->write('type : ' . $package->getType());
+ $io->write('type : ' . $package->getType());
$this->printLicenses($package);
- $this->getIO()->write('source : ' . sprintf('[%s] %s %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
- $this->getIO()->write('dist : ' . sprintf('[%s] %s %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
- $this->getIO()->write('names : ' . implode(', ', $package->getNames()));
+ $io->write('source : ' . sprintf('[%s] %s %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
+ $io->write('dist : ' . sprintf('[%s] %s %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
+ $io->write('names : ' . implode(', ', $package->getNames()));
if ($package->isAbandoned()) {
$replacement = ($package->getReplacementPackage() !== null)
? ' The author suggests using the ' . $package->getReplacementPackage(). ' package instead.'
: null;
- $this->getIO()->writeError(
+ $io->writeError(
sprintf('Attention: This package is abandoned and no longer maintained.%s', $replacement)
);
}
if ($package->getSupport()) {
- $this->getIO()->write("\nsupport");
+ $io->write("\nsupport");
foreach ($package->getSupport() as $type => $value) {
- $this->getIO()->write('' . $type . ' : '.$value);
+ $io->write('' . $type . ' : '.$value);
}
}
if ($package->getAutoload()) {
- $this->getIO()->write("\nautoload");
+ $io->write("\nautoload");
foreach ($package->getAutoload() as $type => $autoloads) {
- $this->getIO()->write('' . $type . '');
+ $io->write('' . $type . '');
if ($type === 'psr-0') {
foreach ($autoloads as $name => $path) {
- $this->getIO()->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
+ $io->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
}
} elseif ($type === 'psr-4') {
foreach ($autoloads as $name => $path) {
- $this->getIO()->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
+ $io->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
}
} elseif ($type === 'classmap') {
- $this->getIO()->write(implode(', ', $autoloads));
+ $io->write(implode(', ', $autoloads));
}
}
if ($package->getIncludePaths()) {
- $this->getIO()->write('include-path');
- $this->getIO()->write(implode(', ', $package->getIncludePaths()));
+ $io->write('include-path');
+ $io->write(implode(', ', $package->getIncludePaths()));
}
}
}
@@ -374,11 +376,12 @@ EOT
protected function printLinks(CompletePackageInterface $package, $linkType, $title = null)
{
$title = $title ?: $linkType;
+ $io = $this->getIO();
if ($links = $package->{'get'.ucfirst($linkType)}()) {
- $this->getIO()->write("\n" . $title . "");
+ $io->write("\n" . $title . "");
foreach ($links as $link) {
- $this->getIO()->write($link->getTarget() . ' ' . $link->getPrettyConstraint() . '');
+ $io->write($link->getTarget() . ' ' . $link->getPrettyConstraint() . '');
}
}
}
@@ -393,6 +396,7 @@ EOT
$spdxLicenses = new SpdxLicenses();
$licenses = $package->getLicense();
+ $io = $this->getIO();
foreach ($licenses as $licenseId) {
$license = $spdxLicenses->getLicenseByIdentifier($licenseId); // keys: 0 fullname, 1 osi, 2 url
@@ -408,7 +412,7 @@ EOT
}
}
- $this->getIO()->write('license : ' . $out);
+ $io->write('license : ' . $out);
}
}
}
diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php
index f17124226..7455e84b8 100644
--- a/src/Composer/Command/StatusCommand.php
+++ b/src/Composer/Command/StatusCommand.php
@@ -60,6 +60,7 @@ EOT
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_STATUS_CMD, true);
$errors = array();
+ $io = $this->getIO();
// list packages
foreach ($installedRepo->getPackages() as $package) {
@@ -80,9 +81,9 @@ EOT
// output errors/warnings
if (!$errors) {
- $this->getIO()->writeError('No local changes');
+ $io->writeError('No local changes');
} else {
- $this->getIO()->writeError('You have changes in the following dependencies:');
+ $io->writeError('You have changes in the following dependencies:');
}
foreach ($errors as $path => $changes) {
@@ -90,15 +91,15 @@ EOT
$indentedChanges = implode("\n", array_map(function ($line) {
return ' ' . ltrim($line);
}, explode("\n", $changes)));
- $this->getIO()->write(''.$path.':');
- $this->getIO()->write($indentedChanges);
+ $io->write(''.$path.':');
+ $io->write($indentedChanges);
} else {
- $this->getIO()->write($path);
+ $io->write($path);
}
}
if ($errors && !$input->getOption('verbose')) {
- $this->getIO()->writeError('Use --verbose (-v) to see modified files');
+ $io->writeError('Use --verbose (-v) to see modified files');
}
// Dispatch post-status-command
diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php
index 579236143..32968a56c 100644
--- a/src/Composer/Command/UpdateCommand.php
+++ b/src/Composer/Command/UpdateCommand.php
@@ -74,18 +74,18 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
+ $io = $this->getIO();
if ($input->getOption('no-custom-installers')) {
- $this->getIO()->writeError('You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.');
+ $io->writeError('You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.');
$input->setOption('no-plugins', true);
}
if ($input->getOption('dev')) {
- $this->getIO()->writeError('You are using the deprecated option "dev". Dev packages are installed by default now.');
+ $io->writeError('You are using the deprecated option "dev". Dev packages are installed by default now.');
}
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
- $io = $this->getIO();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'update', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php
index 8a1595a04..a26f1a868 100644
--- a/src/Composer/Command/ValidateCommand.php
+++ b/src/Composer/Command/ValidateCommand.php
@@ -58,19 +58,20 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument('file');
+ $io = $this->getIO();
if (!file_exists($file)) {
- $this->getIO()->writeError('' . $file . ' not found.');
+ $io->writeError('' . $file . ' not found.');
return 1;
}
if (!is_readable($file)) {
- $this->getIO()->writeError('' . $file . ' is not readable.');
+ $io->writeError('' . $file . ' is not readable.');
return 1;
}
- $validator = new ConfigValidator($this->getIO());
+ $validator = new ConfigValidator($io);
$checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL;
$checkPublish = !$input->getOption('no-check-publish');
list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll);
@@ -78,7 +79,7 @@ EOT
$checkLock = !$input->getOption('no-check-lock');
$lockErrors = array();
- $composer = Factory::create($this->getIO(), $file);
+ $composer = Factory::create($io, $file);
$locker = $composer->getLocker();
if ($locker->isLocked() && !$locker->isFresh()) {
$lockErrors[] = 'The lock file is not up to date with the latest changes in composer.json.';
@@ -86,16 +87,16 @@ EOT
// output errors/warnings
if (!$errors && !$publishErrors && !$warnings) {
- $this->getIO()->write('' . $file . ' is valid');
+ $io->write('' . $file . ' is valid');
} elseif (!$errors && !$publishErrors) {
- $this->getIO()->writeError('' . $file . ' is valid, but with a few warnings');
- $this->getIO()->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema');
+ $io->writeError('' . $file . ' is valid, but with a few warnings');
+ $io->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema');
} elseif (!$errors) {
- $this->getIO()->writeError('' . $file . ' is valid for simple usage with composer but has');
- $this->getIO()->writeError('strict errors that make it unable to be published as a package:');
- $this->getIO()->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema');
+ $io->writeError('' . $file . ' is valid for simple usage with composer but has');
+ $io->writeError('strict errors that make it unable to be published as a package:');
+ $io->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema');
} else {
- $this->getIO()->writeError('' . $file . ' is invalid, the following errors/warnings were found:');
+ $io->writeError('' . $file . ' is invalid, the following errors/warnings were found:');
}
$messages = array(
@@ -119,7 +120,7 @@ EOT
foreach ($messages as $style => $msgs) {
foreach ($msgs as $msg) {
- $this->getIO()->writeError('<' . $style . '>' . $msg . '' . $style . '>');
+ $io->writeError('<' . $style . '>' . $msg . '' . $style . '>');
}
}
diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php
index 91ad1f9d4..84e03f754 100644
--- a/src/Composer/Console/Application.php
+++ b/src/Composer/Console/Application.php
@@ -89,9 +89,10 @@ class Application extends BaseApplication
{
$this->io = new ConsoleIO($input, $output, $this->getHelperSet());
ErrorHandler::register($this->io);
+ $io = $this->getIO();
if (PHP_VERSION_ID < 50302) {
- $this->getIO()->writeError('Composer only officially supports PHP 5.3.2 and above, you will most likely encounter problems with your PHP '.PHP_VERSION.', upgrading is strongly recommended.');
+ $io->writeError('Composer only officially supports PHP 5.3.2 and above, you will most likely encounter problems with your PHP '.PHP_VERSION.', upgrading is strongly recommended.');
}
if (defined('COMPOSER_DEV_WARNING_TIME')) {
@@ -104,7 +105,7 @@ class Application extends BaseApplication
}
if ($commandName !== 'self-update' && $commandName !== 'selfupdate') {
if (time() > COMPOSER_DEV_WARNING_TIME) {
- $this->getIO()->writeError(sprintf('Warning: This development build of composer is over 60 days old. It is recommended to update it by running "%s self-update" to get the latest version.', $_SERVER['PHP_SELF']));
+ $io->writeError(sprintf('Warning: This development build of composer is over 60 days old. It is recommended to update it by running "%s self-update" to get the latest version.', $_SERVER['PHP_SELF']));
}
}
}
@@ -117,8 +118,8 @@ class Application extends BaseApplication
if ($newWorkDir = $this->getNewWorkingDir($input)) {
$oldWorkingDir = getcwd();
chdir($newWorkDir);
- if ($this->getIO()->isDebug() >= 4) {
- $this->getIO()->writeError('Changed CWD to ' . getcwd());
+ if ($io->isDebug() >= 4) {
+ $io->writeError('Changed CWD to ' . getcwd());
}
}
@@ -129,7 +130,7 @@ class Application extends BaseApplication
foreach ($composer['scripts'] as $script => $dummy) {
if (!defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) {
if ($this->has($script)) {
- $this->getIO()->writeError('A script named '.$script.' would override a native Composer function and has been skipped');
+ $io->writeError('A script named '.$script.' would override a native Composer function and has been skipped');
} else {
$this->add(new Command\ScriptAliasCommand($script));
}
@@ -150,7 +151,7 @@ class Application extends BaseApplication
}
if (isset($startTime)) {
- $this->getIO()->writeError('Memory usage: '.round(memory_get_usage() / 1024 / 1024, 2).'MB (peak: '.round(memory_get_peak_usage() / 1024 / 1024, 2).'MB), time: '.round(microtime(true) - $startTime, 2).'s');
+ $io->writeError('Memory usage: '.round(memory_get_usage() / 1024 / 1024, 2).'MB (peak: '.round(memory_get_peak_usage() / 1024 / 1024, 2).'MB), time: '.round(microtime(true) - $startTime, 2).'s');
}
return $result;
@@ -176,6 +177,8 @@ class Application extends BaseApplication
*/
public function renderException($exception, $output)
{
+ $io = $this->getIO();
+
try {
$composer = $this->getComposer(false, true);
if ($composer) {
@@ -186,20 +189,20 @@ class Application extends BaseApplication
|| (($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree)
|| (($df = @disk_free_space($dir = sys_get_temp_dir())) !== false && $df < $minSpaceFree)
) {
- $this->getIO()->writeError('The disk hosting '.$dir.' is full, this may be the cause of the following exception');
+ $io->writeError('The disk hosting '.$dir.' is full, this may be the cause of the following exception');
}
}
} catch (\Exception $e) {
}
if (defined('PHP_WINDOWS_VERSION_BUILD') && false !== strpos($exception->getMessage(), 'The system cannot find the path specified')) {
- $this->getIO()->writeError('The following exception may be caused by a stale entry in your cmd.exe AutoRun');
- $this->getIO()->writeError('Check https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows- for details');
+ $io->writeError('The following exception may be caused by a stale entry in your cmd.exe AutoRun');
+ $io->writeError('Check https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows- for details');
}
if (false !== strpos($exception->getMessage(), 'fork failed - Cannot allocate memory')) {
- $this->getIO()->writeError('The following exception is caused by a lack of memory and not having swap configured');
- $this->getIO()->writeError('Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details');
+ $io->writeError('The following exception is caused by a lack of memory and not having swap configured');
+ $io->writeError('Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details');
}
if ($output instanceof ConsoleOutputInterface) {