1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the XabbuhPandaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
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 Xabbuh\PandaBundle\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
15
|
|
|
use Symfony\Component\Console\Command\Command; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
21
|
|
|
use Xabbuh\PandaClient\Api\AccountManagerInterface; |
22
|
|
|
use Xabbuh\PandaClient\Api\Cloud; |
23
|
|
|
use Xabbuh\PandaClient\Api\HttplugClient; |
24
|
|
|
use Xabbuh\PandaClient\Transformer\TransformerRegistry; |
25
|
|
|
|
26
|
1 |
|
if (class_exists(ContainerAwareCommand::class)) { |
27
|
|
|
/** |
28
|
|
|
* Modify a panda cloud via command-line. |
29
|
|
|
* |
30
|
|
|
* @author Christian Flothmann <[email protected]> |
31
|
|
|
* |
32
|
|
|
* @final since 1.5 |
33
|
|
|
*/ |
34
|
|
|
class ModifyCloudCommand extends ContainerAwareCommand |
35
|
|
|
{ |
36
|
|
|
use ModifyCloudCommandTrait; |
37
|
|
|
|
38
|
|
|
protected static $defaultName = 'panda:cloud:modify'; |
39
|
|
|
|
40
|
|
|
private $accountManager; |
41
|
|
|
private $transformerRegistry; |
42
|
|
|
|
43
|
|
|
public function __construct(AccountManagerInterface $accountManager = null, TransformerRegistry $transformerRegistry = null) |
44
|
|
|
{ |
45
|
|
|
if (null === $accountManager) { |
46
|
|
|
@trigger_error(sprintf('Not injecting an %s instance into the constructor of the %s class is deprecated since PandaBundle 1.5.', AccountManagerInterface::class, static::class), E_USER_DEPRECATED); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (null === $transformerRegistry) { |
50
|
|
|
@trigger_error(sprintf('Not injecting an %s instance into the constructor of the %s class is deprecated since PandaBundle 1.5.', TransformerRegistry::class, static::class), E_USER_DEPRECATED); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
parent::__construct(); |
54
|
|
|
|
55
|
|
|
$this->accountManager = $accountManager; |
56
|
|
|
$this->transformerRegistry = $transformerRegistry; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setContainer(ContainerInterface $container = null) |
60
|
|
|
{ |
61
|
|
|
@trigger_error(sprintf('The %s() method is deprecated since PandaBundle 1.5.', __METHOD__), E_USER_DEPRECATED); |
62
|
|
|
|
63
|
|
|
parent::setContainer($container); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getContainer() |
67
|
|
|
{ |
68
|
|
|
@trigger_error(sprintf('The %s() method is deprecated since PandaBundle 1.5.', __METHOD__), E_USER_DEPRECATED); |
69
|
|
|
|
70
|
|
|
return parent::getContainer(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} else { |
74
|
|
|
/** |
75
|
|
|
* Modify a panda cloud via command-line. |
76
|
|
|
* |
77
|
|
|
* @author Christian Flothmann <[email protected]> |
78
|
|
|
* |
79
|
|
|
* @final since 1.5 |
80
|
|
|
*/ |
81
|
|
|
class ModifyCloudCommand extends Command |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
use ModifyCloudCommandTrait; |
84
|
|
|
|
85
|
|
|
protected static $defaultName = 'panda:cloud:modify'; |
86
|
|
|
|
87
|
|
|
private $accountManager; |
88
|
|
|
private $transformerRegistry; |
89
|
|
|
private $container; |
90
|
|
|
|
91
|
1 |
|
public function __construct(AccountManagerInterface $accountManager = null, TransformerRegistry $transformerRegistry = null) |
92
|
|
|
{ |
93
|
1 |
|
if (null === $accountManager) { |
94
|
|
|
@trigger_error(sprintf('Not injecting an %s instance into the constructor of the %s class is deprecated since PandaBundle 1.5.', AccountManagerInterface::class, static::class), E_USER_DEPRECATED); |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
if (null === $transformerRegistry) { |
98
|
|
|
@trigger_error(sprintf('Not injecting an %s instance into the constructor of the %s class is deprecated since PandaBundle 1.5.', TransformerRegistry::class, static::class), E_USER_DEPRECATED); |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
parent::__construct(); |
102
|
|
|
|
103
|
1 |
|
$this->accountManager = $accountManager; |
104
|
1 |
|
$this->transformerRegistry = $transformerRegistry; |
105
|
1 |
|
} |
106
|
|
|
|
107
|
|
|
public function setContainer(ContainerInterface $container = null) |
108
|
|
|
{ |
109
|
|
|
@trigger_error(sprintf('The %s() method is deprecated since PandaBundle 1.5.', __METHOD__), E_USER_DEPRECATED); |
110
|
|
|
|
111
|
|
|
$this->container = $container; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getContainer() |
115
|
|
|
{ |
116
|
|
|
@trigger_error(sprintf('The %s() method is deprecated since PandaBundle 1.5.', __METHOD__), E_USER_DEPRECATED); |
117
|
|
|
|
118
|
|
|
return $this->container; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
trait ModifyCloudCommandTrait |
124
|
|
|
{ |
125
|
|
|
/** |
126
|
|
|
* {@inheritDoc} |
127
|
|
|
*/ |
128
|
1 |
|
protected function configure() |
129
|
|
|
{ |
130
|
1 |
|
$this->setName(static::$defaultName); // BC with Symfony Console 3.3 and older not handling the property automatically |
|
|
|
|
131
|
1 |
|
$this->setDescription('Modify a cloud'); |
|
|
|
|
132
|
1 |
|
$this->addOption( |
|
|
|
|
133
|
1 |
|
'account', |
134
|
1 |
|
'a', |
135
|
1 |
|
InputOption::VALUE_REQUIRED, |
136
|
1 |
|
'The account to use to authenticate to the panda service' |
137
|
|
|
); |
138
|
1 |
|
$this->addOption('name', null, InputOption::VALUE_REQUIRED, 'The new cloud name'); |
|
|
|
|
139
|
1 |
|
$this->addOption('s3-bucket', null, InputOption::VALUE_REQUIRED, 'The new AWS S3 bucket'); |
|
|
|
|
140
|
1 |
|
$this->addOption('access-key', null, InputOption::VALUE_REQUIRED, 'The new access key'); |
|
|
|
|
141
|
1 |
|
$this->addOption('secret-key', null, InputOption::VALUE_REQUIRED, 'The new secret key'); |
|
|
|
|
142
|
1 |
|
$this->addArgument('cloud-id', InputArgument::REQUIRED, 'The id of the cloud being modified'); |
|
|
|
|
143
|
1 |
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritDoc} |
147
|
|
|
*/ |
148
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
149
|
|
|
{ |
150
|
|
|
$data = array(); |
151
|
|
|
|
152
|
|
|
// change the cloud name |
153
|
|
|
if ($name = $input->getOption('name')) { |
154
|
|
|
$data['name'] = $name; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
// change the s3 bucket |
158
|
|
|
if ($s3bucket = $input->getOption('s3-bucket')) { |
159
|
|
|
$data['s3_videos_bucket'] = $s3bucket; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
// change the access key |
163
|
|
|
if ($accessKey = $input->getOption('access-key')) { |
164
|
|
|
$data['aws_access_key'] = $accessKey; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
// change the secret key |
168
|
|
|
if ($secretKey = $input->getOption('secret-key')) { |
169
|
|
|
$data['aws_secret_key'] = $secretKey; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
// if anything has changed |
173
|
|
|
if (count($data) > 0) { |
174
|
|
|
$cloud = $this->getCloud($input->getArgument('cloud-id'), $input->getOption('account')); |
|
|
|
|
175
|
|
|
$cloud->setCloud($data, $input->getArgument('cloud-id')); |
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
return 0; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
private function getCloud(string $cloudId, ?string $accountKey): Cloud |
182
|
|
|
{ |
183
|
|
|
if (null === $this->accountManager) { |
184
|
|
|
$this->accountManager = $this->getContainer()->get('xabbuh_panda.account_manager'); |
|
|
|
|
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
if (null === $this->transformerRegistry) { |
188
|
|
|
$this->transformerRegistry = $this->getContainer()->get('xabbuh_panda.transformer'); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$account = $this->accountManager->getAccount($accountKey); |
192
|
|
|
|
193
|
|
|
$httpClient = new HttplugClient(); |
194
|
|
|
$httpClient->setCloudId($cloudId); |
195
|
|
|
$httpClient->setAccount($account); |
196
|
|
|
|
197
|
|
|
$cloud = new Cloud(); |
198
|
|
|
$cloud->setHttpClient($httpClient); |
199
|
|
|
$cloud->setTransformers($this->transformerRegistry); |
200
|
|
|
|
201
|
|
|
return $cloud; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
This check looks for classes that have been defined more than once in the same file.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.