first commit
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
use Config\Generators;
|
||||
|
||||
/**
|
||||
* Generates a skeleton Cell and its view.
|
||||
*/
|
||||
class CellGenerator extends BaseCommand
|
||||
{
|
||||
use GeneratorTrait;
|
||||
|
||||
/**
|
||||
* The Command's Group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Generators';
|
||||
|
||||
/**
|
||||
* The Command's Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'make:cell';
|
||||
|
||||
/**
|
||||
* The Command's Description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generates a new Controlled Cell file and its view.';
|
||||
|
||||
/**
|
||||
* The Command's Usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'make:cell <name> [options]';
|
||||
|
||||
/**
|
||||
* The Command's Arguments
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The Controlled Cell class name.',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Command's Options
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $options = [
|
||||
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
|
||||
'--force' => 'Force overwrite existing file.',
|
||||
];
|
||||
|
||||
/**
|
||||
* Actually execute a command.
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$this->component = 'Cell';
|
||||
$this->directory = 'Cells';
|
||||
|
||||
$params = array_merge($params, ['suffix' => null]);
|
||||
|
||||
$this->templatePath = config(Generators::class)->views[$this->name]['class'];
|
||||
$this->template = 'cell.tpl.php';
|
||||
$this->classNameLang = 'CLI.generator.className.cell';
|
||||
|
||||
$this->generateClass($params);
|
||||
|
||||
$this->templatePath = config(Generators::class)->views[$this->name]['view'];
|
||||
$this->template = 'cell_view.tpl.php';
|
||||
$this->classNameLang = 'CLI.generator.viewName.cell';
|
||||
|
||||
$className = $this->qualifyClassName();
|
||||
$viewName = decamelize(class_basename($className));
|
||||
$viewName = preg_replace(
|
||||
'/([a-z][a-z0-9_\/\\\\]+)(_cell)$/i',
|
||||
'$1',
|
||||
$viewName
|
||||
) ?? $viewName;
|
||||
$namespace = substr($className, 0, strrpos($className, '\\') + 1);
|
||||
|
||||
$this->generateView($namespace . $viewName, $params);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The command class name.',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Command's Options
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $options = [
|
||||
'--command' => 'The command name. Default: "command:name"',
|
||||
'--type' => 'The command type. Options [basic, generator]. Default: "basic".',
|
||||
'--group' => 'The command group. Default: [basic -> "App", 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->generateClass($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' : 'App';
|
||||
}
|
||||
|
||||
return $this->parseTemplate(
|
||||
$class,
|
||||
['{group}', '{command}'],
|
||||
[$group, $command],
|
||||
['type' => $type]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The config 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 => 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->generateClass($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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use CodeIgniter\RESTful\ResourcePresenter;
|
||||
|
||||
/**
|
||||
* 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<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The controller class name.',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Command's Options
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
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->generateClass($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 = Controller::class;
|
||||
$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 = ResourceController::class;
|
||||
$extends = 'ResourceController';
|
||||
} elseif ($rest === 'presenter') {
|
||||
$useStatement = ResourcePresenter::class;
|
||||
$extends = 'ResourcePresenter';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->parseTemplate(
|
||||
$class,
|
||||
['{useStatement}', '{extends}'],
|
||||
[$useStatement, $extends],
|
||||
['type' => $rest]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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<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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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<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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
use Config\Database;
|
||||
use Config\Migrations;
|
||||
use Config\Session as SessionConfig;
|
||||
|
||||
/**
|
||||
* 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<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The migration class name.',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Command's Options
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
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->generateClass($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare options and do the necessary replacements.
|
||||
*/
|
||||
protected function prepare(string $class): string
|
||||
{
|
||||
$data = [];
|
||||
$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::class)->{$data['DBGroup']}['DBDriver'];
|
||||
|
||||
/** @var SessionConfig|null $session */
|
||||
$session = config(SessionConfig::class);
|
||||
|
||||
$data['matchIP'] = $session->matchIP;
|
||||
}
|
||||
|
||||
return $this->parseTemplate($class, [], [], $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change file basename before saving.
|
||||
*/
|
||||
protected function basename(string $filename): string
|
||||
{
|
||||
return gmdate(config(Migrations::class)->timestampFormat) . basename($filename);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The model class name.',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Command's Options
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
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->generateClass($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));
|
||||
$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, ['{dbGroup}', '{table}', '{return}'], [$dbGroup, $table, $return], compact('dbGroup'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The class name',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Command's Options
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The seeder 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 => 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->generateClass($params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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 TestGenerator extends BaseCommand
|
||||
{
|
||||
use GeneratorTrait;
|
||||
|
||||
/**
|
||||
* The Command's Group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Generators';
|
||||
|
||||
/**
|
||||
* The Command's Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'make:test';
|
||||
|
||||
/**
|
||||
* The Command's Description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generates a new test file.';
|
||||
|
||||
/**
|
||||
* The Command's Usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'make:test <name> [options]';
|
||||
|
||||
/**
|
||||
* The Command's Arguments
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The test class name.',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Command's Options
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $options = [
|
||||
'--namespace' => 'Set root namespace. Default: "Tests".',
|
||||
'--force' => 'Force overwrite existing file.',
|
||||
];
|
||||
|
||||
/**
|
||||
* Actually execute a command.
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$this->component = 'Test';
|
||||
$this->template = 'test.tpl.php';
|
||||
|
||||
$this->classNameLang = 'CLI.generator.className.test';
|
||||
|
||||
$autoload = service('autoloader');
|
||||
$autoload->addNamespace('CodeIgniter', TESTPATH . 'system');
|
||||
$autoload->addNamespace('Tests', ROOTPATH . 'tests');
|
||||
|
||||
$this->generateClass($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace from input or the default namespace.
|
||||
*/
|
||||
protected function getNamespace(): string
|
||||
{
|
||||
if ($this->namespace !== null) {
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
if ($this->getOption('namespace') !== null) {
|
||||
return trim(
|
||||
str_replace(
|
||||
'/',
|
||||
'\\',
|
||||
$this->getOption('namespace')
|
||||
),
|
||||
'\\'
|
||||
);
|
||||
}
|
||||
|
||||
$class = $this->normalizeInputClassName();
|
||||
$classPaths = explode('\\', $class);
|
||||
|
||||
$namespaces = service('autoloader')->getNamespace();
|
||||
|
||||
while ($classPaths !== []) {
|
||||
array_pop($classPaths);
|
||||
$namespace = implode('\\', $classPaths);
|
||||
|
||||
foreach (array_keys($namespaces) as $prefix) {
|
||||
if ($prefix === $namespace) {
|
||||
// The input classname is FQCN, and use the namespace.
|
||||
return $namespace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 'Tests';
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the test file path from the class name.
|
||||
*
|
||||
* @param string $class namespaced classname.
|
||||
*/
|
||||
protected function buildPath(string $class): string
|
||||
{
|
||||
$namespace = $this->getNamespace();
|
||||
|
||||
$base = $this->searchTestFilePath($namespace);
|
||||
|
||||
if ($base === null) {
|
||||
CLI::error(
|
||||
lang('CLI.namespaceNotDefined', [$namespace]),
|
||||
'light_gray',
|
||||
'red'
|
||||
);
|
||||
CLI::newLine();
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$realpath = realpath($base);
|
||||
$base = ($realpath !== false) ? $realpath : $base;
|
||||
|
||||
$file = $base . DIRECTORY_SEPARATOR
|
||||
. str_replace(
|
||||
'\\',
|
||||
DIRECTORY_SEPARATOR,
|
||||
trim(str_replace($namespace . '\\', '', $class), '\\')
|
||||
) . '.php';
|
||||
|
||||
return implode(
|
||||
DIRECTORY_SEPARATOR,
|
||||
array_slice(
|
||||
explode(DIRECTORY_SEPARATOR, $file),
|
||||
0,
|
||||
-1
|
||||
)
|
||||
) . DIRECTORY_SEPARATOR . $this->basename($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns test file path for the namespace.
|
||||
*/
|
||||
private function searchTestFilePath(string $namespace): ?string
|
||||
{
|
||||
$bases = service('autoloader')->getNamespace($namespace);
|
||||
|
||||
$base = null;
|
||||
|
||||
foreach ($bases as $candidate) {
|
||||
if (str_contains($candidate, '/tests/')) {
|
||||
$base = $candidate;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $base;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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<string, string>
|
||||
*/
|
||||
protected $arguments = [
|
||||
'name' => 'The validation 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 => 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->generateClass($params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<@php
|
||||
|
||||
namespace {namespace};
|
||||
|
||||
use CodeIgniter\View\Cells\Cell;
|
||||
|
||||
class {class} extends Cell
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
<!-- Your HTML here -->
|
||||
</div>
|
||||
@@ -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 ?>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<@php
|
||||
|
||||
namespace {namespace};
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class {class} extends BaseConfig
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<@php
|
||||
|
||||
namespace {namespace};
|
||||
|
||||
use {useStatement};
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class {class} extends {extends}
|
||||
{
|
||||
<?php if ($type === 'controller'): ?>
|
||||
/**
|
||||
* Return an array of resource objects, themselves in array format.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the properties of a resource object.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function show($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new resource object, with default properties.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function new()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new resource object, from "posted" parameters.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the editable properties of a resource object.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or update a model resource, from "posted" properties.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the designated resource object from the model.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
<?php elseif ($type === 'presenter'): ?>
|
||||
/**
|
||||
* Present a view of resource objects.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Present a view to present a specific resource object.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function show($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Present a view to present a new single resource object.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function new()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the creation/insertion of a new resource object.
|
||||
* This should be a POST.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Present a view to edit the properties of a specific resource object.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the updating, full or partial, of a specific resource object.
|
||||
* This should be a POST.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Present a view to confirm the deletion of a specific resource object.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function remove($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the deletion of a specific resource object.
|
||||
*
|
||||
* @param int|string|null $id
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
<?php else: ?>
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
<?php endif ?>
|
||||
}
|
||||
@@ -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 = [];
|
||||
}
|
||||
@@ -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 RequestInterface|ResponseInterface|string|void
|
||||
*/
|
||||
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 ResponseInterface|void
|
||||
*/
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -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 ?>
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<@php
|
||||
|
||||
namespace {namespace};
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class {class} extends Model
|
||||
{
|
||||
<?php if (is_string($dbGroup)): ?>
|
||||
protected $DBGroup = '{dbGroup}';
|
||||
<?php endif; ?>
|
||||
protected $table = '{table}';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = {return};
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [];
|
||||
|
||||
protected bool $allowEmptyInserts = false;
|
||||
protected bool $updateOnlyChanged = true;
|
||||
|
||||
protected array $casts = [];
|
||||
protected array $castHandlers = [];
|
||||
|
||||
// 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 = [];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<@php
|
||||
|
||||
namespace {namespace};
|
||||
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
class {class} extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<@php
|
||||
|
||||
namespace {namespace};
|
||||
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
|
||||
class {class} extends CIUnitTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testExample(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<@php
|
||||
|
||||
namespace {namespace};
|
||||
|
||||
class {class}
|
||||
{
|
||||
// public function custom_rule(): bool
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user