Skip to content

Commit 0a53d5d

Browse files
committed
Introduced applayer commands, and make:resource
1 parent fb308bb commit 0a53d5d

File tree

6 files changed

+82
-6
lines changed

6 files changed

+82
-6
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ sail artisan vendor:publish --tag=ddd-commands
2424

2525
_Config explanation is added inside the published ddd-commands.php file_
2626

27-
## Commands:
27+
## App layer Commands:
28+
If you are not using sail please replace "sail" with "php" in commands below
29+
30+
| Command | Default output path | Documentation |
31+
|----------------------------------------------------------|------------------------------------------|--------------------------------------------------------------------------|
32+
| `sail artisan make:resource {app_layer} {domain} {name}` | `src/App/{app_layer}/{domain}/Resources` | [Laravel Documentation](https://laravel.com/docs/9.x/eloquent-resources) |
33+
34+
## Domain Commands:
2835
If you are not using sail please replace "sail" with "php" in commands below
2936

3037
| Command | Default output path | Documentation |
3138
|--------------------------------------------|-------------------------------------------|---------------------------------------------------------------------------------|
32-
| `sail artisan make:model {domain} {name}` | `src/Domain/{domain}/Models` | [Laravel Documentation](https://laravel.com/docs/8.x/eloquent) |
33-
| `sail artisan make:job {domain} {name}` | `src/Domain/{domain}/Jobs` | [Laravel Documentation](https://laravel.com/docs/8.x/queues#creating-jobs) |
34-
| `sail artisan make:mail {domain} {name}` | `src/Domain/{domain}/Mails` | [Laravel Documentation](https://laravel.com/docs/8.x/mail#generating-mailables) |
39+
| `sail artisan make:model {domain} {name}` | `src/Domain/{domain}/Models` | [Laravel Documentation](https://laravel.com/docs/9.x/eloquent) |
40+
| `sail artisan make:job {domain} {name}` | `src/Domain/{domain}/Jobs` | [Laravel Documentation](https://laravel.com/docs/9.x/queues#creating-jobs) |
41+
| `sail artisan make:mail {domain} {name}` | `src/Domain/{domain}/Mails` | [Laravel Documentation](https://laravel.com/docs/9.x/mail#generating-mailables) |
3542
| `sail artisan make:action {domain} {name}` | `src/Domain/{domain}/Actions` | (None yet) |
3643
| `sail artisan make:dto {domain} {name}` | `src/Domain/{domain}/DataTransferObjects` | (None yet) |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace DomainDrivenLaravel\Commands\Console\Commands;
4+
5+
use DomainDrivenLaravel\Commands\Console\Traits\AppLayerCommandTrait;
6+
use Illuminate\Filesystem\Filesystem;
7+
use Illuminate\Foundation\Console\ResourceMakeCommand as Command;
8+
9+
class ResourceMakeCommand extends Command
10+
{
11+
use AppLayerCommandTrait;
12+
13+
protected $name = 'make:resource';
14+
protected $signature = 'make:resource {app_layer} {domain} {name} {--collection}';
15+
16+
public function __construct()
17+
{
18+
parent::__construct(new Filesystem());
19+
}
20+
21+
protected function subdirectoryName(): string
22+
{
23+
return 'Resources';
24+
}
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace DomainDrivenLaravel\Commands\Console\Traits;
4+
5+
use Illuminate\Support\Str;
6+
7+
trait AppLayerCommandTrait
8+
{
9+
abstract public function argument($key = null);
10+
abstract protected function subdirectoryName(): string;
11+
12+
protected function rootNamespace(): string
13+
{
14+
return config('ddd-commands.app_layer.root_namespace');
15+
}
16+
17+
protected function getPath($name): string
18+
{
19+
$name = Str::replaceFirst($this->rootNamespace(), '', $name);
20+
21+
return config('ddd-commands.app_layer.path').str_replace('\\', '/', $name).'.php';
22+
}
23+
24+
protected function getDefaultNamespace($rootNamespace): string
25+
{
26+
$appLayer = ucfirst($this->argument('app_layer'));
27+
$domain = ucfirst($this->argument('domain'));
28+
29+
return "{$rootNamespace}\\{$appLayer}\\{$domain}\\{$this->subdirectoryName()}";
30+
}
31+
}

src/Console/Traits/DomainCommandTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ protected function rootNamespace(): string
1616

1717
protected function getPath($name): string
1818
{
19+
$name = ucfirst($name);
20+
1921
$name = Str::replaceFirst($this->rootNamespace(), '', $name);
2022

2123
return config('ddd-commands.domain.path').str_replace('\\', '/', $name).'.php';
2224
}
2325

2426
protected function getDefaultNamespace($rootNamespace): string
2527
{
26-
$domain = $this->argument('domain');
28+
$domain = ucfirst($this->argument('domain'));
2729

2830
return "{$rootNamespace}\\{$domain}\\{$this->subdirectoryName()}";
2931
}

src/Providers/DomainDrivenCommandsProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use DomainDrivenLaravel\Commands\Console\Commands\JobMakeCommand;
66
use DomainDrivenLaravel\Commands\Console\Commands\MailMakeCommand;
7+
use DomainDrivenLaravel\Commands\Console\Commands\ResourceMakeCommand;
78
use Illuminate\Support\ServiceProvider;
89
use Illuminate\Contracts\Support\DeferrableProvider;
910
use DomainDrivenLaravel\Commands\Console\Commands\ActionMakeCommand;
@@ -31,8 +32,9 @@ public function boot()
3132
[
3233
ModelMakeCommand::class,
3334
JobMakeCommand::class,
34-
MailMakeCommand::class,
3535
ActionMakeCommand::class,
36+
MailMakeCommand::class,
37+
ResourceMakeCommand::class,
3638
DataTransferObjectMakeCommand::class,
3739
]
3840
);
@@ -64,6 +66,10 @@ public function register()
6466
$this->app->extend('command.mail.make', function (\Illuminate\Foundation\Console\MailMakeCommand $command) {
6567
return new MailMakeCommand;
6668
});
69+
70+
$this->app->extend('command.resource.make', function (\Illuminate\Foundation\Console\ResourceMakeCommand $command) {
71+
return new ResourceMakeCommand;
72+
});
6773
}
6874

6975
/**
@@ -78,6 +84,7 @@ public function provides(): array
7884
'command.make.job',
7985
'command.make.mail',
8086
'command.make.action',
87+
'command.make.resource',
8188
'command.make.dto',
8289
];
8390
}

src/config/ddd-commands.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
'domain' => [
99
'root_namespace' => 'Domain',
1010
'path' => 'src/Domain/'
11+
],
12+
'app_layer' => [
13+
'root_namespace' => 'App',
14+
'path' => 'src/App/'
1115
]
1216
];

0 commit comments

Comments
 (0)