Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Console/JKULoaderCommand.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Jose\Component\Console;
6
7 use InvalidArgumentException;
8 use Jose\Component\KeyManagement\JKUFactory;
9 use Symfony\Component\Console\Attribute\AsCommand;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use function is_string;
14
15 #[AsCommand(name: 'keyset:load:jku', description: 'Loads a key set from an url.',)]
16 final class JKULoaderCommand extends ObjectOutputCommand
17 {
18 protected static $defaultName = 'keyset:load:jku';
19
20 protected static $defaultDescription = 'Loads a key set from an url.';
21
22 public function __construct(
23 private readonly JKUFactory $jkuFactory,
24 ?string $name = null
25 ) {
26 parent::__construct($name);
27 }
28
29 protected function configure(): void
30 {
31 parent::configure();
32 $this->setHelp('This command will try to get a key set from an URL. The distant key set is a JWKSet.')
33 ->addArgument('url', InputArgument::REQUIRED, 'The URL');
34 }
35
36 protected function execute(InputInterface $input, OutputInterface $output): int
37 {
38 $url = $input->getArgument('url');
39 if (! is_string($url)) {
40 throw new InvalidArgumentException('Invalid URL');
41 }
42 $result = $this->jkuFactory->loadFromUrl($url);
43 $this->prepareJsonOutput($input, $output, $result);
44
45 return self::SUCCESS;
46 }
47 }