From c4d9188384a1769ef12c669c4503999ee687ed5c Mon Sep 17 00:00:00 2001 From: davood Date: Thu, 14 Dec 2023 18:21:05 +0330 Subject: [PATCH] now makeDTO uses custom stubs if they exists --- src/Console/Commands/MakeDTOCommand.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Console/Commands/MakeDTOCommand.php b/src/Console/Commands/MakeDTOCommand.php index ae13239..1e56710 100644 --- a/src/Console/Commands/MakeDTOCommand.php +++ b/src/Console/Commands/MakeDTOCommand.php @@ -56,11 +56,21 @@ protected function getPath($name) protected function getStub(): string { - return match (true) { - $this->option('resource') => __DIR__ . '/../stubs/resource_dto.stub', - $this->option('simple') => __DIR__ . '/../stubs/simple_dto.stub', - default => __DIR__ . '/../stubs/dto.stub', - }; + return $this->resolveStubPath(match (true) { + $this->option('resource') => 'resource_dto.stub', + $this->option('simple') => 'simple_dto.stub', + default => 'dto.stub', + }); + } + + /** + * Resolve the fully-qualified path to the stub. + */ + protected function resolveStubPath(string $stub): string + { + return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__ . '/../stubs/' . $stub; } protected function getOptions(): array