ScaffoldCommand
extends Command
in package
CLI command for generating a complete Neuron ORM CRUD scaffold.
Emits a model, DTO YAML, repository (interface + implementation),
attribute-routed controller, field-aware views and (for new tables) a
migration. Fields come from a --fields spec or from introspecting an
existing table via --from-table.
Table of Contents
Properties
- $arguments : array<string|int, mixed>
- $input : Input
- $inputReader : IInputReader|null
- $options : array<string|int, mixed>
- $output : Output
- $_HasMvcComponent : bool
- $_Messages : array<string|int, mixed>
- $_ProjectPath : string
- $fs : IFileSystem
- $scaffolder : ResourceScaffolder
- $templates : ITemplateEngine
Methods
- __construct() : mixed
- configure() : void
- Configure the command
- execute() : int
- Execute the command
- getArguments() : array<string|int, mixed>
- Get all configured arguments
- getDescription() : string
- Get the command description
- getHelp() : string
- Get the help text for this command
- getName() : string
- Get the command name
- getOptions() : array<string|int, mixed>
- Get all configured options
- hasArgument() : bool
- Check if the command has a specific argument
- hasOption() : bool
- Check if the command has a specific option
- setInput() : self
- Set the input instance
- setInputReader() : self
- Set the input reader (for dependency injection, especially in tests).
- setOutput() : self
- Set the output instance
- validate() : void
- Validate that required arguments are present
- addArgument() : self
- Add an argument to the command
- addOption() : self
- Add an option to the command
- choice() : string
- Prompt user to select from a list of options.
- confirm() : bool
- Ask user for yes/no confirmation.
- getInputReader() : IInputReader
- Get the input reader instance.
- prompt() : string
- Prompt user for input.
- secret() : string
- Prompt for sensitive input without echoing to console.
- applyFieldConventions() : array<string|int, mixed>
- Refine info with details that depend on the resolved field set.
- applyFieldFilters() : FieldSet
- Narrow the editable surface (DTO + views) using --only / --except.
- buildInfo() : array<string|int, mixed>
- Build the placeholder/info array for the resource.
- databaseConfig() : array<string|int, mixed>
- Read the database configuration section from the project settings.
- decorateWithConventions() : FieldSet
- Prepend an auto-increment primary key and append timestamp columns to a --fields derived set, mirroring the generated migration.
- findConfigPath() : string|null
- Find configuration directory
- generateMigration() : bool
- Generate migration file
- generateMigrationTemplate() : string
- Generate migration template content
- getFieldOptions() : array<string|int, mixed>
- Get field options based on type
- loadSettings() : Yaml|null
- Load settings from config directory
- mapFieldType() : string
- Map field type to Phinx type
- parseFields() : array<string|int, mixed>
- Parse field definitions string
- parseResourceName() : array<string|int, mixed>
- Parse resource name into naming components.
- pluralize() : string
- Simple pluralization
- printFieldList() : void
- Print the resolved columns (used by --list-fields) so the caller can decide what to pass to --only / --except before generating.
- printSummary() : void
- Print the success summary, next steps and DI binding guidance.
- resolveFieldSet() : FieldSet
- Resolve a FieldSet from --from-table introspection or --fields.
- underscore() : string
- Convert PascalCase to snake_case
Properties
$arguments
protected
array<string|int, mixed>
$arguments
= []
$input
protected
Input
$input
$inputReader
protected
IInputReader|null
$inputReader
= null
$options
protected
array<string|int, mixed>
$options
= []
$output
protected
Output
$output
$_HasMvcComponent
private
bool
$_HasMvcComponent
= false
$_Messages
private
array<string|int, mixed>
$_Messages
= []
$_ProjectPath
private
string
$_ProjectPath
$fs
private
IFileSystem
$fs
$scaffolder
private
ResourceScaffolder
$scaffolder
$templates
private
ITemplateEngine
$templates
Methods
__construct()
public
__construct([IFileSystem|null $fs = null ][, ITemplateEngine|null $templates = null ]) : mixed
Parameters
- $fs : IFileSystem|null = null
- $templates : ITemplateEngine|null = null
configure()
Configure the command
public
configure() : void
execute()
Execute the command
public
execute([array<string|int, mixed> $Parameters = [] ]) : int
Parameters
- $Parameters : array<string|int, mixed> = []
Return values
int —Exit code (0 for success)
getArguments()
Get all configured arguments
public
getArguments() : array<string|int, mixed>
Return values
array<string|int, mixed>getDescription()
Get the command description
public
getDescription() : string
Tags
Return values
stringgetHelp()
Get the help text for this command
public
getHelp() : string
Return values
stringgetName()
Get the command name
public
getName() : string
Tags
Return values
stringgetOptions()
Get all configured options
public
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>hasArgument()
Check if the command has a specific argument
public
hasArgument(string $name) : bool
Parameters
- $name : string
Return values
boolhasOption()
Check if the command has a specific option
public
hasOption(string $name) : bool
Parameters
- $name : string
Return values
boolsetInput()
Set the input instance
public
setInput(Input $input) : self
Parameters
- $input : Input
Return values
selfsetInputReader()
Set the input reader (for dependency injection, especially in tests).
public
setInputReader(IInputReader $inputReader) : self
This allows tests to inject a TestInputReader with pre-programmed responses instead of requiring actual user input.
Parameters
- $inputReader : IInputReader
Return values
selfsetOutput()
Set the output instance
public
setOutput(Output $output) : self
Parameters
- $output : Output
Return values
selfvalidate()
Validate that required arguments are present
public
validate() : void
Tags
addArgument()
Add an argument to the command
protected
addArgument(string $name[, bool $required = false ][, string $description = '' ][, mixed $default = null ]) : self
Parameters
- $name : string
-
Argument name
- $required : bool = false
-
Whether the argument is required
- $description : string = ''
-
Description of the argument
- $default : mixed = null
-
Default value if not provided
Return values
selfaddOption()
Add an option to the command
protected
addOption(string $name[, string|null $shortcut = null ][, bool $hasValue = false ][, string $description = '' ][, mixed $default = null ]) : self
Parameters
- $name : string
-
Option name (long form)
- $shortcut : string|null = null
-
Option shortcut (single character)
- $hasValue : bool = false
-
Whether the option accepts a value
- $description : string = ''
-
Description of the option
- $default : mixed = null
-
Default value if not provided
Return values
selfchoice()
Prompt user to select from a list of options.
protected
choice(string $message, array<string|int, string> $options[, string|null $default = null ]) : string
Convenience method that delegates to the input reader. Users can select by entering either the option index (numeric) or the exact option text.
Example:
$env = $this->choice(
"Select environment:",
['development', 'staging', 'production'],
'development'
);
Parameters
- $message : string
-
The prompt message
- $options : array<string|int, string>
-
Available options
- $default : string|null = null
-
Default option (will be marked with *)
Return values
string —The selected option
confirm()
Ask user for yes/no confirmation.
protected
confirm(string $message[, bool $default = false ]) : bool
Convenience method that delegates to the input reader. Accepts: y, yes, true, 1 (case-insensitive) as positive responses.
Example:
if( $this->confirm( "Delete all files?" ) ) {
// User confirmed
}
Parameters
- $message : string
-
The confirmation message
- $default : bool = false
-
Default value if user just presses enter
Return values
bool —True if user confirms, false otherwise
getInputReader()
Get the input reader instance.
protected
getInputReader() : IInputReader
Creates a default StdinInputReader if not already set. This enables testable CLI commands by abstracting user input.
If output hasn't been set, a default Output instance will be created automatically.
Return values
IInputReaderprompt()
Prompt user for input.
protected
prompt(string $message) : string
Convenience method that delegates to the input reader.
Example:
$name = $this->prompt( "Enter your name: " );
Parameters
- $message : string
-
The prompt message to display
Return values
string —The user's response (trimmed)
secret()
Prompt for sensitive input without echoing to console.
protected
secret(string $message) : string
Convenience method that delegates to the input reader. Note: Secret input hiding only works on Unix-like systems.
Example:
$password = $this->secret( "Enter password: " );
Parameters
- $message : string
-
The prompt message
Return values
string —The user's input (trimmed)
applyFieldConventions()
Refine info with details that depend on the resolved field set.
private
applyFieldConventions(array<string|int, mixed> $info, FieldSet $fields) : array<string|int, mixed>
Parameters
- $info : array<string|int, mixed>
- $fields : FieldSet
Return values
array<string|int, mixed>applyFieldFilters()
Narrow the editable surface (DTO + views) using --only / --except.
private
applyFieldFilters(FieldSet $fields) : FieldSet
The model, repository and migration are unaffected: they always map the complete table so inserts/updates remain valid. Returns the full set unchanged when neither option is supplied.
Parameters
- $fields : FieldSet
Tags
Return values
FieldSetbuildInfo()
Build the placeholder/info array for the resource.
private
buildInfo(string $resourceName) : array<string|int, mixed>
Parameters
- $resourceName : string
Return values
array<string|int, mixed>databaseConfig()
Read the database configuration section from the project settings.
private
databaseConfig() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>decorateWithConventions()
Prepend an auto-increment primary key and append timestamp columns to a --fields derived set, mirroring the generated migration.
private
decorateWithConventions(FieldSet $fields) : FieldSet
Parameters
- $fields : FieldSet
Return values
FieldSetfindConfigPath()
Find configuration directory
private
findConfigPath() : string|null
Return values
string|nullgenerateMigration()
Generate migration file
private
generateMigration(array<string|int, mixed> $info) : bool
Parameters
- $info : array<string|int, mixed>
Return values
boolgenerateMigrationTemplate()
Generate migration template content
private
generateMigrationTemplate(array<string|int, mixed> $info, string $fieldsString) : string
Parameters
- $info : array<string|int, mixed>
- $fieldsString : string
Return values
stringgetFieldOptions()
Get field options based on type
private
getFieldOptions(string $type, string $name) : array<string|int, mixed>
Parameters
- $type : string
- $name : string
Return values
array<string|int, mixed>loadSettings()
Load settings from config directory
private
loadSettings(string $configPath) : Yaml|null
Parameters
- $configPath : string
Return values
Yaml|nullmapFieldType()
Map field type to Phinx type
private
mapFieldType(string $type) : string
Parameters
- $type : string
Return values
stringparseFields()
Parse field definitions string
private
parseFields(string $fieldsString) : array<string|int, mixed>
Parameters
- $fieldsString : string
Return values
array<string|int, mixed>parseResourceName()
Parse resource name into naming components.
private
parseResourceName(string $name) : array<string|int, mixed>
Parameters
- $name : string
Return values
array<string|int, mixed>pluralize()
Simple pluralization
private
pluralize(string $word) : string
Parameters
- $word : string
Return values
stringprintFieldList()
Print the resolved columns (used by --list-fields) so the caller can decide what to pass to --only / --except before generating.
private
printFieldList(array<string|int, mixed> $info, FieldSet $fields) : void
Parameters
- $info : array<string|int, mixed>
- $fields : FieldSet
printSummary()
Print the success summary, next steps and DI binding guidance.
private
printSummary(array<string|int, mixed> $info) : void
Parameters
- $info : array<string|int, mixed>
resolveFieldSet()
Resolve a FieldSet from --from-table introspection or --fields.
private
resolveFieldSet(array<string|int, mixed> $info) : FieldSet
Parameters
- $info : array<string|int, mixed>
Tags
Return values
FieldSetunderscore()
Convert PascalCase to snake_case
private
underscore(string $word) : string
Parameters
- $word : string