Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
"autoload": {
"psr-4": {
"RonasIT\\Support\\": "src/"
},
"files": [
"src/helpers.php"
]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
81 changes: 18 additions & 63 deletions src/Commands/MakeEntityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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;
Expand All @@ -27,22 +27,6 @@
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 = [
Expand Down Expand Up @@ -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],
Expand All @@ -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.
*
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -320,4 +260,19 @@ protected function validateOnlyApiOption()
}
}
}

protected function listenEvents(): void
{
$eventDispatcher = app(EventDispatcher::class);

$eventDispatcher->listen(
events: SuccessCreateMessage::class,
listener: fn (SuccessCreateMessage $event) => $this->info($event->message),
);

$eventDispatcher->listen(
events: WarningEvent::class,
listener: fn (WarningEvent $event) => $this->warn($event->message),
);
}
}
11 changes: 0 additions & 11 deletions src/helpers.php

This file was deleted.