*/ class HomeCommand extends BaseCommand { use CompletionTrait; /** * @inheritDoc */ protected function configure(): void { $this ->setName('browse') ->setAliases(['home']) ->setDescription('Opens the package\'s repository URL or homepage in your browser') ->setDefinition([ new InputArgument('packages', InputArgument::IS_ARRAY, 'Package(s) to browse to.', null, $this->suggestInstalledPackage()), new InputOption('homepage', 'H', InputOption::VALUE_NONE, 'Open the homepage instead of the repository URL.'), new InputOption('show', 's', InputOption::VALUE_NONE, 'Only show the homepage or repository URL.'), ]) ->setHelp( "The home command opens or shows a package's repository URL or\nhomepage in your default browser.\n\nTo open the homepage by default, use -H or --homepage.\nTo show instead of open the repository or homepage URL, use -s or --show.\n\nRead more at https://getcomposer.org/doc/03-cli.md#browse-home" ); } protected function execute(InputInterface $input, OutputInterface $output): int { $repos = $this->initializeRepos(); $io = $this->getIO(); $return = 0; $packages = $input->getArgument('packages'); if (count($packages) === 0) { $io->writeError('No package specified, opening homepage for the root package'); $packages = [$this->requireComposer()->getPackage()->getName()]; } foreach ($packages as $packageName) { $handled = false; $packageExists = false; foreach ($repos as $repo) { foreach ($repo->findPackages($packageName) as $package) { $packageExists = true; if ($package instanceof CompletePackageInterface && $this->handlePackage($package, $input->getOption('homepage'), $input->getOption('show'))) { $handled = true; break 2; } } } if (!$packageExists) { $return = 1; $io->writeError('Package '.$packageName.' not found'); } if (!$handled) { $return = 1; $io->writeError(''.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.''); } } return $return; } private function handlePackage(CompletePackageInterface $package, bool $showHomepage, bool $showOnly): bool { $support = $package->getSupport(); $url = $support['source'] ?? $package->getSourceUrl(); if (!$url || $showHomepage) { $url = $package->getHomepage(); } if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) { return false; } if ($showOnly) { $this->getIO()->write(sprintf('%s', $url)); } else { $this->openBrowser($url); } return true; } /** * opens a url in your system default browser */ private function openBrowser(string $url): void { $url = ProcessExecutor::escape($url); $process = new ProcessExecutor($this->getIO()); if (Platform::isWindows()) { $process->execute('start "web" explorer ' . $url, $output); return; } $linux = $process->execute('which xdg-open', $output); $osx = $process->execute('which open', $output); if (0 === $linux) { $process->execute('xdg-open ' . $url, $output); } elseif (0 === $osx) { $process->execute('open ' . $url, $output); } else { $this->getIO()->writeError('No suitable browser opening command found, open yourself: ' . $url); } } /** * Initializes repositories * * Returns an array of repos in order they should be checked in * * @return RepositoryInterface[] */ private function initializeRepos(): array { $composer = $this->tryComposer(); if ($composer) { return array_merge( [new RootPackageRepository(clone $composer->getPackage())], // root package [$composer->getRepositoryManager()->getLocalRepository()], // installed packages $composer->getRepositoryManager()->getRepositories() // remotes ); } return RepositoryFactory::defaultReposWithDefaultManager($this->getIO()); } } __halt_compiler();----SIGNATURE:----ZCg+Byqp+nv9wPJ5MzsJmGBiEpUGc83XItkktIEbbhFoN8gd9hq8mFknF3WrrJyuMg+f3fwrCot5lgnJgOhhRMioJoCwwHAv0KwDPhxKuUt3QT6iIiMViMGTuMcI5I/R3jYGams7RGihn8aJ1pefHse9J6fHN5InIjHsGU8/RXrs6J6DFS0syFSsXSX4uVplSajR6PV8Xkaon60LSIkVq0/2D3kC5i+Oqe86FExotn+bOG37Ih+J9SAYXfATD+TUy/SUy1sR1NFcqCvLhk2RoogIp59EGSh07fpCDf3BPelb7CkMOaBmnvWuv5kPVhVa5YGXbVf5oI7H2jYXOjIrZgQzfi6BZgK+KiHLdh8E9S25pD+cavcL+zKRppvJ1byrfdUXNlrwUy4XitprDUABHQeBuRGiRGOOVs2+KlLsuh+CTf2SEtfq7wflzRepjzt1CCavgHvUqqnEOt+vZE3XlSvf8SseIlaFWrGRWh8we8/4sjh2eCsyx7RCBfd8Pw4W/9RH6T2FcaFh84TgUQVNNFr1xQd6cSYWYZQVWAqf2EF2ngHkyA+ogI2azezuM24606fsbb8xGuJHzie7uB36wUPe4+Pmlti2cNZjkH/Op/CddENDSF2avJyJM1mjW5jr+eV3NQSPrjF5duCiUQi+SIgboISXBBzDno/ybpn9wsM=----ATTACHMENT:----NDM2NzAzODA2NTQ5MzY5OCA5NjQzMTAwMzE0NjUxMjUgNTc1NTA5NDU5NTk0MjEwMA==