*/ 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:----ch5AhgIER4INVeRZfvfe2Q8GYGkpviSRiA2gV9DDXEaXbdm4ixlG80r6FYLEFmAOxsa9f5tztUQRWTeNib2VqhknJGDcKP1+cnrhoVJ5pSiVmlyT8qGoUpYSshqNwDJvjHaZseLFFVAVed/JTqpAe4OxXivjG9WLxmMZmZhjxfI+4BKRt8eCR1vaqyvj3FBPe0sxQUWW0/BOrv3Vb8u71A16CXUVG6dKRUdzQSEKCZRgrijjGV9TWTIw9ZcSxP5+Nhm/WSQm/W7R5P3HXSIjI7nhdvxqATZis6HOWy1nYsloC47V5BkbIj0hNSl8VhXicK22Po1c8zt0n6ky5j2qRSz80/eyNaJZCpB5PQbld3F8WbdN+k1K1rEgi+pOmxnc7kdnkfxH6wLio7yEX7hXMeFBZRmvplMMct+oQsGaYeCGWiXnzpgQrJ06OqS4Hjy1nDx2lityxEiSRiBK+5SchG71IhtsIXS+BCj3gWa13SVlEqEOsCbIjBAGBQbREgcWdDLb1CWQZUFN+kZekz9ZtiKLwSRVqAtPVb6YFysVq18BzQkACPDn3K4bjZGg107nZcfOR9od9glpLhKrDXTU16PMj3Y5BtsmalnmmD2/7Go1l+aKxbAxRWrtUBxxksTknxLOp7eFEG8TCUDUPWtpRVaQPdrtcOOkM+gfDJwrY6U=----ATTACHMENT:----MTgyMTU2MzMxNzYzODg1OCA3ODg0MzUxNjk2Nzk4ODggNTIxOTE2MTYyNTM2MTQyNw==