1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Bundle\Console\Command; |
15
|
|
|
|
16
|
|
|
use Jose\Component\Console\Command\AbstractGeneratorCommand; |
17
|
|
|
use Jose\Component\KeyManagement\JKUFactory; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
23
|
|
|
|
24
|
|
|
final class JKULoaderCommand extends AbstractGeneratorCommand implements ContainerAwareInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ContainerInterface|null |
28
|
|
|
*/ |
29
|
|
|
private $container; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function configure() |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->setName('keyset:load:jku') |
38
|
|
|
->setDescription('Loads a key set from an url.') |
39
|
|
|
->setHelp('This command will try to get a key set from an URL. The distant key set is a JWKSet.') |
40
|
|
|
->addArgument('url', InputArgument::REQUIRED, 'The URL') |
41
|
|
|
; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
48
|
|
|
{ |
49
|
|
|
/** @var JKUFactory $jkuFactory */ |
50
|
|
|
$jkuFactory = $this->getContainer()->get(JKUFactory::class); |
51
|
|
|
$url = $input->getArgument('url'); |
52
|
|
|
|
53
|
|
|
$result = $jkuFactory->loadFromUrl($url); |
54
|
|
|
$this->prepareOutput($input, $output, $result); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return ContainerInterface |
59
|
|
|
* |
60
|
|
|
* @throws \LogicException |
61
|
|
|
*/ |
62
|
|
|
protected function getContainer(): ContainerInterface |
63
|
|
|
{ |
64
|
|
|
if (null === $this->container) { |
65
|
|
|
$application = $this->getApplication(); |
66
|
|
|
if (null === $application) { |
67
|
|
|
throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->container = $application->getKernel()->getContainer(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->container; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function setContainer(ContainerInterface $container = null) |
80
|
|
|
{ |
81
|
|
|
$this->container = $container; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|