Skip to content

Commit d009077

Browse files
committed
Merge branch '47-add-api-entity-commands' into 'master'
#47 Added new commands --only-api, --only-entity See merge request components/laravel-entity-generator!69
2 parents 70d1200 + 257caa3 commit d009077

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Commands/MakeEntityCommand.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Support\Arr;
77
use RonasIT\Support\Events\SuccessCreateMessage;
8+
use RonasIT\Support\Exceptions\ClassNotExistsException;
89
use RonasIT\Support\Exceptions\EntityCreateException;
910
use RonasIT\Support\Generators\ControllerGenerator;
1011
use RonasIT\Support\Generators\EntityGenerator;
@@ -50,6 +51,8 @@ class MakeEntityCommand extends Command
5051
{--without-tests : Set this flag if you don\'t want to create tests. This flag is a lower priority than --only-tests.}
5152
{--without-seeder : Set this flag if you don\'t want to create seeder.}
5253
54+
{--only-api : Set this flag if you want to create controller, route, requests, tests.}
55+
{--only-entity : Set this flag if you want to create migration, model, repository, service, factory, seeder.}
5356
{--only-model : Set this flag if you want to create only model. This flag is a higher priority than --without-model, --only-migration, --only-tests and --only-repository.}
5457
{--only-repository : Set this flag if you want to create only repository. This flag is a higher priority than --without-repository, --only-tests and --only-migration.}
5558
{--only-service : Set this flag if you want to create only service.}
@@ -98,6 +101,8 @@ class MakeEntityCommand extends Command
98101

99102
protected $rules = [
100103
'only' => [
104+
'only-api' => [ControllerGenerator::class, RequestsGenerator::class, TestsGenerator::class],
105+
'only-entity' => [MigrationGenerator::class, ModelGenerator::class, ServiceGenerator::class, RepositoryGenerator::class, FactoryGenerator::class, SeederGenerator::class],
101106
'only-model' => [ModelGenerator::class],
102107
'only-repository' => [RepositoryGenerator::class],
103108
'only-service' => [ServiceGenerator::class],
@@ -150,6 +155,7 @@ public function __construct()
150155
*/
151156
public function handle()
152157
{
158+
$this->validateInput();
153159
$this->eventDispatcher->listen(SuccessCreateMessage::class, $this->getSuccessMessageCallback());
154160

155161
try {
@@ -159,6 +165,27 @@ public function handle()
159165
}
160166
}
161167

168+
protected function classExists($path, $name)
169+
{
170+
$paths = config('entity-generator.paths');
171+
172+
$entitiesPath = $paths[$path];
173+
174+
$classPath = base_path("{$entitiesPath}/{$name}.php");
175+
176+
return file_exists($classPath);
177+
}
178+
179+
protected function validateInput()
180+
{
181+
if ($this->option('only-api')) {
182+
$modelName = $this->argument('name');
183+
if (!$this->classExists('services', "{$modelName}Service")) {
184+
throw new ClassNotExistsException('Cannot create API without entity.');
185+
}
186+
}
187+
}
188+
162189
protected function generate()
163190
{
164191
foreach ($this->rules['only'] as $option => $generators) {

0 commit comments

Comments
 (0)