| 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 |  |  |         $progressBar = $this->output->createProgressBar(count(config('webfactor.generators.naming'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         foreach (config('webfactor.generators.naming') as $key => $naming) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $progressBar->advance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $this->info(' Naming Class: ' . $naming); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             $namingObject = new $naming($this->entity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             $this->naming[$key] = $namingObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $progressBar->finish(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->info(' Naming Classes loaded'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->line(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     private function loadServices() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $services = $this->getServicesToBeExecuted(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $progressBar = $this->output->createProgressBar(count($services)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         foreach ($services as $serviceClass) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             $progressBar->advance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $this->info(' Call: ' . $serviceClass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $this->executeService(new $serviceClass($this)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $progressBar->finish(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $this->info(' Service Classes loaded'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $this->line(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     private function getServicesToBeExecuted(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $serviceClassesToBeExecuted = config('webfactor.generators.services', []); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         array_push($serviceClassesToBeExecuted, OpenIdeService::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         array_push($serviceClassesToBeExecuted, AddToGitService::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         return $serviceClassesToBeExecuted; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     private function executeService(ServiceInterface $service) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $service->call(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  |