ScaffoldTask
Generate model layers, interfaces, enums, and tests from the shared db service.
Uses dispatcher options documented by cliDoc. Existing files are preserved unless --force is set, which also permits overwriting concrete application models. Use the --no-* switches to restrict regeneration to files owned by the scaffolder.
- Full name:
\PhalconKit\Modules\Cli\Tasks\ScaffoldTask - Parent class:
\PhalconKit\Modules\Cli\Task
Properties
cliDoc
public string $cliDoc
Methods
getDefinitionsAction
Build output names for one database table without writing files.
public getDefinitionsAction(string $name): array{table: string, source: string, slug: string, enums: array{name: string, file: string}, controller: array{name: string, file: string}, controllerInterface: array{name: string, file: string}, abstract: array{name: string, file: string}, abstractInterface: array{name: string, file: string}, model: array{name: string, file: string}, modelInterface: array{name: string, file: string}, modelTest: array{name: string, file: string}}
Parameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | Source table name. |
runAction
Inspect selected tables and write the enabled model, interface, enum, and test files.
public runAction(): list<string>
--table and --exclude select tables. --force allows replacing existing files, including concrete model shells; no merge with application code is attempted. Output directories are created by saveFile(). Controller generation is not dispatched here even though controller template helpers are available.
Return Value:
Descriptions of the generation attempts for enabled output.
Throws:
When schema inspection fails. - Exception When the database rejects a schema query. - PDOException
createControllerOutput
public createControllerOutput(array $definitions, array $columns, array $relationships): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$definitions | array | |
$columns | array | |
$relationships | array |
createModelInterfaceOutput
Generates the output for a model interface.
public createModelInterfaceOutput(array $definitions): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$definitions | array | The definitions for generating the model interface. |
Return Value:
The generated model interface output as a string.
createAbstractInterfaceOutput
Generates the abstract interface output based on the given definitions and columns.
public createAbstractInterfaceOutput(array $definitions, array $columns, array $relationships): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$definitions | array | The definitions for the abstract interface. |
$columns | array | The columns for which to generate getter and setter methods. |
$relationships | array | The columns for which to generate getter and setter methods. |
Return Value:
The generated abstract interface output as a string.
createAbstractOutput
Generates an abstract class output for the given definitions, table, columns, and tables.
public createAbstractOutput(array $definitions, array $columns, array $relationships, array $indexes): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$definitions | array | The definitions for the abstract output. |
$columns | array | The columns. |
$relationships | array | The relationship items. |
$indexes | array |
Return Value:
The abstract output as a string.
createEnumOutput
public createEnumOutput(string $enumName, \Phalcon\Db\Column $column): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$enumName | string | |
$column | \Phalcon\Db\Column |
createModelOutput
Generates a comment for the createModelOutput method.
public createModelOutput(array $definitions): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$definitions | array | The array of model definitions. |
Return Value:
The generated comment.
createModelTestOutput
public createModelTestOutput(array $definitions, array $columns): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$definitions | array | |
$columns | array |
getModelClassComments
public getModelClassComments(array $definitions): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$definitions | array |
getValidationItems
Generates a string containing validation items for each column in the provided array.
public getValidationItems(array $columns, array $indexes): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$columns | array | An array of column contracts. |
$indexes | array | An array of index contracts. |
Return Value:
The generated validation items string.
getBooleanColumnAttributes
Resolve explicitly configured table.column flags to model attributes.
protected getBooleanColumnAttributes(\Phalcon\Contracts\Db\Column[] $columns, string $table): array<string,bool>
The boolean-columns CLI option applies only to named integer columns. Unknown columns, non-integers and identity columns on the current table are rejected before generating its abstract. No database changes occur.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$columns | \Phalcon\Contracts\Db\Column[] | Columns described for this table. |
$table | string | Original SQL table name. |
Return Value:
Mapped attributes => allowEmpty.
Throws:
For an invalid flag declaration. - InvalidArgumentException
getRelationshipItems
Generates relationship items for a given table.
public getRelationshipItems(string $table, array $columns, array $tables): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | The name of the table. |
$columns | array | The array of column objects. |
$tables | array | The array of table names. |
Return Value:
An array containing the generated relationship items.
getManyToManyRelationshipAlias
Select a stable alias for generated many-to-many relationships.
private getManyToManyRelationshipAlias(string $table, string $intermediateTable, string $targetTable, string $intermediateName, string $targetName, array $directRelationshipAliases, array<string,bool> $relationshipAliases): string
Short target aliases such as RightList are reserved for canonical two-table junctions like left_right or right_left. Contextual intermediate tables, such as communication_update_user, keep the intermediate model in the alias so they cannot shadow a direct relation.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | |
$intermediateTable | string | |
$targetTable | string | |
$intermediateName | string | |
$targetName | string | |
$directRelationshipAliases | array | |
$relationshipAliases | array |
getDirectHasManyRelationshipAliases
private getDirectHasManyRelationshipAliases(string $table, array<int,\Phalcon\Contracts\Db\Column> $columns, array<int,string> $tables): array<string,bool>
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | |
$columns | array | |
$tables | array |
isCanonicalManyToManyTable
private isCanonicalManyToManyTable(string $table, string $intermediateTable, string $targetTable): bool
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | |
$intermediateTable | string | |
$targetTable | string |
reserveRelationshipAlias
private reserveRelationshipAlias(array<string,bool>& $relationshipAliases, string $alias): bool
Parameters:
| Parameter | Type | Description |
|---|---|---|
$relationshipAliases | array | |
$alias | string |
hasRelationshipAlias
private hasRelationshipAlias(array<string,bool> $relationshipAliases, string $alias): bool
Parameters:
| Parameter | Type | Description |
|---|---|---|
$relationshipAliases | array | |
$alias | string |
getColumnMapMethod
public getColumnMapMethod(array $columns): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$columns | array |
getColumnMapComment
Returns the documentation comment for the getColumnMap method.
public getColumnMapComment(): string
Return Value:
The documentation comment for the getColumnMap method.
getColumnMapItems
Generates a string representation of column map items for a given array of columns.
public getColumnMapItems(array $columns): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$columns | array | An array of columns. |
Return Value:
The string representation of the column map items.
getPropertyItems
Generates property items for each column in the given array.
public getPropertyItems(array $columns): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$columns | array | An array of column contracts. |
Return Value:
The generated property items.
getPropertyComment
Generates the comment for a property with the given column name and property type.
public getPropertyComment(\Phalcon\Contracts\Db\Column $column, array $definitions): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$column | \Phalcon\Contracts\Db\Column | The column object. |
$definitions | array | The property definitions. |
Return Value:
The generated property comment.
getGetSetMethods
Generates a string representation of getters and setters for a given array of columns.
public getGetSetMethods(array $columns, string $type = 'default', string $property = 'model'): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$columns | array | An array of columns. |
$type | string | (optional) The type of code to generate. Can be 'default', 'interface', or 'test'. Default is 'default'. |
$property | string | (optional) The name of the property to use in setter methods. Default is 'model'. |
Return Value:
The string representation of the getters and setters.
getSetMethodComment
Generates a comment for a getter or setter method for a specific column.
public getSetMethodComment(\Phalcon\Contracts\Db\Column $column, array $definitions, bool $get): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$column | \Phalcon\Contracts\Db\Column | The column object. |
$definitions | array | The property definitions. |
$get | bool | Determines whether the comment is for a getter or setter method. |
Return Value:
The generated comment.
getColumnAttributes
public getColumnAttributes(\Phalcon\Contracts\Db\Column $column): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$column | \Phalcon\Contracts\Db\Column |
getPropertyDefinitions
public getPropertyDefinitions(\Phalcon\Contracts\Db\Column $column): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$column | \Phalcon\Contracts\Db\Column |
saveFile
Saves a file with the given text content.
public saveFile(string $file, string $text, bool $force = false): bool
Parameters:
| Parameter | Type | Description |
|---|---|---|
$file | string | The path of the file to be saved. |
$text | string | The content to be written to the file. |
$force | bool | Determines whether to overwrite an existing file. Default is false. |
Return Value:
Returns true if the file was saved successfully, false otherwise.
Inherited methods
beforeExecuteRoute
public beforeExecuteRoute(): void
helpAction
public helpAction(): void
mainAction
public mainAction(): ?array
afterExecuteRoute
Handle rest response automagically
public afterExecuteRoute(\Phalcon\Cli\Dispatcher $dispatcher): void
Parameters:
| Parameter | Type | Description |
|---|---|---|
$dispatcher | \Phalcon\Cli\Dispatcher |
Throws:
normalizeCliPayload
Normalize values before CLI output serializers see them.
protected normalizeCliPayload(mixed $payload): mixed
Phalcon message objects are useful inside the framework but are opaque for JSON automation. This helper recursively converts them into scalar arrays while leaving other payload values unchanged.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$payload | mixed |
normalizeCliMessages
Normalize a list of model messages and optionally add a fallback entry.
protected normalizeCliMessages(iterable $messages, ?string $fallbackMessage = null): list<array{message: string, field: string|null, type: string|null, code: int|null}>
Parameters:
| Parameter | Type | Description |
|---|---|---|
$messages | iterable | Messages returned by a model or resultset. |
$fallbackMessage | ?string |
describeColumns
Retrieves the columns of a given table.
public describeColumns(string $table): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | The name of the table to describe the columns. |
Return Value:
An array of columns for the specified table.
describeReferences
Retrieves the references of a given table.
public describeReferences(string $table): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | The name of the table to describe the references. |
Return Value:
An array of references for the specified table.
describeIndexes
Retrieves the indexes of a given table.
public describeIndexes(string $table): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | The name of the table to describe the indexes. |
Return Value:
An array of indexes for the specified table.
isRawValue
Determines if a value is a Phalcon DB RawValue.
public isRawValue(string|null $defaultValue = null): bool
Parameters:
| Parameter | Type | Description |
|---|---|---|
$defaultValue | string|null | The value to check. |
Return Value:
Returns true if the value is a raw value, false otherwise.
getColumnType
Determines the PHP data type of column.
public getColumnType(\Phalcon\Contracts\Db\Column $column): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$column | \Phalcon\Contracts\Db\Column | The column to check. |
Return Value:
The data type of the column. Possible values are: - 'bool' for boolean columns. - 'int' for integer columns. - 'float' for decimal or float columns. - 'double' for double columns. - 'string' for all other column types.
getDefaultValue
Retrieves the default value for a column.
public getDefaultValue(\Phalcon\Contracts\Db\Column $column): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$column | \Phalcon\Contracts\Db\Column | The column object to retrieve the default value from. |
Return Value:
Returns the default value of the column as a string, integer, boolean, float, or null based on the column type.
getPropertyName
Retrieves the property name based on the given name.
public getPropertyName(string $name): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | The name from which to retrieve the property name. |
Return Value:
Returns the property name as a string.
getTableName
Retrieves the table name based on the given name.
public getTableName(string $name): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | The original name of the table. |
Return Value:
Returns the table name with the first letter capitalized and all other letters unchanged.
wrapIdentifier
Wraps a property name in square brackets if certain conditions are met.
public wrapIdentifier(string $name, bool $always = false): string
Note: fields that are already wrapped will not be wrapped again.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | The name of the property to be wrapped. |
$always | bool | Indicates whether the property name should always be wrapped, regardless of other conditions. |
Return Value:
The property name, optionally wrapped in square brackets.
requiresWrapping
Determines whether a property name should be wrapped based on specific conditions.
public requiresWrapping(string $name, bool $always = false): bool
Reasoning: Phalcon PHQL parser has a bug with function names starting with 'not'.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | The property name to check for wrapping. |
$always | bool | Whether to always wrap the property name regardless of other conditions. |
Return Value:
True if the property name should be wrapped, otherwise false.
getLicenseStamp
Return the --license override or default header text.
public getLicenseStamp(): string|null
Return Value:
Header text, or an empty string when --no-license is set. The nullable signature is retained for task overrides.
getStrictTypes
Return the strict_types declaration for a generated PHP file.
public getStrictTypes(): string|null
Return Value:
Declaration text, or an empty string when --no-strict-types is set. The nullable signature is retained for task overrides.
getPhpFileHeader
Builds the normalized opening PHP header for scaffolded files.
public getPhpFileHeader(): string
Optional fragments, such as the license stamp and strict-types declaration, are trimmed before joining so disabled fragments do not leave extra blank lines in generated files.
Return Value:
Header text ending with exactly one blank line before the next top-level statement, typically a namespace declaration.
isWhitelistedTable
Checks if the given table is whitelisted.
public isWhitelistedTable(string $table): bool
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | The table name to check. |
Return Value:
True when --table is empty or includes this exact table name.
isExcludedTable
Determines if a table is excluded.
public isExcludedTable(string $table): bool
Parameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | The name of the table to check. |
Return Value:
Returns true if the table is excluded, false otherwise.
isNoControllers
Skip controller generation when --no-controllers is set.
public isNoControllers(): bool
isNoInterfaces
Skip model interface generation when --no-interfaces is set.
public isNoInterfaces(): bool
isNoAbstracts
Skip abstract model generation when --no-abstracts is set.
public isNoAbstracts(): bool
isNoModels
Skip concrete model generation when --no-models is set.
public isNoModels(): bool
isNoEnums
Skip enum generation when --no-enums is set.
public isNoEnums(): bool
isNoTests
Skip test generation when --no-tests is set.
public isNoTests(): bool
isNoStrictTypes
Omit the strict_types declaration when --no-strict-types is set.
public isNoStrictTypes(): bool
isNoLicense
Omit the generated license header when --no-license is set.
public isNoLicense(): bool
isNoComments
Omit optional generated documentation when --no-comments is set.
public isNoComments(): bool
isNoGetSetMethods
Omit generated accessors when --no-get-set-methods is set.
public isNoGetSetMethods(): bool
isNoValidations
Omit generated validation methods when --no-validations is set.
public isNoValidations(): bool
isNoRelationships
Omit generated relation definitions when --no-relationships is set.
public isNoRelationships(): bool
isNoColumnMap
Omit generated column maps when --no-column-map is set.
public isNoColumnMap(): bool
isNoSetSource
Omit generated source-table assignment when --no-set-source is set.
public isNoSetSource(): bool
isNoTypings
Omit optional generated type declarations when --no-typings is set.
public isNoTypings(): bool
isGranularTypings
Use the more specific scaffold type mappings requested by --granular-typings.
public isGranularTypings(): bool
isAddRawValueType
Include Phalcon RawValue in generated types when --add-raw-value-type is set.
public isAddRawValueType(): bool
isProtectedProperties
Generate protected model properties when --protected-properties is set.
public isProtectedProperties(): bool
isAbsolutePath
Determines if a given path is an absolute path.
public isAbsolutePath(string $path = ''): bool
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The path to be checked. (default: empty string) |
Return Value:
Returns true if the path is an absolute path, false otherwise.
absolutePathOr
Retrieves the absolute file or directory path.
public absolutePathOr(string $path = '', string $fullPath = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The relative or absolute path to the file or directory. |
$fullPath | string | The full path including directory for the file or directory. |
Return Value:
The absolute file or directory path. If the given path is absolute, it will be returned as is. Otherwise, the full path including directory will be returned.
getDirectory
Retrieves the directory path for a given file or directory path.
public getDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The relative or absolute path to the file or directory. |
Return Value:
Path under --directory, or the unchanged absolute $path. A relative --directory produces a relative result.
getSrcDirectory
Compose a path using the srcDir dispatcher option under the project directory.
public getSrcDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getTestsDirectory
Compose a path using the testsDir dispatcher option under the project directory.
public getTestsDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getControllersDirectory
Compose a path using the controllersDir dispatcher option under the source directory.
public getControllersDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getModelsDirectory
Compose a path using the modelsDir dispatcher option under the source directory.
public getModelsDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getModelsInterfacesDirectory
Compose a path using the interfacesDir dispatcher option under the models directory.
public getModelsInterfacesDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getEnumsDirectory
Compose a path using the enumsDir dispatcher option under the models directory.
public getEnumsDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getAbstractsDirectory
Compose a path using the abstractsDir dispatcher option under the models directory.
public getAbstractsDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getAbstractsInterfacesDirectory
Compose a path using the interfaceDir dispatcher option under the abstract models directory.
public getAbstractsInterfacesDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getModelsTestsDirectory
Compose a path using the modelsDir dispatcher option under the tests directory.
public getModelsTestsDirectory(string $path = ''): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Suffix to append; a leading slash returns this path unchanged. |
Return Value:
Composed path, which may remain relative to the working directory.
getModelsExtend
Return the model parent class name from modelsExtend, falling back to the task default.
public getModelsExtend(): string
getInterfacesExtend
Return the model parent interface name from interfacesExtend, falling back to the task default.
public getInterfacesExtend(): string
getTestsExtend
Return the test parent class name from testsExtend, falling back to the task default.
public getTestsExtend(): string
getControllersExtend
Return the controller parent class name from controllersExtend, falling back to the task default.
public getControllersExtend(): string
getNamespaceFromPath
Converts a file system path to a PHP namespace.
public getNamespaceFromPath(string $path): string
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The file system path to be converted. |
Return Value:
The converted PHP namespace.
getNamespace
Derive the project root namespace from its configured directory and base namespace.
public getNamespace(): string
getControllersNamespace
Derive the controllers namespace from its configured directory and base namespace.
public getControllersNamespace(): string
getEnumsNamespace
Derive the model enums namespace from its configured directory and base namespace.
public getEnumsNamespace(): string
getModelsNamespace
Derive the models namespace from its configured directory and base namespace.
public getModelsNamespace(): string
getAbstractsNamespace
Derive the abstract models namespace from its configured directory and base namespace.
public getAbstractsNamespace(): string
getModelsInterfacesNamespace
Derive the model interfaces namespace from its configured directory and base namespace.
public getModelsInterfacesNamespace(): string
getAbstractsInterfacesNamespace
Derive the abstract model interfaces namespace from its configured directory and base namespace.
public getAbstractsInterfacesNamespace(): string
getModelsTestsNamespace
Derive the model tests namespace from its configured directory and base namespace.
public getModelsTestsNamespace(): string