55use Illuminate \Console \Command ;
66use Illuminate \Support \Arr ;
77use Illuminate \Support \Facades \Config ;
8+ use Illuminate \Support \Facades \Event ;
89use Illuminate \Support \Str ;
910use RonasIT \Support \DTO \RelationsDTO ;
1011use RonasIT \Support \Events \SuccessCreateMessage ;
1112use RonasIT \Support \Events \WarningEvent ;
1213use RonasIT \Support \Exceptions \ClassNotExistsException ;
13- use RonasIT \ Support \ Exceptions \ EntityCreateException ;
14+ use Exception ;
1415use RonasIT \Support \Generators \ControllerGenerator ;
1516use RonasIT \Support \Generators \EntityGenerator ;
1617use RonasIT \Support \Generators \FactoryGenerator ;
2526use RonasIT \Support \Generators \TestsGenerator ;
2627use RonasIT \Support \Generators \TranslationsGenerator ;
2728use RonasIT \Support \Generators \SeederGenerator ;
28- use Illuminate \Contracts \Events \Dispatcher as EventDispatcher ;
2929use UnexpectedValueException ;
3030
31- /**
32- * @property ControllerGenerator $controllerGenerator
33- * @property MigrationGenerator $migrationGenerator
34- * @property ModelGenerator $modelGenerator
35- * @property RepositoryGenerator $repositoryGenerator
36- * @property RequestsGenerator $requestsGenerator
37- * @property ServiceGenerator $serviceGenerator
38- * @property FactoryGenerator $factoryGenerator
39- * @property TestsGenerator $testGenerator
40- * @property TranslationsGenerator $translationsGenerator
41- * @property SeederGenerator $seederGenerator
42- * @property ResourceGenerator $resourceGenerator
43- * @property NovaResourceGenerator $novaResourceGenerator
44- * @property NovaTestGenerator $novaTestGenerator
45- * @property EventDispatcher $eventDispatcher
46- */
4731class MakeEntityCommand extends Command
4832{
4933 const CRUD_OPTIONS = [
@@ -98,21 +82,6 @@ class MakeEntityCommand extends Command
9882 */
9983 protected $ description = 'Make entity with Model, Repository, Service, Migration, Controller, Resource and Nova Resource. ' ;
10084
101- protected $ controllerGenerator ;
102- protected $ migrationGenerator ;
103- protected $ modelGenerator ;
104- protected $ repositoryGenerator ;
105- protected $ requestsGenerator ;
106- protected $ serviceGenerator ;
107- protected $ factoryGenerator ;
108- protected $ testGenerator ;
109- protected $ translationsGenerator ;
110- protected $ seederGenerator ;
111- protected $ resourceGenerator ;
112- protected $ novaResourceGenerator ;
113- protected $ novaTestGenerator ;
114- protected $ eventDispatcher ;
115-
11685 protected $ rules = [
11786 'only ' => [
11887 'only-api ' => [ResourceGenerator::class, ControllerGenerator::class, RequestsGenerator::class, TestsGenerator::class],
@@ -139,26 +108,6 @@ class MakeEntityCommand extends Command
139108 NovaTestGenerator::class
140109 ];
141110
142- public function __construct ()
143- {
144- parent ::__construct ();
145-
146- $ this ->controllerGenerator = app (ControllerGenerator::class);
147- $ this ->migrationGenerator = app (MigrationGenerator::class);
148- $ this ->modelGenerator = app (ModelGenerator::class);
149- $ this ->repositoryGenerator = app (RepositoryGenerator::class);
150- $ this ->requestsGenerator = app (RequestsGenerator::class);
151- $ this ->serviceGenerator = app (ServiceGenerator::class);
152- $ this ->factoryGenerator = app (FactoryGenerator::class);
153- $ this ->testGenerator = app (TestsGenerator::class);
154- $ this ->translationsGenerator = app (TranslationsGenerator::class);
155- $ this ->seederGenerator = app (SeederGenerator::class);
156- $ this ->resourceGenerator = app (ResourceGenerator::class);
157- $ this ->novaResourceGenerator = app (NovaResourceGenerator::class);
158- $ this ->novaTestGenerator = app (NovaTestGenerator::class);
159- $ this ->eventDispatcher = app (EventDispatcher::class);
160- }
161-
162111 /**
163112 * Execute the console command.
164113 *
@@ -168,20 +117,11 @@ public function handle(): void
168117 {
169118 $ this ->validateInput ();
170119 $ this ->checkConfigs ();
171-
172- $ this ->eventDispatcher ->listen (
173- events: SuccessCreateMessage::class,
174- listener: fn (SuccessCreateMessage $ event ) => $ this ->info ($ event ->message ),
175- );
176-
177- $ this ->eventDispatcher ->listen (
178- events: WarningEvent::class,
179- listener: fn (WarningEvent $ event ) => $ this ->warn ($ event ->message ),
180- );
120+ $ this ->listenEvents ();
181121
182122 try {
183123 $ this ->generate ();
184- } catch (EntityCreateException $ e ) {
124+ } catch (Exception $ e ) {
185125 $ this ->error ($ e ->getMessage ());
186126 }
187127 }
@@ -321,4 +261,17 @@ protected function validateOnlyApiOption()
321261 }
322262 }
323263 }
264+
265+ protected function listenEvents (): void
266+ {
267+ Event::listen (
268+ events: SuccessCreateMessage::class,
269+ listener: fn (SuccessCreateMessage $ event ) => $ this ->info ($ event ->message ),
270+ );
271+
272+ Event::listen (
273+ events: WarningEvent::class,
274+ listener: fn (WarningEvent $ event ) => $ this ->warn ($ event ->message ),
275+ );
276+ }
324277}
0 commit comments