|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OAuth\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Del\Service\UserService; |
|
6
|
|
|
use OAuth\Client; |
|
7
|
|
|
use OAuth\Repository\ScopeRepository; |
|
8
|
|
|
use OAuth\Scope; |
|
9
|
|
|
use OAuth\Service\ClientService; |
|
10
|
|
|
use OAuth\OAuthUser as User; |
|
11
|
|
|
use Symfony\Component\Console\Command\Command; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
15
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
16
|
|
|
use Symfony\Component\Console\Question\Question; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class ClientCommand |
|
20
|
|
|
* @package OAuth\Command |
|
21
|
|
|
*/ |
|
22
|
|
|
class ScopeCreateCommand extends Command |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var ScopeRepository $scopeRepository |
|
26
|
|
|
*/ |
|
27
|
|
|
private $scopeRepository; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* ScopeCreateCommand constructor. |
|
31
|
|
|
* @param ScopeRepository $scopeRepository |
|
32
|
|
|
* @param string|null $name |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(ScopeRepository $scopeRepository, ?string $name = null) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->scopeRepository = $scopeRepository; |
|
37
|
|
|
parent::__construct($name); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* configure options |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function configure() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->setName('scope:create'); |
|
46
|
|
|
$this->setDescription('Creates a new scope.'); |
|
47
|
|
|
$this->setHelp('Create a new OAuth2 client application'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param InputInterface $input |
|
52
|
|
|
* @param OutputInterface $output |
|
53
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
56
|
|
|
{ |
|
57
|
|
|
$output->writeln('Bone API scope creator'); |
|
58
|
|
|
$helper = $this->getHelper('question'); |
|
59
|
|
|
|
|
60
|
|
|
$question = new Question('Name of new scope: ', false); |
|
61
|
|
|
$scopeName = $helper->ask($input, $output, $question); |
|
62
|
|
|
|
|
63
|
|
|
$question = new Question('Describe this scope: ', false); |
|
64
|
|
|
$description = $helper->ask($input, $output, $question); |
|
65
|
|
|
|
|
66
|
|
|
$scope = new Scope(); |
|
67
|
|
|
$scope->setIdentifier($scopeName); |
|
68
|
|
|
$scope->setDescription($description); |
|
69
|
|
|
|
|
70
|
|
|
$this->scopeRepository->create($scope); |
|
71
|
|
|
|
|
72
|
|
|
$output->writeln('Scope created.'); |
|
73
|
|
|
} |
|
74
|
|
|
} |