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