1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWeb\Initializer\Console\Commands; |
4
|
|
|
|
5
|
|
|
use ErrorException; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Illuminate\Contracts\Container\Container; |
8
|
|
|
use MadWeb\Initializer\Contracts\Runner as ExecutorContract; |
9
|
|
|
use MadWeb\Initializer\Run; |
10
|
|
|
|
11
|
|
|
abstract class AbstractInitializeCommand extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Execute the console command. |
15
|
|
|
* |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
210 |
|
public function handle(Container $container) |
19
|
|
|
{ |
20
|
210 |
|
$initializerInstance = null; |
21
|
|
|
|
22
|
|
|
try { |
23
|
210 |
|
$initializerInstance = $this->getInitializerInstance($container); |
24
|
|
|
} catch (ErrorException $e) { |
|
|
|
|
25
|
|
|
$this->error('Publish initializer classes:'); |
26
|
|
|
$this->error('$ php artisan vendor:publish --tag=initializers'); |
27
|
|
|
|
28
|
|
|
return 1; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** @var ExecutorContract $Executor */ |
32
|
210 |
|
$config = $container->make('config'); |
33
|
210 |
|
$env = $config->get($config->get('initializer.env_config_key')); |
34
|
|
|
|
35
|
210 |
|
$this->alert($this->title().' started'); |
36
|
|
|
|
37
|
210 |
|
$runner = $container->makeWith(Run::class, ['artisanCommand' => $this]); |
38
|
|
|
|
39
|
198 |
|
$initializerInstance->{$this->option('root') ? $env.'Root' : $env}($runner); |
40
|
|
|
|
41
|
198 |
|
$this->output->newLine(); |
42
|
|
|
|
43
|
198 |
|
if ($runner->doneWithErrors()) { |
44
|
18 |
|
$errorMessages = $runner->errorMessages(); |
45
|
|
|
|
46
|
18 |
|
$this->line( |
47
|
18 |
|
'<fg=red>'.$this->title().' done with errors'. |
48
|
18 |
|
(! empty($errorMessages) ? ':' : '.'). |
49
|
18 |
|
'</>' |
50
|
|
|
); |
51
|
|
|
|
52
|
18 |
|
if (! empty($errorMessages)) { |
53
|
12 |
|
$this->output->newLine(); |
54
|
|
|
|
55
|
12 |
|
foreach ($runner->errorMessages() as $message) { |
56
|
12 |
|
$this->error($message); |
57
|
12 |
|
$this->output->newLine(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
18 |
|
$this->line('<fg=red>You could run command with <fg=cyan>-v</> flag to see more details</>'); |
62
|
|
|
|
63
|
18 |
|
return 1; |
64
|
|
|
} |
65
|
|
|
|
66
|
180 |
|
$this->info($this->title().' done!'); |
67
|
|
|
|
68
|
180 |
|
return 0; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns initializer instance for current command. |
73
|
|
|
* |
74
|
|
|
* @return object |
75
|
|
|
*/ |
76
|
|
|
abstract protected function getInitializerInstance(Container $container); |
77
|
|
|
|
78
|
|
|
abstract protected function title(): string; |
79
|
|
|
} |
80
|
|
|
|