Failed Conditions
Push — v7 ( 1e67af...6a6683 )
by Florent
02:18
created

X5ULoaderCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
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\X5UFactory;
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 X5ULoaderCommand 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:x5u')
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 list of X.509 certificates.')
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 X5UFactory $x5uFactory */
50
        $x5uFactory = $this->getContainer()->get(X5UFactory::class);
51
        $url = $input->getArgument('url');
52
53
        $result = $x5uFactory->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