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