PHP Class Bake\Shell\Task\ModelTask

Inheritance: extends Bake\Shell\Task\BakeTask
Afficher le fichier Open project: cakephp/bake Class Usage Examples

Méthodes publiques

Свойство Type Description
$pathFragment string path to Model directory
$skipTables array Tables to skip when running all()
$tasks array tasks

Protected Properties

Свойство Type Description
$_modelNames array Holds the model names
$_tables array Holds tables found on connection.
$_validations array Holds validation method map.

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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

_getPrefix() protected méthode

Models never have routing prefixes applied.
protected _getPrefix ( ) : string
Résultat string

all() public méthode

Bake all models at once.
public all ( ) : void
Résultat void

applyAssociations() public méthode

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.
Résultat void

bake() public méthode

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

bakeEntity() public méthode

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
Résultat string | null

bakeFixture() public méthode

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.
Résultat void

bakeTable() public méthode

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
Résultat string | null

bakeTest() public méthode

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

fieldValidation() public méthode

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
Résultat array Array of validation for the field.

findBelongsTo() public méthode

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
Résultat array Associations with belongsTo added in.

findBelongsToMany() public méthode

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
Résultat array Associations with belongsToMany added in.

findHasMany() public méthode

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
Résultat array Associations with hasMany added in.

findTableReferencedBy() public méthode

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.
Résultat string | null Either the referenced table or null if the field has no constraints.

getAssociations() public méthode

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

getBehaviors() public méthode

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

getCounterCache() public méthode

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

getDisplayField() public méthode

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

getEntityPropertySchema() public méthode

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.
Résultat array The property schema

getFields() public méthode

Evaluates the fields and no-fields options, and returns if, and which fields should be made accessible.
public getFields ( ) : array | boolean | null
Résultat 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 méthode

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

getOptionParser() public méthode

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

getPrimaryKey() public méthode

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

getRules() public méthode

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.
Résultat array The rules to be applied.

getTable() public méthode

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

getTableContext() public méthode

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.
Résultat array

getTableObject() public méthode

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
Résultat Cake\ORM\Table Table instance

getValidation() public méthode

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

listAll() public méthode

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

listUnskipped() public méthode

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

main() public méthode

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

Property Details

$_modelNames protected_oe property

Holds the model names
protected array $_modelNames
Résultat array

$_tables protected_oe property

Holds tables found on connection.
protected array $_tables
Résultat array

$_validations protected_oe property

Holds validation method map.
protected array $_validations
Résultat array

$pathFragment public_oe property

path to Model directory
public string $pathFragment
Résultat string

$skipTables public_oe property

Tables to skip when running all()
public array $skipTables
Résultat array

$tasks public_oe property

tasks
public array $tasks
Résultat array