ekart/backend/app/Console/Commands/MakeDtoCommand.php
kusowl 61ecbec994 chore: add command to generate dto
- add make:dto command which generates dto in App\Data namespace
- varient: --input (default), --output
2026-03-13 11:28:22 +05:30

64 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;
class MakeDtoCommand extends GeneratorCommand
{
/**
* The console command name and signature.
*
* @var string
*/
protected $name = 'make:dto';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new Data Transfer Object class';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'DTO';
/**
* Get the stub file for the generator.
*/
protected function getStub(): string
{
if ($this->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'],
];
}
}