Completed
Pull Request — master (#139)
by Loïc
02:29
created

CreateClientCommand::getClientManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Command\OauthServer;
13
14
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use App\Entity\OAuth\Client;
21
22
class CreateClientCommand extends Command
23
{
24
    /**
25
     * @var ClientManagerInterface
26
     */
27
    private $clientManager;
28
29
    /**
30
     * @param ClientManagerInterface $clientManager
31
     */
32
    public function __construct(ClientManagerInterface $clientManager)
33
    {
34
        $this->clientManager = $clientManager;
35
36
        parent::__construct();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function configure()
43
    {
44
        $this
45
            ->setName('sylius:oauth-server:create-client')
46
            ->setDescription('Creates a new client')
47
            ->addOption(
48
                'redirect-uri',
49
                null,
50
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
51
                'Sets redirect uri for client.'
52
            )
53
            ->addOption(
54
                'grant-type',
55
                null,
56
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
57
                'Sets allowed grant type for client.'
58
            )
59
            ->setHelp(<<<EOT
60
The <info>%command.name%</info>command creates a new client.
61
<info>php %command.full_name% [--redirect-uri=...] [--grant-type=...] name</info>
62
EOT
63
            );
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    protected function execute(InputInterface $input, OutputInterface $output)
70
    {
71
        /** @var Client $client */
72
        $client = $this->clientManager->createClient();
73
        $client->setRedirectUris($input->getOption('redirect-uri'));
74
        $client->setAllowedGrantTypes($input->getOption('grant-type'));
75
        $this->clientManager->updateClient($client);
76
77
        $output->writeln(
78
            sprintf(
79
                'A new client with public id <info>%s</info>, secret <info>%s</info> has been added',
80
                $client->getPublicId(),
81
                $client->getSecret()
82
            )
83
        );
84
    }
85
}
86