76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace mpba\Modules\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use mpba\Modules\Contracts\ActivatorInterface;
|
|
use mpba\Modules\Generators\ModuleGenerator;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
class ModuleMakeCommand extends Command
|
|
{
|
|
/**
|
|
* The console command name.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $name = 'module:make';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Create a new module.';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): int
|
|
{
|
|
$names = $this->argument('name');
|
|
$success = true;
|
|
|
|
foreach ($names as $name) {
|
|
$code = with(new ModuleGenerator($name))
|
|
->setFilesystem($this->laravel['files'])
|
|
->setModule($this->laravel['modules'])
|
|
->setConfig($this->laravel['config'])
|
|
->setActivator($this->laravel[ActivatorInterface::class])
|
|
->setConsole($this)
|
|
->setForce($this->option('force'))
|
|
->setPlain($this->option('plain'))
|
|
->setActive(! $this->option('disabled'))
|
|
->generate();
|
|
|
|
if ($code === E_ERROR) {
|
|
$success = false;
|
|
}
|
|
}
|
|
|
|
return $success ? 0 : E_ERROR;
|
|
}
|
|
|
|
/**
|
|
* Get the console command arguments.
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getArguments()
|
|
{
|
|
return [
|
|
['name', InputArgument::IS_ARRAY, 'The names of modules will be created.'],
|
|
];
|
|
}
|
|
|
|
protected function getOptions()
|
|
{
|
|
return [
|
|
['plain', 'p', InputOption::VALUE_NONE, 'Generate a plain module (without some resources).'],
|
|
['disabled', 'd', InputOption::VALUE_NONE, 'Do not enable the module at creation.'],
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when the module already exists.'],
|
|
];
|
|
}
|
|
}
|