From 61ecbec994c610921fec56a37343e1ff3dfb7015 Mon Sep 17 00:00:00 2001 From: kusowl Date: Fri, 13 Mar 2026 11:28:22 +0530 Subject: [PATCH] chore: add command to generate dto - add make:dto command which generates dto in App\Data namespace - varient: --input (default), --output --- .../app/Console/Commands/MakeDtoCommand.php | 63 +++++++++++++++++++ backend/stubs/dto.input.stub | 30 +++++++++ backend/stubs/dto.output.stub | 30 +++++++++ 3 files changed, 123 insertions(+) create mode 100644 backend/app/Console/Commands/MakeDtoCommand.php create mode 100644 backend/stubs/dto.input.stub create mode 100644 backend/stubs/dto.output.stub diff --git a/backend/app/Console/Commands/MakeDtoCommand.php b/backend/app/Console/Commands/MakeDtoCommand.php new file mode 100644 index 0000000..2a5005d --- /dev/null +++ b/backend/app/Console/Commands/MakeDtoCommand.php @@ -0,0 +1,63 @@ +option('output')) { + return base_path('stubs/dto.output.stub'); + } + + return base_path('stubs/dto.input.stub'); + } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + */ + protected function getDefaultNamespace($rootNamespace): string + { + return $rootNamespace.'\Data'; + } + + /** + * Get the console command options. + */ + protected function getOptions(): array + { + return [ + ['input', 'i', InputOption::VALUE_NONE, 'Generate an Input DTO (default)'], + ['output', 'o', InputOption::VALUE_NONE, 'Generate an Output DTO'], + ]; + } +} diff --git a/backend/stubs/dto.input.stub b/backend/stubs/dto.input.stub new file mode 100644 index 0000000..184901f --- /dev/null +++ b/backend/stubs/dto.input.stub @@ -0,0 +1,30 @@ + + */ + public function toArray(): array + { + return [ + // TODO: Map properties to array + ]; + } + + public static function fromRequest(FormRequest $request): InputDataTransferObject + { + return new self( + // TODO: Map request data to properties + ); + } +} diff --git a/backend/stubs/dto.output.stub b/backend/stubs/dto.output.stub new file mode 100644 index 0000000..23c1d5b --- /dev/null +++ b/backend/stubs/dto.output.stub @@ -0,0 +1,30 @@ + + */ + public function toArray(): array + { + return [ + // TODO: Map properties to array + ]; + } + + public static function fromModel(Model $model): OutputDataTransferObject + { + return new self( + // TODO: Map model data to properties + ); + } +}