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
|
|
|
|
21
|
|
|
if (class_exists(ContainerAwareCommand::class)) { |
22
|
|
|
/** |
23
|
|
|
* Modify a panda cloud via command-line. |
24
|
|
|
* |
25
|
|
|
* @author Christian Flothmann <[email protected]> |
26
|
|
|
* |
27
|
|
|
* @final since 1.5 |
28
|
|
|
*/ |
29
|
|
|
class ModifyCloudCommand extends ContainerAwareCommand |
30
|
|
|
{ |
31
|
|
|
use ModifyCloudCommandTrait; |
32
|
|
|
|
33
|
|
|
protected static $defaultName = 'panda:cloud:modify'; |
34
|
|
|
} |
35
|
|
|
} else { |
36
|
|
|
/** |
37
|
|
|
* Modify a panda cloud via command-line. |
38
|
|
|
* |
39
|
|
|
* @author Christian Flothmann <[email protected]> |
40
|
|
|
* |
41
|
|
|
* @final since 1.5 |
42
|
|
|
*/ |
43
|
|
|
class ModifyCloudCommand extends Command |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
use ModifyCloudCommandTrait; |
46
|
|
|
|
47
|
|
|
protected static $defaultName = 'panda:cloud:modify'; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
trait ModifyCloudCommandTrait |
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
*/ |
56
|
|
|
protected function configure() |
57
|
|
|
{ |
58
|
|
|
$this->setName(static::$defaultName); // BC with Symfony Console 3.3 and older not handling the property automatically |
|
|
|
|
59
|
|
|
$this->setDescription('Modify a cloud'); |
|
|
|
|
60
|
|
|
$this->addOption( |
|
|
|
|
61
|
|
|
'account', |
62
|
|
|
'a', |
63
|
|
|
InputOption::VALUE_REQUIRED, |
64
|
|
|
'The account to use to authenticate to the panda service' |
65
|
|
|
); |
66
|
|
|
$this->addOption('name', null, InputOption::VALUE_REQUIRED, 'The new cloud name'); |
|
|
|
|
67
|
|
|
$this->addOption('s3-bucket', null, InputOption::VALUE_REQUIRED, 'The new AWS S3 bucket'); |
|
|
|
|
68
|
|
|
$this->addOption('access-key', null, InputOption::VALUE_REQUIRED, 'The new access key'); |
|
|
|
|
69
|
|
|
$this->addOption('secret-key', null, InputOption::VALUE_REQUIRED, 'The new secret key'); |
|
|
|
|
70
|
|
|
$this->addArgument('cloud-id', InputArgument::REQUIRED, 'The id of the cloud being modified'); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritDoc} |
75
|
|
|
*/ |
76
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
77
|
|
|
{ |
78
|
|
|
$data = array(); |
79
|
|
|
|
80
|
|
|
// change the cloud name |
81
|
|
|
if ($name = $input->getOption('name')) { |
82
|
|
|
$data['name'] = $name; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// change the s3 bucket |
86
|
|
|
if ($s3bucket = $input->getOption('s3-bucket')) { |
87
|
|
|
$data['s3_videos_bucket'] = $s3bucket; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// change the access key |
91
|
|
|
if ($accessKey = $input->getOption('access-key')) { |
92
|
|
|
$data['aws_access_key'] = $accessKey; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// change the secret key |
96
|
|
|
if ($secretKey = $input->getOption('secret-key')) { |
97
|
|
|
$data['aws_secret_key'] = $secretKey; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// if anything has changed |
101
|
|
|
if (count($data) > 0) { |
102
|
|
|
// push these changes to the panda service |
103
|
|
|
$cloudFactory = $this->getContainer()->get('xabbuh_panda.cloud_factory'); |
|
|
|
|
104
|
|
|
$cloud = $cloudFactory->get( |
105
|
|
|
$input->getArgument('cloud-id'), |
106
|
|
|
$input->getOption('account') |
107
|
|
|
); |
108
|
|
|
$cloud->setCloud($data, $input->getArgument('cloud-id')); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return 0; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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.