¨4.0.1¨
This commit is contained in:
@@ -25,14 +25,15 @@ class ScaffoldEntityCommand extends Command
|
||||
/**
|
||||
* The instance of EntityGenerator.
|
||||
*
|
||||
* @var \FleetCart\Scaffold\Module\Generators\EntityGenerator
|
||||
* @var EntityGenerator
|
||||
*/
|
||||
private $entityGenerator;
|
||||
private EntityGenerator $entityGenerator;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @param \FleetCart\Scaffold\Module\Generators\EntityGenerator $entityGenerator
|
||||
* @param EntityGenerator $entityGenerator
|
||||
*/
|
||||
public function __construct(EntityGenerator $entityGenerator)
|
||||
{
|
||||
@@ -41,12 +42,13 @@ class ScaffoldEntityCommand extends Command
|
||||
$this->entityGenerator = $entityGenerator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
$this->entityGenerator
|
||||
->module($this->argument('module'))
|
||||
@@ -55,12 +57,13 @@ class ScaffoldEntityCommand extends Command
|
||||
$this->info('Entity generated.');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
protected function getArguments(): array
|
||||
{
|
||||
return [
|
||||
['entity', InputArgument::REQUIRED, 'The name of the entity.'],
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace FleetCart\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use FleetCart\Scaffold\Module\ModuleScaffold;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
|
||||
class ScaffoldModuleCommand extends Command
|
||||
{
|
||||
@@ -24,14 +25,15 @@ class ScaffoldModuleCommand extends Command
|
||||
/**
|
||||
* The instance of ModuleScaffold.
|
||||
*
|
||||
* @var \FleetCart\Scaffold\Module\ModuleScaffold
|
||||
* @var ModuleScaffold
|
||||
*/
|
||||
private $scaffolder;
|
||||
private ModuleScaffold $scaffolder;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @param \FleetCart\Scaffold\Module\ModuleScaffold $scaffolder
|
||||
* @param ModuleScaffold $scaffolder
|
||||
*/
|
||||
public function __construct(ModuleScaffold $scaffolder)
|
||||
{
|
||||
@@ -40,12 +42,14 @@ class ScaffoldModuleCommand extends Command
|
||||
$this->scaffolder = $scaffolder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
$module = $this->askModuleName();
|
||||
$entities = $this->askEntities();
|
||||
@@ -55,49 +59,68 @@ class ScaffoldModuleCommand extends Command
|
||||
$this->info('Module has been generated.');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ask for module name.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function askModuleName()
|
||||
private function askModuleName(): array
|
||||
{
|
||||
do {
|
||||
$moduleName = $this->ask('Please enter the module name in the following format: vendor/name');
|
||||
do {
|
||||
$moduleName = $this->ask('Please enter the module name in the following format: vendor/name');
|
||||
} while (!$this->moduleNameIsValid($moduleName));
|
||||
|
||||
list($vendor, $name) = $this->extractModuleName($moduleName);
|
||||
[$vendor, $name] = $this->extractModuleName($moduleName);
|
||||
} while ($this->moduleExists($name));
|
||||
|
||||
return compact('vendor', 'name');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate the given module name.
|
||||
*
|
||||
* @param string $moduleName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function moduleNameIsValid(string $moduleName): bool
|
||||
{
|
||||
$name = explode('/', $moduleName);
|
||||
|
||||
if (count($name) !== 2) {
|
||||
$this->error('Module name must be in the following format: vendor/name');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the given module name.
|
||||
*
|
||||
* @param string $moduleName
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function extractModuleName($moduleName)
|
||||
private function extractModuleName(string $moduleName): array
|
||||
{
|
||||
do {
|
||||
$name = explode('/', $moduleName);
|
||||
|
||||
if (count($name) !== 2) {
|
||||
$this->error('Module name must be in the following format: vendor/name');
|
||||
|
||||
$moduleName = $this->ask('Please enter the module name in the following format: vendor/name');
|
||||
}
|
||||
} while (count($name) !== 2);
|
||||
$name = explode('/', $moduleName);
|
||||
|
||||
return [$name[0], ucfirst(camel_case($name[1]))];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the given module is exists.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
private function moduleExists($name)
|
||||
private function moduleExists($name): bool
|
||||
{
|
||||
if (is_dir(config('modules.paths.modules') . "/{$name}")) {
|
||||
$this->error("The module [$name] is already exists.");
|
||||
@@ -108,17 +131,18 @@ class ScaffoldModuleCommand extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ask for entities.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function askEntities()
|
||||
private function askEntities(): array
|
||||
{
|
||||
$entities = [];
|
||||
|
||||
do {
|
||||
$entity = $this->ask('Enter entity name. Leaving option empty will continue script', false);
|
||||
$entity = $this->ask('Enter entity name. To Continue Press Enter .', false);
|
||||
|
||||
if ($entity !== '') {
|
||||
$entities[] = ucfirst($entity);
|
||||
|
||||
@@ -17,13 +17,15 @@ class Kernel extends ConsoleKernel
|
||||
Commands\ScaffoldEntityCommand::class,
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @param Schedule $schedule
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
|
||||
Reference in New Issue
Block a user