This commit is contained in:
Markus
2022-04-28 09:40:10 +02:00
commit 795794f992
9586 changed files with 1146991 additions and 0 deletions

View File

@@ -0,0 +1,119 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton command file.
*/
class CommandGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:command';
/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new spark command.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:command <name> [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [
'name' => 'The command class name.',
];
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'--command' => 'The command name. Default: "command:name"',
'--type' => 'The command type. Options [basic, generator]. Default: "basic".',
'--group' => 'The command group. Default: [basic -> "CodeIgniter", generator -> "Generators"].',
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserCommand).',
'--force' => 'Force overwrite existing file.',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Command';
$this->directory = 'Commands';
$this->template = 'command.tpl.php';
$this->classNameLang = 'CLI.generator.className.command';
$this->execute($params);
}
/**
* Prepare options and do the necessary replacements.
*/
protected function prepare(string $class): string
{
$command = $this->getOption('command');
$group = $this->getOption('group');
$type = $this->getOption('type');
$command = is_string($command) ? $command : 'command:name';
$type = is_string($type) ? $type : 'basic';
if (! in_array($type, ['basic', 'generator'], true)) {
// @codeCoverageIgnoreStart
$type = CLI::prompt(lang('CLI.generator.commandType'), ['basic', 'generator'], 'required');
CLI::newLine();
// @codeCoverageIgnoreEnd
}
if (! is_string($group)) {
$group = $type === 'generator' ? 'Generators' : 'CodeIgniter';
}
return $this->parseTemplate(
$class,
['{group}', '{command}'],
[$group, $command],
['type' => $type]
);
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton config file.
*/
class ConfigGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:config';
/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new config file.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:config <name> [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [
'name' => 'The config class name.',
];
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserConfig).',
'--force' => 'Force overwrite existing file.',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Config';
$this->directory = 'Config';
$this->template = 'config.tpl.php';
$this->classNameLang = 'CLI.generator.className.config';
$this->execute($params);
}
/**
* Prepare options and do the necessary replacements.
*/
protected function prepare(string $class): string
{
$namespace = $this->getOption('namespace') ?? APP_NAMESPACE;
if ($namespace === APP_NAMESPACE) {
$class = substr($class, strlen($namespace . '\\'));
}
return $this->parseTemplate($class);
}
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton controller file.
*/
class ControllerGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:controller';
/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new controller file.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:controller <name> [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [
'name' => 'The controller class name.',
];
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'--bare' => 'Extends from CodeIgniter\Controller instead of BaseController.',
'--restful' => 'Extends from a RESTful resource, Options: [controller, presenter]. Default: "controller".',
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserController).',
'--force' => 'Force overwrite existing file.',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Controller';
$this->directory = 'Controllers';
$this->template = 'controller.tpl.php';
$this->classNameLang = 'CLI.generator.className.controller';
$this->execute($params);
}
/**
* Prepare options and do the necessary replacements.
*/
protected function prepare(string $class): string
{
$bare = $this->getOption('bare');
$rest = $this->getOption('restful');
$useStatement = trim(APP_NAMESPACE, '\\') . '\Controllers\BaseController';
$extends = 'BaseController';
// Gets the appropriate parent class to extend.
if ($bare || $rest) {
if ($bare) {
$useStatement = 'CodeIgniter\Controller';
$extends = 'Controller';
} elseif ($rest) {
$rest = is_string($rest) ? $rest : 'controller';
if (! in_array($rest, ['controller', 'presenter'], true)) {
// @codeCoverageIgnoreStart
$rest = CLI::prompt(lang('CLI.generator.parentClass'), ['controller', 'presenter'], 'required');
CLI::newLine();
// @codeCoverageIgnoreEnd
}
if ($rest === 'controller') {
$useStatement = 'CodeIgniter\RESTful\ResourceController';
$extends = 'ResourceController';
} elseif ($rest === 'presenter') {
$useStatement = 'CodeIgniter\RESTful\ResourcePresenter';
$extends = 'ResourcePresenter';
}
}
}
return $this->parseTemplate(
$class,
['{useStatement}', '{extends}'],
[$useStatement, $extends],
['type' => $rest]
);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton Entity file.
*/
class EntityGenerator extends BaseCommand
{
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
*/
protected $arguments = [
'name' => 'The entity class name.',
];
/**
* The Command's Options
*
* @var array
*/
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->execute($params);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton Filter file.
*/
class FilterGenerator extends BaseCommand
{
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
*/
protected $arguments = [
'name' => 'The filter class name.',
];
/**
* The Command's Options
*
* @var array
*/
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->execute($params);
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
/**
* Deprecated class for the migration creation command.
*
* @deprecated Use make:migration instead.
*
* @codeCoverageIgnore
*/
class MigrateCreate extends BaseCommand
{
/**
* The group the command is lumped under
* when listing commands.
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's name
*
* @var string
*/
protected $name = 'migrate:create';
/**
* The Command's short description
*
* @var string
*/
protected $description = '[DEPRECATED] Creates a new migration file. Please use "make:migration" instead.';
/**
* The Command's usage
*
* @var string
*/
protected $usage = 'migrate:create <name> [options]';
/**
* The Command's arguments.
*
* @var array
*/
protected $arguments = [
'name' => 'The migration file name.',
];
/**
* The Command's options.
*
* @var array
*/
protected $options = [
'--namespace' => 'Set root namespace. Defaults to APP_NAMESPACE',
'--force' => 'Force overwrite existing files.',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
// Resolve arguments before passing to make:migration
$params[0] = $params[0] ?? CLI::getSegment(2);
$params['namespace'] = $params['namespace'] ?? CLI::getOption('namespace') ?? APP_NAMESPACE;
if (array_key_exists('force', $params) || CLI::getOption('force')) {
$params['force'] = null;
}
$this->call('make:migration', $params);
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton migration file.
*/
class MigrationGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:migration';
/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new migration file.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:migration <name> [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [
'name' => 'The migration class name.',
];
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'--session' => 'Generates the migration file for database sessions.',
'--table' => 'Table name to use for database sessions. Default: "ci_sessions".',
'--dbgroup' => 'Database group to use for database sessions. Default: "default".',
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserMigration).',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Migration';
$this->directory = 'Database\Migrations';
$this->template = 'migration.tpl.php';
if (array_key_exists('session', $params) || CLI::getOption('session')) {
$table = $params['table'] ?? CLI::getOption('table') ?? 'ci_sessions';
$params[0] = "_create_{$table}_table";
}
$this->classNameLang = 'CLI.generator.className.migration';
$this->execute($params);
}
/**
* Prepare options and do the necessary replacements.
*/
protected function prepare(string $class): string
{
$data['session'] = false;
if ($this->getOption('session')) {
$table = $this->getOption('table');
$DBGroup = $this->getOption('dbgroup');
$data['session'] = true;
$data['table'] = is_string($table) ? $table : 'ci_sessions';
$data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default';
$data['DBDriver'] = config('Database')->{$data['DBGroup']}['DBDriver'];
$data['matchIP'] = config('App')->sessionMatchIP;
}
return $this->parseTemplate($class, [], [], $data);
}
/**
* Change file basename before saving.
*/
protected function basename(string $filename): string
{
return gmdate(config('Migrations')->timestampFormat) . basename($filename);
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton Model file.
*/
class ModelGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:model';
/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new model file.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:model <name> [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [
'name' => 'The model class name.',
];
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'--table' => 'Supply a table name. Default: "the lowercased plural of the class name".',
'--dbgroup' => 'Database group to use. Default: "default".',
'--return' => 'Return type, Options: [array, object, entity]. Default: "array".',
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserModel).',
'--force' => 'Force overwrite existing file.',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Model';
$this->directory = 'Models';
$this->template = 'model.tpl.php';
$this->classNameLang = 'CLI.generator.className.model';
$this->execute($params);
}
/**
* Prepare options and do the necessary replacements.
*/
protected function prepare(string $class): string
{
$table = $this->getOption('table');
$dbGroup = $this->getOption('dbgroup');
$return = $this->getOption('return');
$baseClass = class_basename($class);
if (preg_match('/^(\S+)Model$/i', $baseClass, $match) === 1) {
$baseClass = $match[1];
}
$table = is_string($table) ? $table : plural(strtolower($baseClass));
$dbGroup = is_string($dbGroup) ? $dbGroup : 'default';
$return = is_string($return) ? $return : 'array';
if (! in_array($return, ['array', 'object', 'entity'], true)) {
// @codeCoverageIgnoreStart
$return = CLI::prompt(lang('CLI.generator.returnType'), ['array', 'object', 'entity'], 'required');
CLI::newLine();
// @codeCoverageIgnoreEnd
}
if ($return === 'entity') {
$return = str_replace('Models', 'Entities', $class);
if (preg_match('/^(\S+)Model$/i', $return, $match) === 1) {
$return = $match[1];
if ($this->getOption('suffix')) {
$return .= 'Entity';
}
}
$return = '\\' . trim($return, '\\') . '::class';
$this->call('make:entity', array_merge([$baseClass], $this->params));
} else {
$return = "'{$return}'";
}
return $this->parseTemplate($class, ['{table}', '{dbGroup}', '{return}'], [$table, $dbGroup, $return]);
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a complete set of scaffold files.
*/
class ScaffoldGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:scaffold';
/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a complete set of scaffold files.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:scaffold <name> [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [
'name' => 'The class name',
];
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'--bare' => 'Add the "--bare" option to controller component.',
'--restful' => 'Add the "--restful" option to controller component.',
'--table' => 'Add the "--table" option to the model component.',
'--dbgroup' => 'Add the "--dbgroup" option to model component.',
'--return' => 'Add the "--return" option to the model component.',
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name.',
'--force' => 'Force overwrite existing file.',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->params = $params;
$options = [];
if ($this->getOption('namespace')) {
$options['namespace'] = $this->getOption('namespace');
}
if ($this->getOption('suffix')) {
$options['suffix'] = null;
}
if ($this->getOption('force')) {
$options['force'] = null;
}
$controllerOpts = [];
if ($this->getOption('bare')) {
$controllerOpts['bare'] = null;
} elseif ($this->getOption('restful')) {
$controllerOpts['restful'] = $this->getOption('restful');
}
$modelOpts = [
'table' => $this->getOption('table'),
'dbgroup' => $this->getOption('dbgroup'),
'return' => $this->getOption('return'),
];
$class = $params[0] ?? CLI::getSegment(2);
// Call those commands!
$this->call('make:controller', array_merge([$class], $controllerOpts, $options));
$this->call('make:model', array_merge([$class], $modelOpts, $options));
$this->call('make:migration', array_merge([$class], $options));
$this->call('make:seeder', array_merge([$class], $options));
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton seeder file.
*/
class SeederGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:seeder';
/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new seeder file.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:seeder <name> [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [
'name' => 'The seeder class name.',
];
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserSeeder).',
'--force' => 'Force overwrite existing file.',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Seeder';
$this->directory = 'Database\Seeds';
$this->template = 'seeder.tpl.php';
$this->classNameLang = 'CLI.generator.className.seeder';
$this->execute($params);
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a migration file for database sessions.
*
* @deprecated Use `make:migration --session` instead.
*
* @codeCoverageIgnore
*/
class SessionMigrationGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'session:migration';
/**
* The Command's Description
*
* @var string
*/
protected $description = '[DEPRECATED] Generates the migration file for database sessions, Please use "make:migration --session" instead.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'session:migration [options]';
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'-t' => 'Supply a table name.',
'-g' => 'Database group to use. Default: "default".',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Migration';
$this->directory = 'Database\Migrations';
$this->template = 'migration.tpl.php';
$table = 'ci_sessions';
if (array_key_exists('t', $params) || CLI::getOption('t')) {
$table = $params['t'] ?? CLI::getOption('t');
}
$params[0] = "_create_{$table}_table";
$this->execute($params);
}
/**
* Performs the necessary replacements.
*/
protected function prepare(string $class): string
{
$data['session'] = true;
$data['table'] = $this->getOption('t');
$data['DBGroup'] = $this->getOption('g');
$data['matchIP'] = config('App')->sessionMatchIP ?? false;
$data['table'] = is_string($data['table']) ? $data['table'] : 'ci_sessions';
$data['DBGroup'] = is_string($data['DBGroup']) ? $data['DBGroup'] : 'default';
return $this->parseTemplate($class, [], [], $data);
}
/**
* Change file basename before saving.
*/
protected function basename(string $filename): string
{
return gmdate(config('Migrations')->timestampFormat) . basename($filename);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;
/**
* Generates a skeleton Validation file.
*/
class ValidationGenerator extends BaseCommand
{
use GeneratorTrait;
/**
* The Command's Group
*
* @var string
*/
protected $group = 'Generators';
/**
* The Command's Name
*
* @var string
*/
protected $name = 'make:validation';
/**
* The Command's Description
*
* @var string
*/
protected $description = 'Generates a new validation file.';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = 'make:validation <name> [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [
'name' => 'The validation class name.',
];
/**
* The Command's Options
*
* @var array
*/
protected $options = [
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
'--suffix' => 'Append the component title to the class name (e.g. User => UserValidation).',
'--force' => 'Force overwrite existing file.',
];
/**
* Actually execute a command.
*/
public function run(array $params)
{
$this->component = 'Validation';
$this->directory = 'Validation';
$this->template = 'validation.tpl.php';
$this->classNameLang = 'CLI.generator.className.validation';
$this->execute($params);
}
}

View File

@@ -0,0 +1,76 @@
<@php
namespace {namespace};
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
<?php if ($type === 'generator'): ?>
use CodeIgniter\CLI\GeneratorTrait;
<?php endif ?>
class {class} extends BaseCommand
{
<?php if ($type === 'generator'): ?>
use GeneratorTrait;
<?php endif ?>
/**
* The Command's Group
*
* @var string
*/
protected $group = '{group}';
/**
* The Command's Name
*
* @var string
*/
protected $name = '{command}';
/**
* The Command's Description
*
* @var string
*/
protected $description = '';
/**
* The Command's Usage
*
* @var string
*/
protected $usage = '{command} [arguments] [options]';
/**
* The Command's Arguments
*
* @var array
*/
protected $arguments = [];
/**
* The Command's Options
*
* @var array
*/
protected $options = [];
/**
* Actually execute a command.
*
* @param array $params
*/
public function run(array $params)
{
<?php if ($type === 'generator'): ?>
$this->component = 'Command';
$this->directory = 'Commands';
$this->template = 'command.tpl.php';
$this->execute($params);
<?php else: ?>
//
<?php endif ?>
}
}

View File

@@ -0,0 +1,10 @@
<@php
namespace {namespace};
use CodeIgniter\Config\BaseConfig;
class {class} extends BaseConfig
{
//
}

View File

@@ -0,0 +1,177 @@
<@php
namespace {namespace};
use {useStatement};
class {class} extends {extends}
{
<?php if ($type === 'controller'): ?>
/**
* Return an array of resource objects, themselves in array format
*
* @return mixed
*/
public function index()
{
//
}
/**
* Return the properties of a resource object
*
* @return mixed
*/
public function show($id = null)
{
//
}
/**
* Return a new resource object, with default properties
*
* @return mixed
*/
public function new()
{
//
}
/**
* Create a new resource object, from "posted" parameters
*
* @return mixed
*/
public function create()
{
//
}
/**
* Return the editable properties of a resource object
*
* @return mixed
*/
public function edit($id = null)
{
//
}
/**
* Add or update a model resource, from "posted" properties
*
* @return mixed
*/
public function update($id = null)
{
//
}
/**
* Delete the designated resource object from the model
*
* @return mixed
*/
public function delete($id = null)
{
//
}
<?php elseif ($type === 'presenter'): ?>
/**
* Present a view of resource objects
*
* @return mixed
*/
public function index()
{
//
}
/**
* Present a view to present a specific resource object
*
* @param mixed $id
*
* @return mixed
*/
public function show($id = null)
{
//
}
/**
* Present a view to present a new single resource object
*
* @return mixed
*/
public function new()
{
//
}
/**
* Process the creation/insertion of a new resource object.
* This should be a POST.
*
* @return mixed
*/
public function create()
{
//
}
/**
* Present a view to edit the properties of a specific resource object
*
* @param mixed $id
*
* @return mixed
*/
public function edit($id = null)
{
//
}
/**
* Process the updating, full or partial, of a specific resource object.
* This should be a POST.
*
* @param mixed $id
*
* @return mixed
*/
public function update($id = null)
{
//
}
/**
* Present a view to confirm the deletion of a specific resource object
*
* @param mixed $id
*
* @return mixed
*/
public function remove($id = null)
{
//
}
/**
* Process the deletion of a specific resource object
*
* @param mixed $id
*
* @return mixed
*/
public function delete($id = null)
{
//
}
<?php else: ?>
public function index()
{
//
}
<?php endif ?>
}

View File

@@ -0,0 +1,12 @@
<@php
namespace {namespace};
use CodeIgniter\Entity\Entity;
class {class} extends Entity
{
protected $datamap = [];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $casts = [];
}

View File

@@ -0,0 +1,47 @@
<@php
namespace {namespace};
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
class {class} implements FilterInterface
{
/**
* Do whatever processing this filter needs to do.
* By default it should not return anything during
* normal execution. However, when an abnormal state
* is found, it should return an instance of
* CodeIgniter\HTTP\Response. If it does, script
* execution will end and that Response will be
* sent back to the client, allowing for error pages,
* redirects, etc.
*
* @param RequestInterface $request
* @param array|null $arguments
*
* @return mixed
*/
public function before(RequestInterface $request, $arguments = null)
{
//
}
/**
* Allows After filters to inspect and modify the response
* object as needed. This method does not allow any way
* to stop execution of other after filters, short of
* throwing an Exception or Error.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @param array|null $arguments
*
* @return mixed
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
//
}
}

View File

@@ -0,0 +1,50 @@
<@php
namespace {namespace};
use CodeIgniter\Database\Migration;
class {class} extends Migration
{
<?php if ($session): ?>
protected $DBGroup = '<?= $DBGroup ?>';
public function up()
{
$this->forge->addField([
'id' => ['type' => 'VARCHAR', 'constraint' => 128, 'null' => false],
<?php if ($DBDriver === 'MySQLi'): ?>
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => false],
'timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL',
'data' => ['type' => 'BLOB', 'null' => false],
<?php elseif ($DBDriver === 'Postgre'): ?>
'ip_address inet NOT NULL',
'timestamp timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL',
"data bytea DEFAULT '' NOT NULL",
<?php endif; ?>
]);
<?php if ($matchIP) : ?>
$this->forge->addKey(['id', 'ip_address'], true);
<?php else: ?>
$this->forge->addKey('id', true);
<?php endif ?>
$this->forge->addKey('timestamp');
$this->forge->createTable('<?= $table ?>', true);
}
public function down()
{
$this->forge->dropTable('<?= $table ?>', true);
}
<?php else: ?>
public function up()
{
//
}
public function down()
{
//
}
<?php endif ?>
}

View File

@@ -0,0 +1,42 @@
<@php
namespace {namespace};
use CodeIgniter\Model;
class {class} extends Model
{
protected $DBGroup = '{dbGroup}';
protected $table = '{table}';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $insertID = 0;
protected $returnType = {return};
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
}

View File

@@ -0,0 +1,13 @@
<@php
namespace {namespace};
use CodeIgniter\Database\Seeder;
class {class} extends Seeder
{
public function run()
{
//
}
}

View File

@@ -0,0 +1,11 @@
<@php
namespace {namespace};
class {class}
{
// public function custom_rule(): bool
// {
// return true;
// }
}