1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ClanManager package. |
5
|
|
|
* (c) Fluxter <https://fluxter.net/> |
6
|
|
|
* Found us at <https://clanmanager.net> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Fluxter\SaasProviderBundle\Command; |
10
|
|
|
|
11
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
12
|
|
|
use Fluxter\SaasProviderBundle\Model\SaasClientInterface; |
13
|
|
|
use Symfony\Component\Console\Command\Command; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
16
|
|
|
|
17
|
|
|
class CreateClientCommand extends Command |
18
|
|
|
{ |
19
|
|
|
protected static $defaultName = 'fluxter:saas:provider:create-client'; |
20
|
|
|
|
21
|
|
|
private string $saasClientEntity; |
22
|
|
|
|
23
|
|
|
private EntityManagerInterface $em; |
24
|
|
|
|
25
|
|
|
public function __construct(ContainerInterface $container, EntityManagerInterface $em) |
26
|
|
|
{ |
27
|
|
|
parent::__construct(); |
28
|
|
|
$this->em = $em; |
29
|
|
|
$this->saasClientEntity = $container->getParameter('saas_provider.client_entity'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function configure() |
33
|
|
|
{ |
34
|
|
|
$this |
35
|
|
|
->setDescription('Creates a new SaaS client') |
36
|
|
|
->addOption( |
37
|
|
|
'url', |
38
|
|
|
'u', |
39
|
|
|
InputOption::VALUE_REQUIRED, |
40
|
|
|
'The URL for the client (without http and port)', |
41
|
|
|
null |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) |
46
|
|
|
{ |
47
|
|
|
/** @var SaasClientInterface */ |
48
|
|
|
$client = new $this->saasClientEntity(); |
49
|
|
|
$client->setUrl($input->getOption('url')); |
50
|
|
|
$this->em->persist($client); |
51
|
|
|
$this->em->flush(); |
52
|
|
|
|
53
|
|
|
$output->writeln('The client has been created successfully.'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|