PHP Class Bake\Shell\Task\ModelTask

Inheritance: extends Bake\Shell\Task\BakeTask
Datei anzeigen Open project: cakephp/bake Class Usage Examples

Public Properties

Property Type Description
$pathFragment string path to Model directory
$skipTables array Tables to skip when running all()
$tasks array tasks

Protected Properties

Property Type Description
$_modelNames array Holds the model names
$_tables array Holds tables found on connection.
$_validations array Holds validation method map.

Public Methods

Method Description
all ( ) : void Bake all models at once.
applyAssociations ( Table $model, array $associations ) : void Sync the in memory table object.
bake ( string $name ) : void Generate code for the given model name.
bakeEntity ( Table $model, array $data = [] ) : string | null Bake an entity class.
bakeFixture ( string $className, string | null $useTable = null ) : void Interact with FixtureTask to automatically bake fixtures when baking models.
bakeTable ( Table $model, array $data = [] ) : string | null Bake a table class.
bakeTest ( string $className ) : string | null Assembles and writes a unit test file
fieldValidation ( Cake\Database\Schema\Table $schema, string $fieldName, array $metaData, string $primaryKey ) : array Does individual field validation handling.
findBelongsTo ( Table $model, array $associations ) : array Find belongsTo relations and add them to the associations list.
findBelongsToMany ( Table $model, array $associations ) : array Find the BelongsToMany relations and add them to associations list
findHasMany ( Table $model, array $associations ) : array Find the hasMany relations and add them to associations list
findTableReferencedBy ( Cake\Database\Schema\Table $schema, string $keyField ) : string | null find the table, if any, actually referenced by the passed key field.
getAssociations ( Table $table ) : array Get the array of associations to generate.
getBehaviors ( Table $model ) : array Get behaviors
getCounterCache ( Table $model ) : array Get CounterCaches
getDisplayField ( Table $model ) : string Get the display field from the model or parameters
getEntityPropertySchema ( Table $model ) : array Returns an entity property "schema".
getFields ( ) : array | boolean | null Evaluates the fields and no-fields options, and returns if, and which fields should be made accessible.
getHiddenFields ( Table $model ) : array Get the hidden fields from a model.
getOptionParser ( ) : Cake\Console\ConsoleOptionParser Gets the option parser instance and configures it.
getPrimaryKey ( Table $model ) : array Get the primary key field from the model or parameters
getRules ( Table $model, array $associations ) : array Generate default rules checker.
getTable ( string $name ) : string Get the table name for the model being baked.
getTableContext ( Table $tableObject, string $table, string $name ) : array Get table context for baking a given table.
getTableObject ( string $className, string $table ) : Table Get a model object for a class name.
getValidation ( Table $model, array $associations = [] ) : array Generate default validation rules.
listAll ( ) : array Outputs the a list of possible models or controllers from database
listUnskipped ( ) : array Outputs the a list of unskipped models or controllers from database
main ( string | null $name = null ) : void Execution method always used for tasks

Protected Methods

Method Description
_getAllTables ( ) : array Get an Array of all the tables in the supplied connection will halt the script if no tables are found.
_getPrefix ( ) : string Models never have routing prefixes applied.

Method Details

_getAllTables() protected method

Get an Array of all the tables in the supplied connection will halt the script if no tables are found.
protected _getAllTables ( ) : array
return array Array of tables in the database.

_getPrefix() protected method

Models never have routing prefixes applied.
protected _getPrefix ( ) : string
return string

all() public method

Bake all models at once.
public all ( ) : void
return void

applyAssociations() public method

Composer's class cache prevents us from loading the newly generated class. Applying associations if we have a generic table object means fields will be detected correctly.
public applyAssociations ( Table $model, array $associations ) : void
$model Cake\ORM\Table The table to apply associations to.
$associations array The associations to append.
return void

bake() public method

Generate code for the given model name.
public bake ( string $name ) : void
$name string The model name to generate.
return void

bakeEntity() public method

Bake an entity class.
public bakeEntity ( Table $model, array $data = [] ) : string | null
$model Cake\ORM\Table Model name or object
$data array An array to use to generate the Table
return string | null

bakeFixture() public method

Interact with FixtureTask to automatically bake fixtures when baking models.
See also: FixtureTask::bake
public bakeFixture ( string $className, string | null $useTable = null ) : void
$className string Name of class to bake fixture for
$useTable string | null Optional table name for fixture to use.
return void

bakeTable() public method

Bake a table class.
public bakeTable ( Table $model, array $data = [] ) : string | null
$model Cake\ORM\Table Model name or object
$data array An array to use to generate the Table
return string | null

bakeTest() public method

Assembles and writes a unit test file
public bakeTest ( string $className ) : string | null
$className string Model class name
return string | null

fieldValidation() public method

Does individual field validation handling.
public fieldValidation ( Cake\Database\Schema\Table $schema, string $fieldName, array $metaData, string $primaryKey ) : array
$schema Cake\Database\Schema\Table The table schema for the current field.
$fieldName string Name of field to be validated.
$metaData array metadata for field
$primaryKey string The primary key field
return array Array of validation for the field.

findBelongsTo() public method

Find belongsTo relations and add them to the associations list.
public findBelongsTo ( Table $model, array $associations ) : array
$model Cake\ORM\Table Database\Table instance of table being generated.
$associations array Array of in progress associations
return array Associations with belongsTo added in.

findBelongsToMany() public method

Find the BelongsToMany relations and add them to associations list
public findBelongsToMany ( Table $model, array $associations ) : array
$model Cake\ORM\Table Model instance being generated
$associations array Array of in-progress associations
return array Associations with belongsToMany added in.

findHasMany() public method

Find the hasMany relations and add them to associations list
public findHasMany ( Table $model, array $associations ) : array
$model Cake\ORM\Table Model instance being generated
$associations array Array of in progress associations
return array Associations with hasMany added in.

findTableReferencedBy() public method

Search tables in db for keyField; if found search key constraints for the table to which it refers.
public findTableReferencedBy ( Cake\Database\Schema\Table $schema, string $keyField ) : string | null
$schema Cake\Database\Schema\Table The table schema to find a constraint for.
$keyField string The field to check for a constraint.
return string | null Either the referenced table or null if the field has no constraints.

getAssociations() public method

Get the array of associations to generate.
public getAssociations ( Table $table ) : array
$table Cake\ORM\Table The table to get associations for.
return array

getBehaviors() public method

Get behaviors
public getBehaviors ( Table $model ) : array
$model Cake\ORM\Table The model to generate behaviors for.
return array Behaviors

getCounterCache() public method

Get CounterCaches
public getCounterCache ( Table $model ) : array
$model Cake\ORM\Table The table to get counter cache fields for.
return array CounterCache configurations

getDisplayField() public method

Get the display field from the model or parameters
public getDisplayField ( Table $model ) : string
$model Cake\ORM\Table The model to introspect.
return string

getEntityPropertySchema() public method

The schema is an associative array, using the property names as keys, and information about the property as the value. The value part consists of at least two keys: - kind: The kind of property, either column, which indicates that the property stems from a database column, or association, which identifies a property that is generated for an associated table. - type: The type of the property value. For the column kind this is the database type associated with the column, and for the association type it's the FQN of the entity class for the associated table. For association properties an additional key will be available - association: Holds an instance of the corresponding association class.
public getEntityPropertySchema ( Table $model ) : array
$model Cake\ORM\Table The model to introspect.
return array The property schema

getFields() public method

Evaluates the fields and no-fields options, and returns if, and which fields should be made accessible.
public getFields ( ) : array | boolean | null
return array | boolean | null Either an array of fields, `false` in case the no-fields option is used, or `null` if none of the field options is used.

getHiddenFields() public method

Uses the hidden and no-hidden options.
public getHiddenFields ( Table $model ) : array
$model Cake\ORM\Table The model to introspect.
return array The columns to make accessible

getOptionParser() public method

Gets the option parser instance and configures it.
public getOptionParser ( ) : Cake\Console\ConsoleOptionParser
return Cake\Console\ConsoleOptionParser

getPrimaryKey() public method

Get the primary key field from the model or parameters
public getPrimaryKey ( Table $model ) : array
$model Cake\ORM\Table The model to introspect.
return array The columns in the primary key

getRules() public method

Generate default rules checker.
public getRules ( Table $model, array $associations ) : array
$model Cake\ORM\Table The model to introspect.
$associations array The associations for the model.
return array The rules to be applied.

getTable() public method

Uses the table option if it is set.
public getTable ( string $name ) : string
$name string Table name
return string

getTableContext() public method

Get table context for baking a given table.
public getTableContext ( Table $tableObject, string $table, string $name ) : array
$tableObject Cake\ORM\Table The model name to generate.
$table string The table name for the model being baked.
$name string The model name to generate.
return array

getTableObject() public method

Get a model object for a class name.
public getTableObject ( string $className, string $table ) : Table
$className string Name of class you want model to be.
$table string Table name
return Cake\ORM\Table Table instance

getValidation() public method

Generate default validation rules.
public getValidation ( Table $model, array $associations = [] ) : array
$model Cake\ORM\Table The model to introspect.
$associations array The associations list.
return array The validation rules.

listAll() public method

Outputs the a list of possible models or controllers from database
public listAll ( ) : array
return array

listUnskipped() public method

Outputs the a list of unskipped models or controllers from database
public listUnskipped ( ) : array
return array

main() public method

Execution method always used for tasks
public main ( string | null $name = null ) : void
$name string | null The name of the table to bake.
return void

Property Details

$_modelNames protected_oe property

Holds the model names
protected array $_modelNames
return array

$_tables protected_oe property

Holds tables found on connection.
protected array $_tables
return array

$_validations protected_oe property

Holds validation method map.
protected array $_validations
return array

$pathFragment public_oe property

path to Model directory
public string $pathFragment
return string

$skipTables public_oe property

Tables to skip when running all()
public array $skipTables
return array

$tasks public_oe property

tasks
public array $tasks
return array