Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions app/Config/Generators.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ class Generators extends BaseConfig
'class' => 'CodeIgniter\Commands\Generators\Views\cell.tpl.php',
'view' => 'CodeIgniter\Commands\Generators\Views\cell_view.tpl.php',
],
'make:command' => 'CodeIgniter\Commands\Generators\Views\command.tpl.php',
'make:config' => 'CodeIgniter\Commands\Generators\Views\config.tpl.php',
'make:controller' => 'CodeIgniter\Commands\Generators\Views\controller.tpl.php',
'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php',
'make:filter' => 'CodeIgniter\Commands\Generators\Views\filter.tpl.php',
'make:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
'make:model' => 'CodeIgniter\Commands\Generators\Views\model.tpl.php',
'make:seeder' => 'CodeIgniter\Commands\Generators\Views\seeder.tpl.php',
'make:validation' => 'CodeIgniter\Commands\Generators\Views\validation.tpl.php',
'make:command' => 'CodeIgniter\Commands\Generators\Views\command.tpl.php',
'make:config' => 'CodeIgniter\Commands\Generators\Views\config.tpl.php',
'make:controller' => 'CodeIgniter\Commands\Generators\Views\controller.tpl.php',
'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php',
'make:filter' => 'CodeIgniter\Commands\Generators\Views\filter.tpl.php',
'make:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
'make:model' => 'CodeIgniter\Commands\Generators\Views\model.tpl.php',
'make:request' => 'CodeIgniter\Commands\Generators\Views\formrequest.tpl.php',
'make:seeder' => 'CodeIgniter\Commands\Generators\Views\seeder.tpl.php',
'make:test' => 'CodeIgniter\Commands\Generators\Views\test.tpl.php',
'make:transformer' => 'CodeIgniter\Commands\Generators\Views\transformer.tpl.php',
'make:validation' => 'CodeIgniter\Commands\Generators\Views\validation.tpl.php',
];
}
2 changes: 1 addition & 1 deletion system/CLI/AbstractGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function configure(): void
{
$this->addArgument(new Argument(
name: 'name',
description: 'The name of the class to generate.',
description: sprintf('The %s class name.', lcfirst($this->component)),
required: true,
));
}
Expand Down
20 changes: 19 additions & 1 deletion system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ abstract public function run(array $params);
/**
* Can be used by a command to run other commands.
*
* For a modern command, integer-keyed params are passed as arguments and string-keyed params as options.
*
* @param array<array-key, string|null> $params
*
* @return int|null
Expand All @@ -116,7 +118,23 @@ abstract public function run(array $params);
*/
protected function call(string $command, array $params = [])
{
return $this->commands->runLegacy($command, $params);
if ($this->commands->hasLegacyCommand($command) || ! $this->commands->hasModernCommand($command)) {
return $this->commands->runLegacy($command, $params);
}

$arguments = [];
$options = [];

foreach ($params as $key => $value) {
if (is_int($key)) {
assert(is_string($value));
$arguments[] = $value;
} else {
$options[$key] = $value;
}
}

return $this->commands->runCommand($command, $arguments, $options);
}

/**
Expand Down
83 changes: 12 additions & 71 deletions system/Commands/Generators/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,17 @@

namespace CodeIgniter\Commands\Generators;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;

/**
* Generates a skeleton Entity file.
*/
class EntityGenerator extends BaseCommand
use CodeIgniter\CLI\AbstractGeneratorCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Attributes\GeneratorCommand;

#[Command(name: 'make:entity', description: 'Generates a new entity file.', group: 'Generators')]
#[GeneratorCommand(
component: 'Entity',
template: 'entity.tpl.php',
directory: 'Entities',
classNameLang: 'CLI.generator.className.entity',
)]
class EntityGenerator extends AbstractGeneratorCommand
{
use GeneratorTrait;

/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';

/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:entity';

/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new entity file.';

/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:entity <name> [options]';

/**
* The Command's Arguments
*
* @var array<string, string>
*/
protected $arguments = [
'name' => 'The entity class name.',
];

/**
* The Command's Options
*
* @var array<string, string>
*/
protected $options = [
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserEntity).',
'--force' => 'Force overwrite existing file.',
];

/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Entity';
$this->directory = 'Entities';
$this->template = 'entity.tpl.php';

$this->classNameLang = 'CLI.generator.className.entity';
$this->generateClass($params);

return EXIT_SUCCESS;
}
}
83 changes: 12 additions & 71 deletions system/Commands/Generators/FilterGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,17 @@

namespace CodeIgniter\Commands\Generators;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;

/**
* Generates a skeleton Filter file.
*/
class FilterGenerator extends BaseCommand
use CodeIgniter\CLI\AbstractGeneratorCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Attributes\GeneratorCommand;

#[Command(name: 'make:filter', description: 'Generates a new filter file.', group: 'Generators')]
#[GeneratorCommand(
component: 'Filter',
template: 'filter.tpl.php',
directory: 'Filters',
classNameLang: 'CLI.generator.className.filter',
)]
class FilterGenerator extends AbstractGeneratorCommand
{
use GeneratorTrait;

/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';

/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:filter';

/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new filter file.';

/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:filter <name> [options]';

/**
* The Command's Arguments
*
* @var array<string, string>
*/
protected $arguments = [
'name' => 'The filter class name.',
];

/**
* The Command's Options
*
* @var array<string, string>
*/
protected $options = [
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserFilter).',
'--force' => 'Force overwrite existing file.',
];

/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Filter';
$this->directory = 'Filters';
$this->template = 'filter.tpl.php';

$this->classNameLang = 'CLI.generator.className.filter';
$this->generateClass($params);

return EXIT_SUCCESS;
}
}
83 changes: 12 additions & 71 deletions system/Commands/Generators/FormRequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,17 @@

namespace CodeIgniter\Commands\Generators;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;

/**
* Generates a skeleton FormRequest file.
*/
class FormRequestGenerator extends BaseCommand
use CodeIgniter\CLI\AbstractGeneratorCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Attributes\GeneratorCommand;

#[Command(name: 'make:request', description: 'Generates a new FormRequest file.', group: 'Generators')]
#[GeneratorCommand(
component: 'Request',
template: 'formrequest.tpl.php',
directory: 'Requests',
classNameLang: 'CLI.generator.className.request',
)]
class FormRequestGenerator extends AbstractGeneratorCommand
{
use GeneratorTrait;

/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';

/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:request';

/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new FormRequest file.';

/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:request <name> [options]';

/**
* The Command's Arguments
*
* @var array<string, string>
*/
protected $arguments = [
'name' => 'The FormRequest class name.',
];

/**
* The Command's Options
*
* @var array<string, string>
*/
protected $options = [
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserRequest).',
'--force' => 'Force overwrite existing file.',
];

/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Request';
$this->directory = 'Requests';
$this->template = 'formrequest.tpl.php';

$this->classNameLang = 'CLI.generator.className.request';
$this->generateClass($params);

return EXIT_SUCCESS;
}
}
4 changes: 3 additions & 1 deletion system/Commands/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ protected function prepare(string $class): string

// Call the entity generator with the fully-qualified class name so
// it ends up under the correct sub-namespace/folder (eg. Admin).
$this->call('make:entity', array_merge([trim($entityClass, '\\')], $this->params));
$entityOptions = array_intersect_key($this->params, array_flip(['namespace', 'suffix', 'force']));

$this->call('make:entity', array_merge([trim($entityClass, '\\')], $entityOptions));

$return = '\\' . trim($entityClass, '\\') . '::class';
} else {
Expand Down
Loading
Loading