*/ class GlobalCommand extends BaseCommand { public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void { $application = $this->getApplication(); if ($input->mustSuggestArgumentValuesFor('command-name')) { $suggestions->suggestValues(array_values(array_filter(array_map(static function (Command $command) { return $command->isHidden() ? null : $command->getName(); }, $application->all())))); return; } if ($application->has($commandName = $input->getArgument('command-name'))) { $input = $this->prepareSubcommandInput($input, true); $input = CompletionInput::fromString($input->__toString(), 2); $command = $application->find($commandName); $command->mergeApplicationDefinition(); $input->bind($command->getDefinition()); $command->complete($input, $suggestions); } } protected function configure(): void { $this ->setName('global') ->setDescription('Allows running commands in the global composer dir ($COMPOSER_HOME)') ->setDefinition([ new InputArgument('command-name', InputArgument::REQUIRED, ''), new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''), ]) ->setHelp( "Use this command as a wrapper to run other Composer commands\nwithin the global context of COMPOSER_HOME.\n\nYou can use this to install CLI utilities globally, all you need\nis to add the COMPOSER_HOME/vendor/bin dir to your PATH env var.\n\nCOMPOSER_HOME is c:\Users\\AppData\Roaming\Composer on Windows\nand /home//.composer on unix systems.\n\nIf your system uses freedesktop.org standards, then it will first check\nXDG_CONFIG_HOME or default to /home//.config/composer\n\nNote: This path may vary depending on customizations to bin-dir in\ncomposer.json or the environmental variable COMPOSER_BIN_DIR.\n\nRead more at https://getcomposer.org/doc/03-cli.md#global" ) ; } /** * @throws \Symfony\Component\Console\Exception\ExceptionInterface */ public function run(InputInterface $input, OutputInterface $output): int { if (!method_exists($input, '__toString')) { // @phpstan-ignore-line throw new \LogicException('Expected an Input instance that is stringable, got '.get_class($input)); } // extract real command name $tokens = Preg::split('{\s+}', $input->__toString()); $args = []; foreach ($tokens as $token) { if ($token && $token[0] !== '-') { $args[] = $token; if (count($args) >= 2) { break; } } } // show help for this command if no command was found if (count($args) < 2) { return parent::run($input, $output); } $input = $this->prepareSubcommandInput($input); return $this->getApplication()->run($input, $output); } private function prepareSubcommandInput(InputInterface $input, bool $quiet = false): StringInput { if (!method_exists($input, '__toString')) { // @phpstan-ignore-line throw new \LogicException('Expected an Input instance that is stringable, got '.get_class($input)); } // The COMPOSER env var should not apply to the global execution scope if (Platform::getEnv('COMPOSER')) { Platform::clearEnv('COMPOSER'); } // change to global dir $config = Factory::createConfig(); $home = $config->get('home'); if (!is_dir($home)) { $fs = new Filesystem(); $fs->ensureDirectoryExists($home); if (!is_dir($home)) { throw new \RuntimeException('Could not create home directory'); } } try { chdir($home); } catch (\Exception $e) { throw new \RuntimeException('Could not switch to home directory "'.$home.'"', 0, $e); } if (!$quiet) { $this->getIO()->writeError('Changed current directory to '.$home.''); } // create new input without "global" command prefix $input = new StringInput(Preg::replace('{\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\b}', '', $input->__toString(), 1)); $this->getApplication()->resetComposer(); return $input; } /** * @inheritDoc */ public function isProxyCommand(): bool { return true; } } __halt_compiler();----SIGNATURE:----pWjVcbDIbKl7AQwanXS/tNLwZ4QGLCNYbkNp0C6w3UMXZHusTJ7oXVYhFxU7NUsUaJPlnEt+QFkWHXBquzn8mRXSBZP/sxBEx+udPntgfAVzEzUEHPN4i6AMwBbQtVe8m/XpW95qTaFy5JxwnEVJZkTk0ydRMMPRHzHtWuNU3STZw6WKDK1r7rwktfrbyP1H6oDZGnA2zCcFeYHyUbPObxbY0KjNNnz64GV1bHtBqrV2MGcx3pvJSTuvuzW1Op5m9GnZeZP2ZTOAvI6imTOnoCjHtD7kifVKWU9gCmMjDlb3XePZoR0diNG5jO6FEgb3F+geFmd2oh1YS9s8eYrKyKibOsG3TIK/Hy8icmbPDW/+TJQ4vpBoK95sWpOEK4gKhjYftPCV2jzUb4q+awRO+CD1rUuNBrnD8E62IZkTDQlEtAMKhPGMXy+Q8a1XBNZxLo3YYpqgQFnYexgHMd4b9mkBHUC6PQOOu4+UmiQo17ppf1M4Xmn6Ub5c8c4+IPXc7UuuQb9SocHvvsH2H8jtyxcDzhl22km25hTamFri8SQw0Y54c3tqK/yiQn+nTwSa09vvHIhqnf6tHq11/U7xgHtjlGe1bZAbZhqI3YysEcKMY6AtbVoFJCr4r1tb3uxKvGY55Knm32K3QPEfSpAxeTz23REjj3j846S8dAdlHFQ=----ATTACHMENT:----NTk2ODE2MTc4ODY0MjUyNiA3NDQyODQ0Mzg3NDQzMjg4IDY5MzMxNDU3NjExNzcwOTM=