diff --git a/composer.json b/composer.json index 1c8cb636..88e89949 100644 --- a/composer.json +++ b/composer.json @@ -29,10 +29,7 @@ "autoload": { "psr-4": { "RonasIT\\Support\\": "src/" - }, - "files": [ - "src/helpers.php" - ] + } }, "autoload-dev": { "psr-4": { diff --git a/src/Commands/MakeEntityCommand.php b/src/Commands/MakeEntityCommand.php index 6ec5f173..60c53797 100644 --- a/src/Commands/MakeEntityCommand.php +++ b/src/Commands/MakeEntityCommand.php @@ -5,11 +5,12 @@ use Illuminate\Console\Command; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Str; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassNotExistsException; -use RonasIT\Support\Exceptions\EntityCreateException; +use Exception; use RonasIT\Support\Generators\ControllerGenerator; use RonasIT\Support\Generators\EntityGenerator; use RonasIT\Support\Generators\FactoryGenerator; @@ -24,25 +25,8 @@ use RonasIT\Support\Generators\TestsGenerator; use RonasIT\Support\Generators\TranslationsGenerator; use RonasIT\Support\Generators\SeederGenerator; -use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; use UnexpectedValueException; -/** - * @property ControllerGenerator $controllerGenerator - * @property MigrationGenerator $migrationGenerator - * @property ModelGenerator $modelGenerator - * @property RepositoryGenerator $repositoryGenerator - * @property RequestsGenerator $requestsGenerator - * @property ServiceGenerator $serviceGenerator - * @property FactoryGenerator $factoryGenerator - * @property TestsGenerator $testGenerator - * @property TranslationsGenerator $translationsGenerator - * @property SeederGenerator $seederGenerator - * @property ResourceGenerator $resourceGenerator - * @property NovaResourceGenerator $novaResourceGenerator - * @property NovaTestGenerator $novaTestGenerator - * @property EventDispatcher $eventDispatcher - */ class MakeEntityCommand extends Command { const CRUD_OPTIONS = [ @@ -97,21 +81,6 @@ class MakeEntityCommand extends Command */ protected $description = 'Make entity with Model, Repository, Service, Migration, Controller, Resource and Nova Resource.'; - protected $controllerGenerator; - protected $migrationGenerator; - protected $modelGenerator; - protected $repositoryGenerator; - protected $requestsGenerator; - protected $serviceGenerator; - protected $factoryGenerator; - protected $testGenerator; - protected $translationsGenerator; - protected $seederGenerator; - protected $resourceGenerator; - protected $novaResourceGenerator; - protected $novaTestGenerator; - protected $eventDispatcher; - protected $rules = [ 'only' => [ 'only-api' => [ResourceGenerator::class, ControllerGenerator::class, RequestsGenerator::class, TestsGenerator::class], @@ -138,26 +107,6 @@ class MakeEntityCommand extends Command NovaTestGenerator::class ]; - public function __construct() - { - parent::__construct(); - - $this->controllerGenerator = app(ControllerGenerator::class); - $this->migrationGenerator = app(MigrationGenerator::class); - $this->modelGenerator = app(ModelGenerator::class); - $this->repositoryGenerator = app(RepositoryGenerator::class); - $this->requestsGenerator = app(RequestsGenerator::class); - $this->serviceGenerator = app(ServiceGenerator::class); - $this->factoryGenerator = app(FactoryGenerator::class); - $this->testGenerator = app(TestsGenerator::class); - $this->translationsGenerator = app(TranslationsGenerator::class); - $this->seederGenerator = app(SeederGenerator::class); - $this->resourceGenerator = app(ResourceGenerator::class); - $this->novaResourceGenerator = app(NovaResourceGenerator::class); - $this->novaTestGenerator = app(NovaTestGenerator::class); - $this->eventDispatcher = app(EventDispatcher::class); - } - /** * Execute the console command. * @@ -167,20 +116,11 @@ public function handle(): void { $this->validateInput(); $this->checkConfigs(); - - $this->eventDispatcher->listen( - events: SuccessCreateMessage::class, - listener: fn (SuccessCreateMessage $event) => $this->info($event->message), - ); - - $this->eventDispatcher->listen( - events: WarningEvent::class, - listener: fn (WarningEvent $event) => $this->warn($event->message), - ); + $this->listenEvents(); try { $this->generate(); - } catch (EntityCreateException $e) { + } catch (Exception $e) { $this->error($e->getMessage()); } } @@ -320,4 +260,17 @@ protected function validateOnlyApiOption() } } } + + protected function listenEvents(): void + { + Event::listen( + events: SuccessCreateMessage::class, + listener: fn (SuccessCreateMessage $event) => $this->info($event->message), + ); + + Event::listen( + events: WarningEvent::class, + listener: fn (WarningEvent $event) => $this->warn($event->message), + ); + } } diff --git a/src/helpers.php b/src/helpers.php deleted file mode 100644 index 4ab804d1..00000000 --- a/src/helpers.php +++ /dev/null @@ -1,11 +0,0 @@ -