CodeIgniter v4.5 API

MigrationGenerator extends BaseCommand
in package
uses GeneratorTrait

Generates a skeleton migration file.

Table of Contents

Properties

$arguments  : array<string, string>
$commands  : Commands
$description  : string
$group  : string
$logger  : LoggerInterface
$name  : string
$options  : array<string, string>
$usage  : string
$arguments  : array<string, string>
The Command's Arguments
$classNameLang  : string
Language string key for required class names.
$commands  : Commands
Instance of Commands so commands can call other commands.
$component  : string
Component Name
$description  : string
The Command's Description
$directory  : string
File directory
$group  : string
The Command's Group
$logger  : LoggerInterface
The Logger to use for a command
$name  : string
The Command's Name
$namespace  : string|null
Namespace to use for class.
$options  : array<string, string>
The Command's Options
$template  : string
View template name for fallback
$templatePath  : string|null
(Optional) View template path
$usage  : string
The Command's Usage

Methods

__construct()  : mixed
__get()  : array<string, string>|Commands|LoggerInterface|string|null
Makes it simple to access our protected properties.
__isset()  : bool
Makes it simple to check our protected properties.
getPad()  : int
Get pad for $key => $value array output
run()  : int|void
Actually execute a command.
setPad()  : string
Pads our string out so that all titles are the same length to nicely line up descriptions.
showHelp()  : void
Show Help includes (Usage, Arguments, Description, Options).
basename()  : string
Change file basename before saving.
buildContent()  : string
Builds the contents for class being generated, doing all the replacements necessary, and alphabetically sorts the imports for a given template.
buildPath()  : string
Builds the file path from the class name.
call()  : int|void
Can be used by a command to run other commands.
execute()  : void
Execute the command.
generateClass()  : void
Generates a class file from an existing template.
generateView()  : void
Generate a view file from an existing template.
getNamespace()  : string
Gets the namespace from the command-line option, or the default namespace if the option is not set.
getOption()  : bool|string|null
Gets a single command-line option. Returns TRUE if the option exists, but doesn't have a value, and is simply acting as a flag.
parseTemplate()  : string
Performs pseudo-variables contained within view file.
prepare()  : string
Prepare options and do the necessary replacements.
qualifyClassName()  : string
Parses the class name and checks if it is already qualified.
renderTemplate()  : string
Gets the generator view as defined in the `Config\Generators::$views`, with fallback to `$template` when the defined view does not exist.
setEnabledSuffixing()  : $this
Allows child generators to modify the internal `$enabledSuffixing` flag.
setHasClassName()  : $this
Allows child generators to modify the internal `$hasClassName` flag.
setSortImports()  : $this
Allows child generators to modify the internal `$sortImports` flag.
showError()  : void
A simple method to display an error with line/file, in child commands.
generateFile()  : void
Handles writing the file to disk, and all of the safety checks around that.
normalizeInputClassName()  : string
Normalize input classname.

Properties

$arguments

The Command's Arguments

protected array<string, string> $arguments = ['name' => 'The migration class name.']

$classNameLang

Language string key for required class names.

protected string $classNameLang = ''

$commands

Instance of Commands so commands can call other commands.

protected Commands $commands

$description

The Command's Description

protected string $description = 'Generates a new migration file.'

$logger

The Logger to use for a command

protected LoggerInterface $logger

$namespace

Namespace to use for class.

protected string|null $namespace = null

Leave null to use the default namespace.

$options

The Command's Options

protected array<string, string> $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).']

$template

View template name for fallback

protected string $template

$templatePath

(Optional) View template path

protected string|null $templatePath = null

We use special namespaced paths like: CodeIgniter\Commands\Generators\Views\cell.tpl.php.

$usage

The Command's Usage

protected string $usage = 'make:migration <name> [options]'

Methods

__construct()

public __construct(LoggerInterface $logger, Commands $commands) : mixed
Parameters
$logger : LoggerInterface
$commands : Commands

__get()

Makes it simple to access our protected properties.

public __get(string $key) : array<string, string>|Commands|LoggerInterface|string|null
Parameters
$key : string
Return values
array<string, string>|Commands|LoggerInterface|string|null

__isset()

Makes it simple to check our protected properties.

public __isset(string $key) : bool
Parameters
$key : string
Return values
bool

getPad()

Get pad for $key => $value array output

public getPad(array<string, string> $array, int $pad) : int

Use setPad() instead.

Parameters
$array : array<string, string>
$pad : int
Tags
codeCoverageIgnore
Return values
int

run()

Actually execute a command.

public run(array<string|int, mixed> $params) : int|void
Parameters
$params : array<string|int, mixed>
Return values
int|void

setPad()

Pads our string out so that all titles are the same length to nicely line up descriptions.

public setPad(string $item, int $max[, int $extra = 2 ][, int $indent = 0 ]) : string
Parameters
$item : string
$max : int
$extra : int = 2

How many extra spaces to add at the end

$indent : int = 0
Return values
string

showHelp()

Show Help includes (Usage, Arguments, Description, Options).

public showHelp() : void

basename()

Change file basename before saving.

protected basename(string $filename) : string
Parameters
$filename : string
Return values
string

buildContent()

Builds the contents for class being generated, doing all the replacements necessary, and alphabetically sorts the imports for a given template.

protected buildContent(string $class) : string
Parameters
$class : string
Return values
string

buildPath()

Builds the file path from the class name.

protected buildPath(string $class) : string
Parameters
$class : string

namespaced classname or namespaced view.

Return values
string

call()

Can be used by a command to run other commands.

protected call(string $command[, array<int|string, string|null> $params = [] ]) : int|void
Parameters
$command : string
$params : array<int|string, string|null> = []
Tags
throws
ReflectionException
Return values
int|void

execute()

Execute the command.

protected execute(array<int|string, string|null> $params) : void

use generateClass() instead

Parameters
$params : array<int|string, string|null>

generateClass()

Generates a class file from an existing template.

protected generateClass(array<int|string, string|null> $params) : void
Parameters
$params : array<int|string, string|null>

generateView()

Generate a view file from an existing template.

protected generateView(string $view, array<int|string, string|null> $params) : void
Parameters
$view : string

namespaced view name that is generated

$params : array<int|string, string|null>

getNamespace()

Gets the namespace from the command-line option, or the default namespace if the option is not set.

protected getNamespace() : string

Can be overridden by directly setting $this->namespace.

Return values
string

getOption()

Gets a single command-line option. Returns TRUE if the option exists, but doesn't have a value, and is simply acting as a flag.

protected getOption(string $name) : bool|string|null
Parameters
$name : string
Return values
bool|string|null

parseTemplate()

Performs pseudo-variables contained within view file.

protected parseTemplate(string $class[, array<int, string> $search = [] ][, array<int, string> $replace = [] ][, array<string, bool|string|null> $data = [] ]) : string
Parameters
$class : string

namespaced classname or namespaced view.

$search : array<int, string> = []
$replace : array<int, string> = []
$data : array<string, bool|string|null> = []
Return values
string

generated file content

prepare()

Prepare options and do the necessary replacements.

protected prepare(string $class) : string
Parameters
$class : string
Return values
string

qualifyClassName()

Parses the class name and checks if it is already qualified.

protected qualifyClassName() : string
Return values
string

renderTemplate()

Gets the generator view as defined in the `Config\Generators::$views`, with fallback to `$template` when the defined view does not exist.

protected renderTemplate([array<string, mixed> $data = [] ]) : string
Parameters
$data : array<string, mixed> = []
Return values
string

setEnabledSuffixing()

Allows child generators to modify the internal `$enabledSuffixing` flag.

protected setEnabledSuffixing(bool $enabledSuffixing) : $this
Parameters
$enabledSuffixing : bool
Return values
$this

setHasClassName()

Allows child generators to modify the internal `$hasClassName` flag.

protected setHasClassName(bool $hasClassName) : $this
Parameters
$hasClassName : bool
Return values
$this

setSortImports()

Allows child generators to modify the internal `$sortImports` flag.

protected setSortImports(bool $sortImports) : $this
Parameters
$sortImports : bool
Return values
$this

showError()

A simple method to display an error with line/file, in child commands.

protected showError(Throwable $e) : void
Parameters
$e : Throwable

generateFile()

Handles writing the file to disk, and all of the safety checks around that.

private generateFile(string $target, string $content) : void
Parameters
$target : string

file path

$content : string

normalizeInputClassName()

Normalize input classname.

private normalizeInputClassName() : string
Return values
string

        
On this page

Search results