This commit is contained in:
Sampanna Rimal
2024-09-04 12:22:04 +05:45
parent 53c0140f58
commit 82fab174dc
203 changed files with 4255 additions and 1343 deletions

View File

@ -0,0 +1,76 @@
<?php
namespace Nwidart\Modules\Commands\Make;
use Illuminate\Support\Str;
use Nwidart\Modules\Support\Config\GenerateConfigReader;
use Nwidart\Modules\Support\Stub;
use Nwidart\Modules\Traits\ModuleCommandTrait;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class EnumMakeCommand extends GeneratorCommand
{
use ModuleCommandTrait;
protected $argumentName = 'name';
protected $name = 'module:make-enum';
protected $description = 'Create a new enum class for the specified module.';
public function getDestinationFilePath(): string
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
$filePath = GenerateConfigReader::read('enums')->getPath() ?? config('modules.paths.app_folder') . 'Enums';
return $path . $filePath . '/' . $this->getEnumName() . '.php';
}
protected function getTemplateContents(): string
{
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
return (new Stub($this->getStubName(), [
'CLASS_NAMESPACE' => $this->getClassNamespace($module),
'CLASS' => $this->getClassNameWithoutNamespace(),
]))->render();
}
protected function getArguments(): array
{
return [
['name', InputArgument::REQUIRED, 'The name of the enum class.'],
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
];
}
/**
* @return array
*/
protected function getOptions(): array
{
return [
['force', 'f', InputOption::VALUE_NONE, 'su.'],
];
}
protected function getEnumName(): array|string
{
return Str::studly($this->argument('name'));
}
private function getClassNameWithoutNamespace(): array|string
{
return class_basename($this->getEnumName());
}
public function getDefaultNamespace(): string
{
return config('modules.paths.generator.enums.namespace', 'Enums');
}
protected function getStubName(): string
{
return '/enum.stub';
}
}