Class TypeMap
Implements default and single-use mappings for columns to their associated types
Properties summary
-
$_defaults
protectedAssociative array with the default fields and the related types this query might contain.array
-
$_types
protectedAssociative array with the fields and the related types that override defaults this query might containarray
Method Summary
- __construct() publicCreates an instance with the given defaults
- addDefaults() publicAdd additional default types into the type map.
- defaults() public
Configures a map of default fields and their associated types to be used as the default list of types for every function in this class with a $types param. Useful to avoid repetition when calling the same functions using the same fields and types.
- getDefaults() publicReturns the currently configured types.
- getTypes() publicGets a map of fields and their associated types for single-use.
- setDefaults() public
Configures a map of default fields and their associated types to be used as the default list of types for every function in this class with a $types param. Useful to avoid repetition when calling the same functions using the same fields and types.
- setTypes() publicSets a map of fields and their associated types for single-use.
- toArray() publicReturns an array of all types mapped types
- type() public
Returns the type of the given column. If there is no single use type is configured, the column type will be looked for inside the default mapping. If neither exist, null will be returned.
- types() publicSets a map of fields and their associated types for single-use.
Method Detail
__construct()source public
__construct( array $defaults [] )
Creates an instance with the given defaults
Parameters
- array
$defaults
optional [] - The defaults to use.
addDefaults()source public
addDefaults( array $types )
Add additional default types into the type map.
If a key already exists it will not be overwritten.
Parameters
- array
$types
- The additional types to add.
defaults()source public
defaults( array $defaults null )
Configures a map of default fields and their associated types to be used as the default list of types for every function in this class with a $types param. Useful to avoid repetition when calling the same functions using the same fields and types.
If called with no arguments it will return the currently configured types.
Example
$query->defaults(['created' => 'datetime', 'is_visible' => 'boolean']);
This method will replace all the existing type maps with the ones provided.
Deprecated
3.4.0 Use setDefaults()/getDefaults() instead.Parameters
- array
$defaults
optional null associative array where keys are field names and values are the correspondent type.
Returns
$this|array
getTypes()source public
getTypes( )
Gets a map of fields and their associated types for single-use.
Returns
arraysetDefaults()source public
setDefaults( array $defaults )
Configures a map of default fields and their associated types to be used as the default list of types for every function in this class with a $types param. Useful to avoid repetition when calling the same functions using the same fields and types.
Example
$query->setDefaults(['created' => 'datetime', 'is_visible' => 'boolean']);
This method will replace all the existing type maps with the ones provided.
Parameters
- array
$defaults
Associative array where keys are field names and values are the correspondent type.
Returns
$this
setTypes()source public
setTypes( array $types )
Sets a map of fields and their associated types for single-use.
Example
$query->setTypes(['created' => 'time']);
This method will replace all the existing type maps with the ones provided.
Parameters
- array
$types
Associative array where keys are field names and values are the correspondent type.
Returns
$this
type()source public
type( string $column )
Returns the type of the given column. If there is no single use type is configured, the column type will be looked for inside the default mapping. If neither exist, null will be returned.
Parameters
- string
$column
- The type for a given column
Returns
null|stringtypes()source public
types( array $types null )
Sets a map of fields and their associated types for single-use.
If called with no arguments it will return the currently configured types.
Example
$query->types(['created' => 'time']);
This method will replace all the existing type maps with the ones provided.
Deprecated
3.4.0 Use setTypes()/getTypes() instead.Parameters
- array
$types
optional null associative array where keys are field names and values are the correspondent type.
Returns
$this|array
Properties detail
$_defaultssource
protected array
Associative array with the default fields and the related types this query might contain.
Used to avoid repetition when calling multiple functions inside this class that may require a custom type for a specific field.
$_typessource
protected array
Associative array with the fields and the related types that override defaults this query might contain
Used to avoid repetition when calling multiple functions inside this class that may require a custom type for a specific field.
[]
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.Database.TypeMap.html