/** * Execute the command. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * * @return int */ public function execute(InputInterface $input, OutputInterface $output) { $io = new OutputStyle($input, $output); $composerPath = $this->getComposerPathFromInput($input); $ladder = new Ladder($composerPath); $packages = $ladder->getOutdatedPackages(); $io->newLine(); if (!count($packages)) { $io->write('All dependencies match the latest package versions <fg=green>:)</>'); $io->newLine(); return 1; } $outdated = []; $upgradable = []; foreach ($packages as $package) { if ($package->isUpgradable()) { $upgradable[$package->getName()] = $package; } else { $outdated[$package->getName()] = $package; } } if ($input->getOption('all')) { $upgradable = array_merge($upgradable, $outdated); } if (empty($upgradable)) { $io->warning('Nothing to install or update, did you forget the flag --all?'); return 1; } foreach ($upgradable as $package) { $command = $input->getOption('global') ? 'composer global require' : 'composer require'; $command .= sprintf(' %s=^%s', $package->getName(), $package->getLatestVersion()); if ($package->getDevDependency()) { $command .= ' --dev'; } $process = new Process($command, $composerPath, array_merge($_SERVER, $_ENV), null, null); $process->run(function ($type, $line) use($io) { $io->write($line); }); $io->newLine(); } return 0; }
/** * Execute the command. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * * @return int */ public function execute(InputInterface $input, OutputInterface $output) { $excluded = []; if ($input->getOption('exclude')) { $excluded = explode(',', $input->getOption('exclude')); } $io = new OutputStyle($input, $output); $composerPath = $this->getComposerPathFromInput($input); $ladder = new Ladder($composerPath); $packages = $ladder->getOutdatedPackages($excluded); $io->newLine(); $statusCode = 0; if (!count($packages)) { $io->writeln('All dependencies match the latest package versions <fg=green>:)</>'); $io->newLine(); return $statusCode; } $outdated = []; $upgradable = []; foreach ($packages as $package) { $diff = $io->versionDiff($package->getVersion(), $package->getLatestVersion()); if ($package->isUpgradable()) { $upgradable[] = [$package->getName(), $package->getVersion(), '→', $diff]; } else { $outdated[] = [$package->getName(), $package->getVersion(), '→', $diff]; } } if (count($outdated) && !$input->getOption('upgradable')) { $statusCode = 1; $io->columns($outdated); $io->newLine(); } if (count($upgradable) && !$input->getOption('outdated')) { $statusCode = 1; $io->writeln('The following dependencies are satisfied by their declared version constraint, but the installed versions are behind. You can install the latest versions without modifying your composer.json file by using <fg=blue>composer update</>.'); $io->newLine(); $io->columns($upgradable); $io->newLine(); } return $statusCode; }