/var/www/vhosts/ihelp.ro/httpdocs/vendor/composer/composer/src/Composer/Command
NameSizeModeActions
AboutCommand.php13070644editdlrm
ArchiveCommand.php86990644editdlrm
AuditCommand.php33910644editdlrm
BaseCommand.php152790644editdlrm
BaseDependencyCommand.php110390644editdlrm
BumpCommand.php98520644editdlrm
CheckPlatformReqsCommand.php90490644editdlrm
ClearCacheCommand.php34560644editdlrm
CompletionTrait.php81100644editdlrm
ConfigCommand.php427550644editdlrm
CreateProjectCommand.php245870644editdlrm
DependsCommand.php19280644editdlrm
DiagnoseCommand.php288190644editdlrm
DumpAutoloadCommand.php58860644editdlrm
ExecCommand.php47350644editdlrm
FundCommand.php54620644editdlrm
GlobalCommand.php56660644editdlrm
HomeCommand.php55350644editdlrm
InitCommand.php237950644editdlrm
InstallCommand.php81940644editdlrm
LicensesCommand.php59260644editdlrm
OutdatedCommand.php55570644editdlrm
PackageDiscoveryTrait.php211700644editdlrm
ProhibitsCommand.php21040644editdlrm
ReinstallCommand.php83240644editdlrm
RemoveCommand.php153690644editdlrm
RequireCommand.php299970644editdlrm
RunScriptCommand.php64410644editdlrm
ScriptAliasCommand.php24790644editdlrm
SearchCommand.php51200644editdlrm
SelfUpdateCommand.php271560644editdlrm
ShowCommand.php628080644editdlrm
StatusCommand.php86530644editdlrm
SuggestsCommand.php40660644editdlrm
UpdateCommand.php165320644editdlrm
ValidateCommand.php95650644editdlrm
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/composer/composer/src/Composer/Command/BumpCommand.php (9852B)
* Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Command; use Composer\Package\AliasPackage; use Composer\Package\BasePackage; use Composer\Package\Locker; use Composer\Package\Version\VersionBumper; use Composer\Pcre\Preg; use Composer\Util\Filesystem; use Symfony\Component\Console\Input\InputInterface; use Composer\Console\Input\InputArgument; use Composer\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Composer\Factory; use Composer\Json\JsonFile; use Composer\Json\JsonManipulator; use Composer\Repository\PlatformRepository; use Composer\Util\Silencer; /** * @author Jordi Boggiano */ final class BumpCommand extends BaseCommand { private const ERROR_GENERIC = 1; private const ERROR_LOCK_OUTDATED = 2; use CompletionTrait; protected function configure(): void { $this ->setName('bump') ->setDescription('Increases the lower limit of your composer.json requirements to the currently installed versions') ->setDefinition([ new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Optional package name(s) to restrict which packages are bumped.', null, $this->suggestRootRequirement()), new InputOption('dev-only', 'D', InputOption::VALUE_NONE, 'Only bump requirements in "require-dev".'), new InputOption('no-dev-only', 'R', InputOption::VALUE_NONE, 'Only bump requirements in "require".'), new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the packages to bump, but will not execute anything.'), ]) ->setHelp( <<bump command increases the lower limit of your composer.json requirements to the currently installed versions. This helps to ensure your dependencies do not accidentally get downgraded due to some other conflict, and can slightly improve dependency resolution performance as it limits the amount of package versions Composer has to look at. Running this blindly on libraries is **NOT** recommended as it will narrow down your allowed dependencies, which may cause dependency hell for your users. Running it with --dev-only on libraries may be fine however as dev requirements are local to the library and do not affect consumers of the package. EOT ) ; } /** * @throws \Seld\JsonLint\ParsingException */ protected function execute(InputInterface $input, OutputInterface $output) { /** @readonly */ $composerJsonPath = Factory::getComposerFile(); $io = $this->getIO(); if (!Filesystem::isReadable($composerJsonPath)) { $io->writeError(''.$composerJsonPath.' is not readable.'); return self::ERROR_GENERIC; } $composerJson = new JsonFile($composerJsonPath); $contents = file_get_contents($composerJson->getPath()); if (false === $contents) { $io->writeError(''.$composerJsonPath.' is not readable.'); return self::ERROR_GENERIC; } // check for writability by writing to the file as is_writable can not be trusted on network-mounts // see https://github.com/composer/composer/issues/8231 and https://bugs.php.net/bug.php?id=68926 if (!is_writable($composerJsonPath) && false === Silencer::call('file_put_contents', $composerJsonPath, $contents)) { $io->writeError(''.$composerJsonPath.' is not writable.'); return self::ERROR_GENERIC; } unset($contents); $composer = $this->requireComposer(); if ($composer->getLocker()->isLocked()) { if (!$composer->getLocker()->isFresh()) { $io->writeError('The lock file is not up to date with the latest changes in composer.json. Run the appropriate `update` to fix that before you use the `bump` command.'); return self::ERROR_LOCK_OUTDATED; } $repo = $composer->getLocker()->getLockedRepository(true); } else { $repo = $composer->getRepositoryManager()->getLocalRepository(); } if ($composer->getPackage()->getType() !== 'project' && !$input->getOption('dev-only')) { $io->writeError('Warning: Bumping dependency constraints is not recommended for libraries as it will narrow down your dependencies and may cause problems for your users.'); $contents = $composerJson->read(); if (!isset($contents['type'])) { $io->writeError('If your package is not a library, you can explicitly specify the "type" by using "composer config type project".'); $io->writeError('Alternatively you can use --dev-only to only bump dependencies within "require-dev".'); } unset($contents); } $bumper = new VersionBumper(); $tasks = []; if (!$input->getOption('dev-only')) { $tasks['require'] = $composer->getPackage()->getRequires(); } if (!$input->getOption('no-dev-only')) { $tasks['require-dev'] = $composer->getPackage()->getDevRequires(); } $packagesFilter = $input->getArgument('packages'); if (count($packagesFilter) > 0) { $pattern = BasePackage::packageNamesToRegexp(array_unique(array_map('strtolower', $packagesFilter))); foreach ($tasks as $key => $reqs) { foreach ($reqs as $pkgName => $link) { if (!Preg::isMatch($pattern, $pkgName)) { unset($tasks[$key][$pkgName]); } } } } $updates = []; foreach ($tasks as $key => $reqs) { foreach ($reqs as $pkgName => $link) { if (PlatformRepository::isPlatformPackage($pkgName)) { continue; } $currentConstraint = $link->getPrettyConstraint(); $package = $repo->findPackage($pkgName, '*'); // name must be provided or replaced if (null === $package) { continue; } while ($package instanceof AliasPackage) { $package = $package->getAliasOf(); } $bumped = $bumper->bumpRequirement($link->getConstraint(), $package); if ($bumped === $currentConstraint) { continue; } $updates[$key][$pkgName] = $bumped; } } $dryRun = $input->getOption('dry-run'); if (!$dryRun && !$this->updateFileCleanly($composerJson, $updates)) { $composerDefinition = $composerJson->read(); foreach ($updates as $key => $packages) { foreach ($packages as $package => $version) { $composerDefinition[$key][$package] = $version; } } $composerJson->write($composerDefinition); } $changeCount = array_sum(array_map('count', $updates)); if ($changeCount > 0) { if ($dryRun) { $io->write('' . $composerJsonPath . ' would be updated with:'); foreach ($updates as $requireType => $packages) { foreach ($packages as $package => $version) { $io->write(sprintf(' - %s.%s: %s', $requireType, $package, $version)); } } } else { $io->write('' . $composerJsonPath . ' has been updated (' . $changeCount . ' changes).'); } } else { $io->write('No requirements to update in '.$composerJsonPath.'.'); } if (!$dryRun && $composer->getLocker()->isLocked() && $changeCount > 0) { $contents = file_get_contents($composerJson->getPath()); if (false === $contents) { throw new \RuntimeException('Unable to read '.$composerJson->getPath().' contents to update the lock file hash.'); } $lock = new JsonFile(Factory::getLockFile($composerJsonPath)); $lockData = $lock->read(); $lockData['content-hash'] = Locker::getContentHash($contents); $lock->write($lockData); } if ($dryRun && $changeCount > 0) { return self::ERROR_GENERIC; } return 0; } /** * @param array<'require'|'require-dev', array> $updates */ private function updateFileCleanly(JsonFile $json, array $updates): bool { $contents = file_get_contents($json->getPath()); if (false === $contents) { throw new \RuntimeException('Unable to read '.$json->getPath().' contents.'); } $manipulator = new JsonManipulator($contents); foreach ($updates as $key => $packages) { foreach ($packages as $package => $version) { if (!$manipulator->addLink($key, $package, $version)) { return false; } } } if (false === file_put_contents($json->getPath(), $manipulator->getContents())) { throw new \RuntimeException('Unable to write new '.$json->getPath().' contents.'); } return true; } }