diff --git a/src/Commands/Concerns/HasDomainStubs.php b/src/Commands/Concerns/HasDomainStubs.php new file mode 100644 index 0000000..9d935f1 --- /dev/null +++ b/src/Commands/Concerns/HasDomainStubs.php @@ -0,0 +1,55 @@ +basename() + ->ltrim('/\\') + ->toString(); + + $publishedPath = resource_path('stubs/ddd/'.$path); + + if (file_exists($publishedPath)) { + return $publishedPath; + } + + $legacyPublishedPath = Str::replaceLast('.stub', '.php.stub', $publishedPath); + + if (file_exists($legacyPublishedPath)) { + return $legacyPublishedPath; + } + + return DDD::packagePath('stubs/'.$path); + } + + protected function resolveStubPath($stub) + { + $defaultStub = parent::resolveStubPath($stub); + + $stubFilename = basename($stub); + + // Check if there is a user-published stub + $publishedPath = app()->basePath('stubs/ddd/'.$stubFilename); + + if (file_exists($publishedPath)) { + return $publishedPath; + } + + $legacyPublishedPath = Str::replaceLast('.stub', '.php.stub', $publishedPath); + + if (file_exists($legacyPublishedPath)) { + return $legacyPublishedPath; + } + + return $defaultStub; + } +} diff --git a/src/Commands/Concerns/InteractsWithStubs.php b/src/Commands/Concerns/InteractsWithStubs.php new file mode 100644 index 0000000..02e9472 --- /dev/null +++ b/src/Commands/Concerns/InteractsWithStubs.php @@ -0,0 +1,32 @@ +preparePlaceholders(); + + foreach ($placeholders as $placeholder => $value) { + $stub = $this->fillPlaceholder($stub, $placeholder, $value ?? ''); + } + + return $stub; + } + + protected function buildClass($name) + { + return $this->applyPlaceholders(parent::buildClass($name)); + } +} diff --git a/src/Commands/DomainActionMakeCommand.php b/src/Commands/DomainActionMakeCommand.php index c1a14f2..96002db 100644 --- a/src/Commands/DomainActionMakeCommand.php +++ b/src/Commands/DomainActionMakeCommand.php @@ -17,7 +17,7 @@ class DomainActionMakeCommand extends DomainGeneratorCommand protected function getStub() { - return $this->resolveStubPath('action.php.stub'); + return $this->resolveDddStubPath('action.stub'); } protected function preparePlaceholders(): array diff --git a/src/Commands/DomainBaseModelMakeCommand.php b/src/Commands/DomainBaseModelMakeCommand.php index 559cd59..114f57d 100644 --- a/src/Commands/DomainBaseModelMakeCommand.php +++ b/src/Commands/DomainBaseModelMakeCommand.php @@ -31,7 +31,7 @@ protected function getArguments() protected function getStub() { - return $this->resolveStubPath('base-model.php.stub'); + return $this->resolveDddStubPath('base-model.stub'); } protected function getRelativeDomainNamespace(): string diff --git a/src/Commands/DomainBaseViewModelMakeCommand.php b/src/Commands/DomainBaseViewModelMakeCommand.php index afac4f7..ac54d0d 100644 --- a/src/Commands/DomainBaseViewModelMakeCommand.php +++ b/src/Commands/DomainBaseViewModelMakeCommand.php @@ -31,7 +31,7 @@ protected function getArguments() protected function getStub() { - return $this->resolveStubPath('base-view-model.php.stub'); + return $this->resolveDddStubPath('base-view-model.stub'); } protected function getRelativeDomainNamespace(): string diff --git a/src/Commands/DomainCastMakeCommand.php b/src/Commands/DomainCastMakeCommand.php index 30531e4..da230a0 100644 --- a/src/Commands/DomainCastMakeCommand.php +++ b/src/Commands/DomainCastMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\CastMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainCastMakeCommand extends CastMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:cast'; } diff --git a/src/Commands/DomainChannelMakeCommand.php b/src/Commands/DomainChannelMakeCommand.php index f3e5ba5..3bee9b9 100644 --- a/src/Commands/DomainChannelMakeCommand.php +++ b/src/Commands/DomainChannelMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ChannelMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainChannelMakeCommand extends ChannelMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:channel'; } diff --git a/src/Commands/DomainClassMakeCommand.php b/src/Commands/DomainClassMakeCommand.php index 242788b..a657407 100644 --- a/src/Commands/DomainClassMakeCommand.php +++ b/src/Commands/DomainClassMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ClassMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainClassMakeCommand extends ClassMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:class'; } diff --git a/src/Commands/DomainConsoleMakeCommand.php b/src/Commands/DomainConsoleMakeCommand.php index 6496db9..f78cd39 100644 --- a/src/Commands/DomainConsoleMakeCommand.php +++ b/src/Commands/DomainConsoleMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ConsoleMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainConsoleMakeCommand extends ConsoleMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:command'; } diff --git a/src/Commands/DomainControllerMakeCommand.php b/src/Commands/DomainControllerMakeCommand.php index aa2a373..93febe0 100644 --- a/src/Commands/DomainControllerMakeCommand.php +++ b/src/Commands/DomainControllerMakeCommand.php @@ -4,6 +4,7 @@ use Illuminate\Routing\Console\ControllerMakeCommand; use Lunarstorm\LaravelDDD\Commands\Concerns\ForwardsToDomainCommands; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; use function Laravel\Prompts\confirm; @@ -11,6 +12,7 @@ class DomainControllerMakeCommand extends ControllerMakeCommand { use ForwardsToDomainCommands, + HasDomainStubs, ResolvesDomainFromInput; protected $name = 'ddd:controller'; diff --git a/src/Commands/DomainDtoMakeCommand.php b/src/Commands/DomainDtoMakeCommand.php index ac4ef3f..793aa33 100644 --- a/src/Commands/DomainDtoMakeCommand.php +++ b/src/Commands/DomainDtoMakeCommand.php @@ -28,7 +28,7 @@ protected function configure() protected function getStub() { - return $this->resolveStubPath('dto.php.stub'); + return $this->resolveDddStubPath('dto.stub'); } protected function getRelativeDomainNamespace(): string diff --git a/src/Commands/DomainEnumMakeCommand.php b/src/Commands/DomainEnumMakeCommand.php index d3110b7..3348186 100644 --- a/src/Commands/DomainEnumMakeCommand.php +++ b/src/Commands/DomainEnumMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\EnumMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainEnumMakeCommand extends EnumMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:enum'; } diff --git a/src/Commands/DomainEventMakeCommand.php b/src/Commands/DomainEventMakeCommand.php index de4a11b..fcba974 100644 --- a/src/Commands/DomainEventMakeCommand.php +++ b/src/Commands/DomainEventMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\EventMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainEventMakeCommand extends EventMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:event'; } diff --git a/src/Commands/DomainExceptionMakeCommand.php b/src/Commands/DomainExceptionMakeCommand.php index c9871e7..f794dc1 100644 --- a/src/Commands/DomainExceptionMakeCommand.php +++ b/src/Commands/DomainExceptionMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ExceptionMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainExceptionMakeCommand extends ExceptionMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:exception'; } diff --git a/src/Commands/DomainFactoryMakeCommand.php b/src/Commands/DomainFactoryMakeCommand.php index 6a1a104..3676641 100644 --- a/src/Commands/DomainFactoryMakeCommand.php +++ b/src/Commands/DomainFactoryMakeCommand.php @@ -2,50 +2,25 @@ namespace Lunarstorm\LaravelDDD\Commands; -use Symfony\Component\Console\Input\InputOption; +use Illuminate\Database\Console\Factories\FactoryMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; +use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; -class DomainFactoryMakeCommand extends DomainGeneratorCommand +class DomainFactoryMakeCommand extends FactoryMakeCommand { - protected $name = 'ddd:factory'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Generate a domain model factory'; + use HasDomainStubs, + ResolvesDomainFromInput; - protected $type = 'Factory'; - - protected function getOptions() - { - return [ - ...parent::getOptions(), - ['model', 'm', InputOption::VALUE_OPTIONAL, 'The name of the model'], - ]; - } + protected $name = 'ddd:factory'; protected function getStub() { - return $this->resolveStubPath('factory.php.stub'); + return $this->resolveDddStubPath('factory.stub'); } - protected function getPath($name) + protected function getNamespace($name) { - if (! str_ends_with($name, 'Factory')) { - $name .= 'Factory'; - } - - return parent::getPath($name); - } - - protected function getFactoryName() - { - $name = $this->getNameInput(); - - return str_ends_with($name, 'Factory') - ? substr($name, 0, -7) - : $name; + return $this->domain->namespaceFor('factory'); } protected function preparePlaceholders(): array @@ -60,16 +35,10 @@ protected function preparePlaceholders(): array $domainFactory = $domain->factory($name); - // dump('preparing placeholders', [ - // 'name' => $name, - // 'modelName' => $modelName, - // 'domainFactory' => $domainFactory, - // ]); - return [ 'namespacedModel' => $domainModel->fullyQualifiedName, 'model' => class_basename($domainModel->fullyQualifiedName), - 'factory' => $this->getFactoryName(), + 'factory' => $domainFactory->name, 'namespace' => $domainFactory->namespace, ]; } @@ -80,6 +49,6 @@ protected function guessModelName($name) $name = substr($name, 0, -7); } - return $this->domain->model($name)->name; + return $this->domain->model(class_basename($name))->name; } } diff --git a/src/Commands/DomainGeneratorCommand.php b/src/Commands/DomainGeneratorCommand.php index 6421409..8241339 100644 --- a/src/Commands/DomainGeneratorCommand.php +++ b/src/Commands/DomainGeneratorCommand.php @@ -4,12 +4,14 @@ use Illuminate\Console\GeneratorCommand; use Illuminate\Support\Str; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; use Lunarstorm\LaravelDDD\Support\DomainResolver; abstract class DomainGeneratorCommand extends GeneratorCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected function getRelativeDomainNamespace(): string { @@ -21,40 +23,40 @@ protected function getNameInput() return Str::studly($this->argument('name')); } - protected function resolveStubPath($path) - { - $path = ltrim($path, '/\\'); + // protected function resolveStubPath($path) + // { + // $path = ltrim($path, '/\\'); - $publishedPath = resource_path('stubs/ddd/'.$path); + // $publishedPath = resource_path('stubs/ddd/'.$path); - return file_exists($publishedPath) - ? $publishedPath - : __DIR__.DIRECTORY_SEPARATOR.'../../stubs'.DIRECTORY_SEPARATOR.$path; - } + // return file_exists($publishedPath) + // ? $publishedPath + // : __DIR__.DIRECTORY_SEPARATOR.'../../stubs'.DIRECTORY_SEPARATOR.$path; + // } - protected function fillPlaceholder($stub, $placeholder, $value) - { - return str_replace(["{{$placeholder}}", "{{ $placeholder }}"], $value, $stub); - } + // protected function fillPlaceholder($stub, $placeholder, $value) + // { + // return str_replace(["{{$placeholder}}", "{{ $placeholder }}"], $value, $stub); + // } - protected function preparePlaceholders(): array - { - return []; - } + // protected function preparePlaceholders(): array + // { + // return []; + // } - protected function applyPlaceholders($stub) - { - $placeholders = $this->preparePlaceholders(); + // protected function applyPlaceholders($stub) + // { + // $placeholders = $this->preparePlaceholders(); - foreach ($placeholders as $placeholder => $value) { - $stub = $this->fillPlaceholder($stub, $placeholder, $value ?? ''); - } + // foreach ($placeholders as $placeholder => $value) { + // $stub = $this->fillPlaceholder($stub, $placeholder, $value ?? ''); + // } - return $stub; - } + // return $stub; + // } - protected function buildClass($name) - { - return $this->applyPlaceholders(parent::buildClass($name)); - } + // protected function buildClass($name) + // { + // return $this->applyPlaceholders(parent::buildClass($name)); + // } } diff --git a/src/Commands/DomainInterfaceMakeCommand.php b/src/Commands/DomainInterfaceMakeCommand.php index 3fbccef..82735d6 100644 --- a/src/Commands/DomainInterfaceMakeCommand.php +++ b/src/Commands/DomainInterfaceMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\InterfaceMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainInterfaceMakeCommand extends InterfaceMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:interface'; } diff --git a/src/Commands/DomainJobMakeCommand.php b/src/Commands/DomainJobMakeCommand.php index 7fc5e37..fd9afbd 100644 --- a/src/Commands/DomainJobMakeCommand.php +++ b/src/Commands/DomainJobMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\JobMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainJobMakeCommand extends JobMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:job'; } diff --git a/src/Commands/DomainListenerMakeCommand.php b/src/Commands/DomainListenerMakeCommand.php index 9726d20..0072172 100644 --- a/src/Commands/DomainListenerMakeCommand.php +++ b/src/Commands/DomainListenerMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ListenerMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainListenerMakeCommand extends ListenerMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:listener'; } diff --git a/src/Commands/DomainMailMakeCommand.php b/src/Commands/DomainMailMakeCommand.php index 15f9508..ef6d0e8 100644 --- a/src/Commands/DomainMailMakeCommand.php +++ b/src/Commands/DomainMailMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\MailMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainMailMakeCommand extends MailMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:mail'; } diff --git a/src/Commands/DomainMiddlewareMakeCommand.php b/src/Commands/DomainMiddlewareMakeCommand.php index 2c6b2af..9a2a041 100644 --- a/src/Commands/DomainMiddlewareMakeCommand.php +++ b/src/Commands/DomainMiddlewareMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Routing\Console\MiddlewareMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainMiddlewareMakeCommand extends MiddlewareMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:middleware'; } diff --git a/src/Commands/DomainModelMakeCommand.php b/src/Commands/DomainModelMakeCommand.php index c92ccdd..f57674e 100644 --- a/src/Commands/DomainModelMakeCommand.php +++ b/src/Commands/DomainModelMakeCommand.php @@ -5,12 +5,14 @@ use Illuminate\Foundation\Console\ModelMakeCommand; use Illuminate\Support\Str; use Lunarstorm\LaravelDDD\Commands\Concerns\ForwardsToDomainCommands; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; use Lunarstorm\LaravelDDD\Support\DomainResolver; class DomainModelMakeCommand extends ModelMakeCommand { use ForwardsToDomainCommands, + HasDomainStubs, ResolvesDomainFromInput; protected $name = 'ddd:model'; diff --git a/src/Commands/DomainModelMakeLegacyCommand.php b/src/Commands/DomainModelMakeLegacyCommand.php deleted file mode 100644 index 37c8164..0000000 --- a/src/Commands/DomainModelMakeLegacyCommand.php +++ /dev/null @@ -1,108 +0,0 @@ -resolveStubPath('model.php.stub'); - } - - protected function preparePlaceholders(): array - { - $baseClass = config('ddd.base_model'); - $baseClassName = class_basename($baseClass); - - return [ - 'extends' => filled($baseClass) ? " extends {$baseClassName}" : '', - 'baseClassImport' => filled($baseClass) ? "use {$baseClass};" : '', - ]; - } - - public function handle() - { - $this->createBaseModelIfNeeded(); - - parent::handle(); - - if ($this->option('factory')) { - $this->createFactory(); - } - } - - protected function createBaseModelIfNeeded() - { - if (! $this->shouldCreateBaseModel()) { - return; - } - - $baseModel = config('ddd.base_model'); - - $this->warn("Base model {$baseModel} doesn't exist, generating..."); - - $domain = DomainResolver::guessDomainFromClass($baseModel); - - $name = Str::after($baseModel, $domain); - - $this->call(DomainBaseModelMakeCommand::class, [ - '--domain' => $domain, - 'name' => $name, - ]); - } - - protected function shouldCreateBaseModel(): bool - { - $baseModel = config('ddd.base_model'); - - // If the class exists, we don't need to create it. - if (class_exists($baseModel)) { - return false; - } - - // If the class is outside of the domain layer, we won't attempt to create it. - if (! DomainResolver::isDomainClass($baseModel)) { - return false; - } - - // At this point the class is probably a domain object, but we should - // check if the expected path exists. - if (file_exists(app()->basePath(DomainResolver::guessPathFromClass($baseModel)))) { - return false; - } - - return true; - } - - protected function createFactory() - { - $this->call(DomainFactoryMakeCommand::class, [ - 'name' => $this->getNameInput().'Factory', - '--domain' => $this->domain->dotName, - '--model' => $this->qualifyClass($this->getNameInput()), - ]); - } -} diff --git a/src/Commands/DomainNotificationMakeCommand.php b/src/Commands/DomainNotificationMakeCommand.php index 04de8ab..099cd9a 100644 --- a/src/Commands/DomainNotificationMakeCommand.php +++ b/src/Commands/DomainNotificationMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\NotificationMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainNotificationMakeCommand extends NotificationMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:notification'; } diff --git a/src/Commands/DomainObserverMakeCommand.php b/src/Commands/DomainObserverMakeCommand.php index 9668230..9351b53 100644 --- a/src/Commands/DomainObserverMakeCommand.php +++ b/src/Commands/DomainObserverMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ObserverMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainObserverMakeCommand extends ObserverMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:observer'; } diff --git a/src/Commands/DomainPolicyMakeCommand.php b/src/Commands/DomainPolicyMakeCommand.php index bbf57f3..180223f 100644 --- a/src/Commands/DomainPolicyMakeCommand.php +++ b/src/Commands/DomainPolicyMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\PolicyMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainPolicyMakeCommand extends PolicyMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:policy'; } diff --git a/src/Commands/DomainProviderMakeCommand.php b/src/Commands/DomainProviderMakeCommand.php index dcc2c8a..8ee4dcc 100644 --- a/src/Commands/DomainProviderMakeCommand.php +++ b/src/Commands/DomainProviderMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ProviderMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainProviderMakeCommand extends ProviderMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:provider'; } diff --git a/src/Commands/DomainRequestMakeCommand.php b/src/Commands/DomainRequestMakeCommand.php index a6a1ddf..88cad30 100644 --- a/src/Commands/DomainRequestMakeCommand.php +++ b/src/Commands/DomainRequestMakeCommand.php @@ -4,20 +4,17 @@ use Illuminate\Foundation\Console\RequestMakeCommand; use Illuminate\Support\Str; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; use Lunarstorm\LaravelDDD\Support\DomainResolver; class DomainRequestMakeCommand extends RequestMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:request'; - // protected function getDefaultNamespace($rootNamespace) - // { - // return $rootNamespace.'\Http\Requests'; - // } - protected function rootNamespace() { $type = $this->guessObjectType(); diff --git a/src/Commands/DomainResourceMakeCommand.php b/src/Commands/DomainResourceMakeCommand.php index 36b3715..4e79208 100644 --- a/src/Commands/DomainResourceMakeCommand.php +++ b/src/Commands/DomainResourceMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ResourceMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainResourceMakeCommand extends ResourceMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:resource'; } diff --git a/src/Commands/DomainRuleMakeCommand.php b/src/Commands/DomainRuleMakeCommand.php index 50c6083..f82aec1 100644 --- a/src/Commands/DomainRuleMakeCommand.php +++ b/src/Commands/DomainRuleMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\RuleMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainRuleMakeCommand extends RuleMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:rule'; } diff --git a/src/Commands/DomainScopeMakeCommand.php b/src/Commands/DomainScopeMakeCommand.php index 9dfe7d7..43e2fd0 100644 --- a/src/Commands/DomainScopeMakeCommand.php +++ b/src/Commands/DomainScopeMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\ScopeMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainScopeMakeCommand extends ScopeMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:scope'; } diff --git a/src/Commands/DomainSeederMakeCommand.php b/src/Commands/DomainSeederMakeCommand.php index 6ee413d..302a073 100644 --- a/src/Commands/DomainSeederMakeCommand.php +++ b/src/Commands/DomainSeederMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Database\Console\Seeds\SeederMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainSeederMakeCommand extends SeederMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:seeder'; } diff --git a/src/Commands/DomainTraitMakeCommand.php b/src/Commands/DomainTraitMakeCommand.php index d377b52..1cb86a5 100644 --- a/src/Commands/DomainTraitMakeCommand.php +++ b/src/Commands/DomainTraitMakeCommand.php @@ -3,11 +3,13 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Foundation\Console\TraitMakeCommand; +use Lunarstorm\LaravelDDD\Commands\Concerns\HasDomainStubs; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; class DomainTraitMakeCommand extends TraitMakeCommand { - use ResolvesDomainFromInput; + use HasDomainStubs, + ResolvesDomainFromInput; protected $name = 'ddd:trait'; } diff --git a/src/Commands/DomainValueObjectMakeCommand.php b/src/Commands/DomainValueObjectMakeCommand.php index 27de72b..52b80f8 100644 --- a/src/Commands/DomainValueObjectMakeCommand.php +++ b/src/Commands/DomainValueObjectMakeCommand.php @@ -27,6 +27,6 @@ protected function configure() protected function getStub() { - return $this->resolveStubPath('value-object.php.stub'); + return $this->resolveDddStubPath('value-object.stub'); } } diff --git a/src/Commands/DomainViewModelMakeCommand.php b/src/Commands/DomainViewModelMakeCommand.php index e097cae..b071955 100644 --- a/src/Commands/DomainViewModelMakeCommand.php +++ b/src/Commands/DomainViewModelMakeCommand.php @@ -29,7 +29,7 @@ protected function configure() protected function getStub() { - return $this->resolveStubPath('view-model.php.stub'); + return $this->resolveDddStubPath('view-model.stub'); } protected function preparePlaceholders(): array diff --git a/src/DomainManager.php b/src/DomainManager.php index 13d465a..767d185 100755 --- a/src/DomainManager.php +++ b/src/DomainManager.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Lunarstorm\LaravelDDD\Support\Domain; +use Lunarstorm\LaravelDDD\Support\Path; use Lunarstorm\LaravelDDD\ValueObjects\DomainCommandContext; class DomainManager @@ -78,4 +79,9 @@ public function getCommandContext(): ?DomainCommandContext { return $this->commandContext; } + + public function packagePath($path = ''): string + { + return Path::normalize(__DIR__.'/../'.$path); + } } diff --git a/src/Facades/DDD.php b/src/Facades/DDD.php index a5aba45..bd16c3a 100644 --- a/src/Facades/DDD.php +++ b/src/Facades/DDD.php @@ -9,6 +9,7 @@ * * @method static void filterAutoloadPathsUsing(callable $filter) * @method static void resolveNamespaceUsing(callable $resolver) + * @method static string packagePath(string $path = '') */ class DDD extends Facade { diff --git a/src/LaravelDDDServiceProvider.php b/src/LaravelDDDServiceProvider.php index 106ec30..95d9995 100644 --- a/src/LaravelDDDServiceProvider.php +++ b/src/LaravelDDDServiceProvider.php @@ -87,7 +87,7 @@ protected function registerMigrations() public function packageBooted() { $this->publishes([ - $this->package->basePath('/../stubs') => resource_path("stubs/{$this->package->shortName()}"), + $this->package->basePath('/../stubs') => base_path("stubs/{$this->package->shortName()}"), ], "{$this->package->shortName()}-stubs"); if ($this->app->runningInConsole() && method_exists($this, 'optimizes')) { diff --git a/src/Support/Domain.php b/src/Support/Domain.php index 225fe61..e36fab8 100644 --- a/src/Support/Domain.php +++ b/src/Support/Domain.php @@ -140,6 +140,7 @@ public function object(string $type, string $name, bool $absolute = false): Doma $baseName = str($name)->replace($namespace, '') ->replace(['\\', '/'], '\\') ->trim('\\') + ->when($type === 'factory', fn ($name) => $name->finish('Factory')) ->toString(); $fullyQualifiedName = $namespace.'\\'.$baseName; diff --git a/stubs/action.php.stub b/stubs/action.stub similarity index 100% rename from stubs/action.php.stub rename to stubs/action.stub diff --git a/stubs/base-model.php.stub b/stubs/base-model.stub similarity index 100% rename from stubs/base-model.php.stub rename to stubs/base-model.stub diff --git a/stubs/base-view-model.php.stub b/stubs/base-view-model.stub similarity index 100% rename from stubs/base-view-model.php.stub rename to stubs/base-view-model.stub diff --git a/stubs/dto.php.stub b/stubs/dto.stub similarity index 100% rename from stubs/dto.php.stub rename to stubs/dto.stub diff --git a/stubs/factory.php.stub b/stubs/factory.stub similarity index 100% rename from stubs/factory.php.stub rename to stubs/factory.stub diff --git a/stubs/model.php.stub b/stubs/model.php.stub deleted file mode 100644 index e775c33..0000000 --- a/stubs/model.php.stub +++ /dev/null @@ -1,13 +0,0 @@ -