1
0
Fork 0

Merge pull request #4418 from olvlvl/olvlvl-optimize-getio

Optimized this->getIO()
pull/4421/head
Jordi Boggiano 2015-09-14 15:48:45 +01:00
commit 7267b2ed90
18 changed files with 177 additions and 154 deletions

View File

@ -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('[<comment>' . $k . $key . '</comment>] <info>' . $rawVal . ' (' . $value . ')</info>');
$io->write('[<comment>' . $k . $key . '</comment>] <info>' . $rawVal . ' (' . $value . ')</info>');
} else {
$this->getIO()->write('[<comment>' . $k . $key . '</comment>] <info>' . $value . '</info>');
$io->write('[<comment>' . $k . $key . '</comment>] <info>' . $value . '</info>');
}
}
}

View File

@ -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('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$io->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$input->setOption('no-plugins', true);
}
return $this->installProject(
$this->getIO(),
$io,
$config,
$input->getArgument('package'),
$input->getArgument('directory'),

View File

@ -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('<info>There is no installed package depending on "'.$needle.'".</info>');
$io->writeError('<info>There is no installed package depending on "'.$needle.'".</info>');
}
}
}

View File

@ -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>WARNING</warning>');
$this->getIO()->write(sprintf(
$io->write('<warning>WARNING</warning>');
$io->write(sprintf(
'<comment>Github has a rate limit on their API. '
. 'You currently have <options=bold>%u</options=bold> '
. 'out of <options=bold>%u</options=bold> 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('<info>OK</info>');
$io->write('<info>OK</info>');
} else {
$this->failures++;
$this->getIO()->write('<error>FAIL</error>');
$io->write('<error>FAIL</error>');
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));
}
}
}

View File

@ -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('<warning>Package '.$packageName.' not found</warning>');
$io->writeError('<warning>Package '.$packageName.' not found</warning>');
}
if (!$handled) {
$return = 1;
$this->getIO()->writeError('<warning>'.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.'</warning>');
$io->writeError('<warning>'.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.'</warning>');
}
}

View File

@ -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 [<comment>yes</comment>]? ', true)) {
$this->getIO()->writeError('<error>Command aborted</error>');
$io->writeError(array('', $json, ''));
if (!$io->askConfirmation('Do you confirm generation [<comment>yes</comment>]? ', true)) {
$io->writeError('<error>Command aborted</error>');
return 1;
}
@ -128,7 +129,7 @@ EOT
if (!$this->hasVendorIgnore($ignoreFile)) {
$question = 'Would you like the <info>vendor</info> directory added to your <info>.gitignore</info> [<comment>yes</comment>]? ';
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 (<vendor>/<name>) [<comment>'.$name.'</comment>]: ',
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 [<comment>'.$description.'</comment>]: ',
$description
);
@ -215,7 +216,7 @@ EOT
}
$self = $this;
$author = $this->getIO()->askAndValidate(
$author = $io->askAndValidate(
'Author [<comment>'.$author.'</comment>]: ',
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 [<comment>'.$minimumStability.'</comment>]: ',
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 [<comment>'.$type.'</comment>]: ',
$type
);
$input->setOption('type', $type);
$license = $input->getOption('license') ?: false;
$license = $this->getIO()->ask(
$license = $io->ask(
'License [<comment>'.$license.'</comment>]: ',
$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 [<comment>yes</comment>]? ';
$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 [<comment>yes</comment>]? ';
$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 <info>%s</info> for <info>%s</info>',
$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 <info>%s</info> packages matching <info>%s</info>', 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 <info>%s</info> for <info>%s</info>',
$constraint,
$package

View File

@ -64,24 +64,24 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = $this->getIO();
if ($args = $input->getArgument('packages')) {
$this->getIO()->writeError('<error>Invalid argument '.implode(' ', $args).'. Use "composer require '.implode(' ', $args).'" instead to add packages to your composer.json.</error>');
$io->writeError('<error>Invalid argument '.implode(' ', $args).'. Use "composer require '.implode(' ', $args).'" instead to add packages to your composer.json.</error>');
return 1;
}
if ($input->getOption('no-custom-installers')) {
$this->getIO()->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$io->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$input->setOption('no-plugins', true);
}
if ($input->getOption('dev')) {
$this->getIO()->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
$io->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
}
$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);

View File

@ -62,14 +62,15 @@ EOT
}
ksort($packages);
$io = $this->getIO();
switch ($format = $input->getOption('format')) {
case 'text':
$this->getIO()->write('Name: <comment>'.$root->getPrettyName().'</comment>');
$this->getIO()->write('Version: <comment>'.$root->getFullPrettyVersion().'</comment>');
$this->getIO()->write('Licenses: <comment>'.(implode(', ', $root->getLicense()) ?: 'none').'</comment>');
$this->getIO()->write('Dependencies:');
$this->getIO()->write('');
$io->write('Name: <comment>'.$root->getPrettyName().'</comment>');
$io->write('Version: <comment>'.$root->getFullPrettyVersion().'</comment>');
$io->write('Licenses: <comment>'.(implode(', ', $root->getLicense()) ?: 'none').'</comment>');
$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(),

View File

@ -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('<warning>'.$package.' could not be found in '.$type.' but it is present in '.$altType.'</warning>');
if ($this->getIO()->isInteractive()) {
if ($this->getIO()->askConfirmation('Do you want to remove it from '.$altType.' [<comment>yes</comment>]? ', true)) {
$io->writeError('<warning>'.$package.' could not be found in '.$type.' but it is present in '.$altType.'</warning>');
if ($io->isInteractive()) {
if ($io->askConfirmation('Do you want to remove it from '.$altType.' [<comment>yes</comment>]? ', true)) {
$json->removeLink($altType, $package);
}
}
} else {
$this->getIO()->writeError('<warning>'.$package.' is not required in your composer.json and has not been removed</warning>');
$io->writeError('<warning>'.$package.' is not required in your composer.json and has not been removed</warning>');
}
}
@ -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".'<error>Removal failed, reverting '.$file.' to its original content.</error>');
$io->writeError("\n".'<error>Removal failed, reverting '.$file.' to its original content.</error>');
file_put_contents($jsonFile->getPath(), $composerBackup);
}

View File

@ -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('<error>'.$file.' could not be created.</error>');
$io->writeError('<error>'.$file.' could not be created.</error>');
return 1;
}
if (!is_readable($file)) {
$this->getIO()->writeError('<error>'.$file.' is not readable.</error>');
$io->writeError('<error>'.$file.' is not readable.</error>');
return 1;
}
if (!is_writable($file)) {
$this->getIO()->writeError('<error>'.$file.' is not writable.</error>');
$io->writeError('<error>'.$file.' is not writable.</error>');
return 1;
}
@ -126,7 +127,7 @@ EOT
$json->write($composerDefinition);
}
$this->getIO()->writeError('<info>'.$file.' has been '.($newlyCreated ? 'created' : 'updated').'</info>');
$io->writeError('<info>'.$file.' has been '.($newlyCreated ? 'created' : 'updated').'</info>');
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".'<error>Installation failed, deleting '.$file.'.</error>');
$io->writeError("\n".'<error>Installation failed, deleting '.$file.'.</error>');
unlink($json->getPath());
} else {
$this->getIO()->writeError("\n".'<error>Installation failed, reverting '.$file.' to its original content.</error>');
$io->writeError("\n".'<error>Installation failed, reverting '.$file.' to its original content.</error>');
file_put_contents($json->getPath(), $composerBackup);
}
}

View File

@ -104,9 +104,10 @@ EOT
return 0;
}
$this->getIO()->writeError('<info>scripts:</info>');
$io = $this->getIO();
$io->writeError('<info>scripts:</info>');
foreach ($scripts as $name => $script) {
$this->getIO()->write(' ' . $name);
$io->write(' ' . $name);
}
return 0;

View File

@ -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'] : ''));
}
}
}

View File

@ -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('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
$io->writeError('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
return 1;
}
if (Composer::VERSION === $updateVersion) {
$this->getIO()->writeError('<info>You are already using composer version '.$updateVersion.'.</info>');
$io->writeError('<info>You are already using composer version '.$updateVersion.'.</info>');
return 0;
}
@ -104,11 +105,11 @@ EOT
self::OLD_INSTALL_EXT
);
$this->getIO()->writeError(sprintf("Updating to version <info>%s</info>.", $updateVersion));
$io->writeError(sprintf("Updating to version <info>%s</info>.", $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('<error>The download of the new composer version failed for an unexpected reason</error>');
$io->writeError('<error>The download of the new composer version failed for an unexpected reason</error>');
return 1;
}
@ -120,22 +121,22 @@ EOT
$fs = new Filesystem;
foreach ($finder as $file) {
$file = (string) $file;
$this->getIO()->writeError('<info>Removing: '.$file.'</info>');
$io->writeError('<info>Removing: '.$file.'</info>');
$fs->remove($file);
}
}
if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
$this->getIO()->writeError('<error>The file is corrupted ('.$err->getMessage().').</error>');
$this->getIO()->writeError('<error>Please re-run the self-update command to try again.</error>');
$io->writeError('<error>The file is corrupted ('.$err->getMessage().').</error>');
$io->writeError('<error>Please re-run the self-update command to try again.</error>');
return 1;
}
if (file_exists($backupFile)) {
$this->getIO()->writeError('Use <info>composer self-update --rollback</info> to return to version '.Composer::VERSION);
$io->writeError('Use <info>composer self-update --rollback</info> to return to version '.Composer::VERSION);
} else {
$this->getIO()->writeError('<warning>A backup of the current version could not be written to '.$backupFile.', no rollback possible</warning>');
$io->writeError('<warning>A backup of the current version could not be written to '.$backupFile.', no rollback possible</warning>');
}
}
@ -160,9 +161,10 @@ EOT
}
$oldFile = $rollbackDir . "/{$rollbackVersion}" . self::OLD_INSTALL_EXT;
$this->getIO()->writeError(sprintf("Rolling back to version <info>%s</info>.", $rollbackVersion));
$io = $this->getIO();
$io->writeError(sprintf("Rolling back to version <info>%s</info>.", $rollbackVersion));
if ($err = $this->setLocalPhar($localFilename, $oldFile)) {
$this->getIO()->writeError('<error>The backup file was corrupted ('.$err->getMessage().') and has been removed.</error>');
$io->writeError('<error>The backup file was corrupted ('.$err->getMessage().') and has been removed.</error>');
return 1;
}

View File

@ -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("\n<info>suggests</info>");
$io->write("\n<info>suggests</info>");
foreach ($package->getSuggests() as $suggested => $reason) {
$this->getIO()->write($suggested . ' <comment>' . $reason . '</comment>');
$io->write($suggested . ' <comment>' . $reason . '</comment>');
}
}
$this->printLinks($package, 'provides');
@ -173,7 +174,7 @@ EOT
foreach (array('<info>platform</info>:' => true, '<comment>available</comment>:' => false, '<info>installed</info>:' => 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('<info>name</info> : ' . $package->getPrettyName());
$this->getIO()->write('<info>descrip.</info> : ' . $package->getDescription());
$this->getIO()->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
$io = $this->getIO();
$io->write('<info>name</info> : ' . $package->getPrettyName());
$io->write('<info>descrip.</info> : ' . $package->getDescription());
$io->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
$this->printVersions($package, $versions, $installedRepo);
$this->getIO()->write('<info>type</info> : ' . $package->getType());
$io->write('<info>type</info> : ' . $package->getType());
$this->printLicenses($package);
$this->getIO()->write('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
$this->getIO()->write('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
$this->getIO()->write('<info>names</info> : ' . implode(', ', $package->getNames()));
$io->write('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
$io->write('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
$io->write('<info>names</info> : ' . 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('<warning>Attention: This package is abandoned and no longer maintained.%s</warning>', $replacement)
);
}
if ($package->getSupport()) {
$this->getIO()->write("\n<info>support</info>");
$io->write("\n<info>support</info>");
foreach ($package->getSupport() as $type => $value) {
$this->getIO()->write('<comment>' . $type . '</comment> : '.$value);
$io->write('<comment>' . $type . '</comment> : '.$value);
}
}
if ($package->getAutoload()) {
$this->getIO()->write("\n<info>autoload</info>");
$io->write("\n<info>autoload</info>");
foreach ($package->getAutoload() as $type => $autoloads) {
$this->getIO()->write('<comment>' . $type . '</comment>');
$io->write('<comment>' . $type . '</comment>');
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('<comment>include-path</comment>');
$this->getIO()->write(implode(', ', $package->getIncludePaths()));
$io->write('<comment>include-path</comment>');
$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<info>" . $title . "</info>");
$io->write("\n<info>" . $title . "</info>");
foreach ($links as $link) {
$this->getIO()->write($link->getTarget() . ' <comment>' . $link->getPrettyConstraint() . '</comment>');
$io->write($link->getTarget() . ' <comment>' . $link->getPrettyConstraint() . '</comment>');
}
}
}
@ -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('<info>license</info> : ' . $out);
$io->write('<info>license</info> : ' . $out);
}
}
}

View File

@ -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('<info>No local changes</info>');
$io->writeError('<info>No local changes</info>');
} else {
$this->getIO()->writeError('<error>You have changes in the following dependencies:</error>');
$io->writeError('<error>You have changes in the following dependencies:</error>');
}
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('<info>'.$path.'</info>:');
$this->getIO()->write($indentedChanges);
$io->write('<info>'.$path.'</info>:');
$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

View File

@ -74,18 +74,18 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = $this->getIO();
if ($input->getOption('no-custom-installers')) {
$this->getIO()->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$io->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
$input->setOption('no-plugins', true);
}
if ($input->getOption('dev')) {
$this->getIO()->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
$io->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
}
$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);

View File

@ -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('<error>' . $file . ' not found.</error>');
$io->writeError('<error>' . $file . ' not found.</error>');
return 1;
}
if (!is_readable($file)) {
$this->getIO()->writeError('<error>' . $file . ' is not readable.</error>');
$io->writeError('<error>' . $file . ' is not readable.</error>');
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('<info>' . $file . ' is valid</info>');
$io->write('<info>' . $file . ' is valid</info>');
} elseif (!$errors && !$publishErrors) {
$this->getIO()->writeError('<info>' . $file . ' is valid, but with a few warnings</info>');
$this->getIO()->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
$io->writeError('<info>' . $file . ' is valid, but with a few warnings</info>');
$io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
} elseif (!$errors) {
$this->getIO()->writeError('<info>' . $file . ' is valid for simple usage with composer but has</info>');
$this->getIO()->writeError('<info>strict errors that make it unable to be published as a package:</info>');
$this->getIO()->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
$io->writeError('<info>' . $file . ' is valid for simple usage with composer but has</info>');
$io->writeError('<info>strict errors that make it unable to be published as a package:</info>');
$io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
} else {
$this->getIO()->writeError('<error>' . $file . ' is invalid, the following errors/warnings were found:</error>');
$io->writeError('<error>' . $file . ' is invalid, the following errors/warnings were found:</error>');
}
$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 . '>');
}
}

View File

@ -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('<warning>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.</warning>');
$io->writeError('<warning>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.</warning>');
}
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>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.</warning>', $_SERVER['PHP_SELF']));
$io->writeError(sprintf('<warning>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.</warning>', $_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('<warning>A script named '.$script.' would override a native Composer function and has been skipped</warning>');
$io->writeError('<warning>A script named '.$script.' would override a native Composer function and has been skipped</warning>');
} else {
$this->add(new Command\ScriptAliasCommand($script));
}
@ -150,7 +151,7 @@ class Application extends BaseApplication
}
if (isset($startTime)) {
$this->getIO()->writeError('<info>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('<info>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('<error>The disk hosting '.$dir.' is full, this may be the cause of the following exception</error>');
$io->writeError('<error>The disk hosting '.$dir.' is full, this may be the cause of the following exception</error>');
}
}
} catch (\Exception $e) {
}
if (defined('PHP_WINDOWS_VERSION_BUILD') && false !== strpos($exception->getMessage(), 'The system cannot find the path specified')) {
$this->getIO()->writeError('<error>The following exception may be caused by a stale entry in your cmd.exe AutoRun</error>');
$this->getIO()->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows- for details</error>');
$io->writeError('<error>The following exception may be caused by a stale entry in your cmd.exe AutoRun</error>');
$io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows- for details</error>');
}
if (false !== strpos($exception->getMessage(), 'fork failed - Cannot allocate memory')) {
$this->getIO()->writeError('<error>The following exception is caused by a lack of memory and not having swap configured</error>');
$this->getIO()->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details</error>');
$io->writeError('<error>The following exception is caused by a lack of memory and not having swap configured</error>');
$io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details</error>');
}
if ($output instanceof ConsoleOutputInterface) {