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
|
204 |
|
public function handle(Container $container) |
19
|
|
|
{ |
20
|
204 |
|
$initializerInstance = null; |
21
|
|
|
|
22
|
|
|
try { |
23
|
204 |
|
$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; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** @var ExecutorContract $Executor */ |
32
|
204 |
|
$config = $container->make('config'); |
33
|
204 |
|
$env = $config->get($config->get('initializer.env_config_key')); |
34
|
|
|
|
35
|
204 |
|
$this->alert($this->title().' started'); |
36
|
|
|
|
37
|
|
|
$result = $initializerInstance |
38
|
204 |
|
->{$this->option('root') ? $env.'Root' : $env} |
39
|
204 |
|
($container->makeWith(Run::class, ['artisanCommand' => $this])); |
40
|
|
|
|
41
|
192 |
|
$this->output->newLine(); |
42
|
|
|
|
43
|
192 |
|
if ($result->errorMessages()) { |
44
|
12 |
|
$this->line('<fg=red>'.$this->title().' done with errors:</>'); |
45
|
|
|
|
46
|
12 |
|
$this->output->newLine(); |
47
|
|
|
|
48
|
12 |
|
foreach ($result->errorMessages() as $message) { |
49
|
12 |
|
$this->error($message); |
50
|
12 |
|
$this->output->newLine(); |
51
|
|
|
} |
52
|
|
|
|
53
|
12 |
|
$this->line('<fg=red>You could run command with <fg=cyan>-v</> flag to see more details</>'); |
54
|
|
|
} else { |
55
|
180 |
|
$this->info($this->title().' done!'); |
56
|
|
|
} |
57
|
192 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns initializer instance for current command. |
61
|
|
|
* |
62
|
|
|
* @return object |
63
|
|
|
*/ |
64
|
|
|
abstract protected function getInitializerInstance(Container $container); |
65
|
|
|
|
66
|
|
|
abstract protected function title(): string; |
67
|
|
|
} |
68
|
|
|
|