\Cake\DatabaseTypeMap

Implements default and single-use mappings for columns to their associated types

Summary

Methods
Properties
Constants
__construct()
setDefaults()
getDefaults()
defaults()
addDefaults()
setTypes()
getTypes()
types()
type()
toArray()
No public properties found
No constants found
No protected methods found
$_defaults
$_types
N/A
No private methods found
No private properties found
N/A

Properties

$_defaults

$_defaults : 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.

Type

array

$_types

$_types : 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.

Type

array

Methods

__construct()

__construct(array  $defaults = array()) 

Creates an instance with the given defaults

Parameters

array $defaults

The defaults to use.

setDefaults()

setDefaults(array  $defaults) : $this

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

getDefaults()

getDefaults() : array

Returns the currently configured types.

Returns

array

defaults()

defaults(array|null  $defaults = null) : $this|array

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.

Parameters

array|null $defaults

associative array where keys are field names and values are the correspondent type.

Returns

$this|array

addDefaults()

addDefaults(array  $types) : void

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.

setTypes()

setTypes(array  $types) : $this

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

getTypes()

getTypes() : array

Gets a map of fields and their associated types for single-use.

Returns

array

types()

types(array|null  $types = null) : $this|array

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.

Parameters

array|null $types

associative array where keys are field names and values are the correspondent type.

Returns

$this|array

type()

type(string  $column) : null|string

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|string

toArray()

toArray() : array

Returns an array of all types mapped types

Returns

array