|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Webfactor\Laravel\Generators\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Webfactor\Laravel\Generators\Contracts\CommandAbstract; |
|
6
|
|
|
use Webfactor\Laravel\Generators\Contracts\ServiceInterface; |
|
7
|
|
|
use Webfactor\Laravel\Generators\Schemas\Schema; |
|
8
|
|
|
use Webfactor\Laravel\Generators\Services\AddToGitService; |
|
9
|
|
|
use Webfactor\Laravel\Generators\Services\OpenIdeService; |
|
10
|
|
|
|
|
11
|
|
|
class MakeEntity extends CommandAbstract |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The name and signature of the console command. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $signature = 'make:entity {entity} {--schema=name:string} {--migrate} {--git} {--ide=}'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Make Entity'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The Schema object. |
|
29
|
|
|
* |
|
30
|
|
|
* @var Schema |
|
31
|
|
|
*/ |
|
32
|
|
|
public $schema; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Execute the console command. |
|
36
|
|
|
* |
|
37
|
|
|
* @return mixed |
|
38
|
|
|
*/ |
|
39
|
|
|
public function handle() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->entity = $this->argument('entity'); |
|
42
|
|
|
|
|
43
|
|
|
$this->loadSchema(); |
|
44
|
|
|
$this->loadNaming(); |
|
45
|
|
|
$this->loadServices(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
private function loadSchema() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->info('Load Schema'); |
|
51
|
|
|
$this->schema = new Schema($this->option('schema')); |
|
52
|
|
|
$this->info('Schema loaded'); |
|
53
|
|
|
$this->line(''); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
private function loadNaming() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->info('Load Naming Classes'); |
|
59
|
|
|
|
|
60
|
|
|
$namingClasses = config('webfactor.generators.naming'); |
|
61
|
|
|
$count = count($namingClasses); |
|
62
|
|
|
$counter = 0; |
|
63
|
|
|
|
|
64
|
|
|
foreach ($namingClasses as $key => $naming) { |
|
65
|
|
|
$this->info(++$counter . '/' . $count . ' Naming Class: ' . $naming, 'v'); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$namingObject = new $naming($this->entity); |
|
68
|
|
|
$this->naming[$key] = $namingObject; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$this->info('Naming Classes loaded'); |
|
72
|
|
|
$this->line(''); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function loadServices() |
|
76
|
|
|
{ |
|
77
|
|
|
$services = $this->getServicesToBeExecuted(); |
|
78
|
|
|
$progressBar = $this->output->createProgressBar(count($services)); |
|
79
|
|
|
|
|
80
|
|
|
foreach ($services as $serviceClass) { |
|
81
|
|
|
$progressBar->advance(); |
|
82
|
|
|
$this->info(' Call: ' . $serviceClass); |
|
83
|
|
|
|
|
84
|
|
|
$this->executeService(new $serviceClass($this)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$progressBar->finish(); |
|
88
|
|
|
$this->info(' Service Classes loaded'); |
|
89
|
|
|
$this->line(''); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
private function getServicesToBeExecuted(): array |
|
93
|
|
|
{ |
|
94
|
|
|
$serviceClassesToBeExecuted = config('webfactor.generators.services', []); |
|
95
|
|
|
array_push($serviceClassesToBeExecuted, OpenIdeService::class); |
|
96
|
|
|
array_push($serviceClassesToBeExecuted, AddToGitService::class); |
|
97
|
|
|
|
|
98
|
|
|
return $serviceClassesToBeExecuted; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
private function executeService(ServiceInterface $service) |
|
102
|
|
|
{ |
|
103
|
|
|
$service->call(); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|