Skip to content

ScaffoldTask

Base class for PhalconKit CLI tasks.

Extend this class for framework/application CLI tasks that need Phalcon's native task lifecycle plus PhalconKit injectable service annotations. The class does not add task behavior itself; action methods remain normal Phalcon CLI task methods.


Properties

cliDoc

public string $cliDoc

Methods

getDefinitionsAction

public getDefinitionsAction(string $name): array

Parameters:

Parameter Type Description
$name string

runAction

public runAction(): array

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.


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

Retrieves the license stamp.

public getLicenseStamp(): string|null

Return Value:

The license stamp, or null if there is no license.


getStrictTypes

Retrieves the value of the 'strictTypes' property.

public getStrictTypes(): string|null

Return Value:

The value of the 'strictTypes' property, or null if the 'no-strict-types' parameter is set.


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:

Returns true if the table is whitelisted, false otherwise.


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

public isNoControllers(): bool

isNoInterfaces

public isNoInterfaces(): bool

isNoAbstracts

public isNoAbstracts(): bool

isNoModels

public isNoModels(): bool

isNoEnums

public isNoEnums(): bool

isNoTests

public isNoTests(): bool

isNoStrictTypes

public isNoStrictTypes(): bool

isNoLicense

public isNoLicense(): bool

isNoComments

public isNoComments(): bool

isNoGetSetMethods

public isNoGetSetMethods(): bool

isNoValidations

public isNoValidations(): bool

isNoRelationships

public isNoRelationships(): bool

isNoColumnMap

public isNoColumnMap(): bool

isNoSetSource

public isNoSetSource(): bool

isNoTypings

public isNoTypings(): bool

isGranularTypings

public isGranularTypings(): bool

isAddRawValueType

public isAddRawValueType(): bool

isProtectedProperties

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: null)

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:

The absolute directory path for the given file or directory path.


getSrcDirectory

public getSrcDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getTestsDirectory

public getTestsDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getControllersDirectory

public getControllersDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getModelsDirectory

public getModelsDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getModelsInterfacesDirectory

public getModelsInterfacesDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getEnumsDirectory

public getEnumsDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getAbstractsDirectory

public getAbstractsDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getAbstractsInterfacesDirectory

public getAbstractsInterfacesDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getModelsTestsDirectory

public getModelsTestsDirectory(string $path = ''): string

Parameters:

Parameter Type Description
$path string

getModelsExtend

public getModelsExtend(): string

getInterfacesExtend

public getInterfacesExtend(): string

getTestsExtend

public getTestsExtend(): string

getControllersExtend

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

public getNamespace(): string

getControllersNamespace

public getControllersNamespace(): string

getEnumsNamespace

public getEnumsNamespace(): string

getModelsNamespace

public getModelsNamespace(): string

getAbstractsNamespace

public getAbstractsNamespace(): string

getModelsInterfacesNamespace

public getModelsInterfacesNamespace(): string

getAbstractsInterfacesNamespace

public getAbstractsInterfacesNamespace(): string

getModelsTestsNamespace

public getModelsTestsNamespace(): string