Files
laravel_modules/src/Commands/FactoryMakeCommand.php
T
2026-04-21 09:12:51 +01:00

77 lines
1.6 KiB
PHP
Executable File

<?php
namespace mpba\Modules\Commands;
use Illuminate\Support\Str;
use mpba\Modules\Support\Config\GenerateConfigReader;
use mpba\Modules\Support\Stub;
use mpba\Modules\Traits\ModuleCommandTrait;
use Symfony\Component\Console\Input\InputArgument;
class FactoryMakeCommand extends GeneratorCommand
{
use ModuleCommandTrait;
/**
* The name of argument name.
*
* @var string
*/
protected $argumentName = 'name';
/**
* The console command name.
*
* @var string
*/
protected $name = 'module:make-factory';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new model factory for the specified module.';
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'The name of the factory.'],
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
];
}
/**
* @return mixed
*/
protected function getTemplateContents()
{
return (new Stub('/factory.stub'))->render();
}
/**
* @return mixed
*/
protected function getDestinationFilePath()
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
$factoryPath = GenerateConfigReader::read('factory');
return $path.$factoryPath->getPath().'/'.$this->getFileName();
}
/**
* @return string
*/
private function getFileName()
{
return Str::studly($this->argument('name')).'.php';
}
}