1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWeb\Initializer\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Container\Container; |
6
|
|
|
|
7
|
|
View Code Duplication |
class UpdateCommand extends AbstractInitializeCommand |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The console command name. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $name = 'app:update'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The console command description. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $description = 'Update the application according to current environment'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Create a new command instance. |
25
|
|
|
* |
26
|
|
|
* @param Illuminate\Contracts\Container\Container $container |
27
|
|
|
* @return void |
|
|
|
|
28
|
|
|
*/ |
29
|
222 |
|
public function __construct(Container $container) |
30
|
|
|
{ |
31
|
222 |
|
$this->signature = 'app:update |
32
|
|
|
{--root : Run commands which requires root privileges} |
33
|
222 |
|
{--o|options=* : Run commands for custom options'.$this->getOptionsConfig($container).'}'; |
34
|
|
|
|
35
|
222 |
|
parent::__construct(); |
36
|
222 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns instance of Update class which defines initializing runner chain. |
40
|
|
|
* |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
111 |
|
protected function getInitializerInstance(Container $container) |
44
|
|
|
{ |
45
|
111 |
|
return $container->make('app.updater'); |
46
|
|
|
} |
47
|
|
|
|
48
|
111 |
|
protected function title(): string |
49
|
|
|
{ |
50
|
111 |
|
return 'Application update'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns allowed options. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
222 |
|
protected function getOptionsConfig(Container $container) |
59
|
|
|
{ |
60
|
222 |
|
$config = $container->make('config'); |
61
|
222 |
|
$env = $config->get($config->get('initializer.env_config_key')); |
62
|
222 |
|
$options = $config->get($config->get('initializer.options.'.$env.'.update')); |
63
|
|
|
|
64
|
222 |
|
$options = array_keys($options); |
65
|
|
|
|
66
|
222 |
|
if (count($options) > 0) { |
67
|
222 |
|
return '. Allowed options:['.implode(', ', $options).']'; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.