W3cubDocs

/CakePHP 4.1

Class TypeMap

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

Namespace: Cake\Database

Properties summary

  • $_defaults protected
    string[]

    Associative array with the default fields and the related types this query might contain.

  • $_types protected
    string[]

    Associative array with the fields and the related types that override defaults this query might contain

Method Summary

  • __construct() public

    Creates an instance with the given defaults

  • addDefaults() public

    Add additional default types into the type map.

  • getDefaults() public

    Returns the currently configured types.

  • getTypes() public

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

  • setDefaults() public

    Configures a map of fields and associated type.

  • setTypes() public

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

  • toArray() public

    Returns 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.

Method Detail

__construct() public

__construct(array $defaults)

Creates an instance with the given defaults

Parameters

string[] $defaults optional

The defaults to use.

addDefaults() public

addDefaults(array $types)

Add additional default types into the type map.

If a key already exists it will not be overwritten.

Parameters

string[] $types

The additional types to add.

getDefaults() public

getDefaults()

Returns the currently configured types.

Returns

string[]

getTypes() public

getTypes()

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

Returns

string[]

setDefaults() public

setDefaults(array $defaults)

Configures a map of fields and associated type.

These values will be used as the default mapping of types for every function in this instance that supports a $types param.

This method is useful when you want to avoid repeating type definitions as setting types overwrites the last set of types.

Example

$query->setDefaults(['created' => 'datetime', 'is_visible' => 'boolean']);

This method will replace all the existing default mappings with the ones provided. To add into the mappings use addDefaults().

Parameters

string[] $defaults

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

Returns

$this

setTypes() 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

string[] $types

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

Returns

$this

toArray() public

toArray()

Returns an array of all types mapped types

Returns

string[]

type() public

type(mixed $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|int $column

The type for a given column

Returns

string|null

Property Detail

$_defaults protected

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

string[]

$_types protected

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

string[]

© 2005–present 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/4.1/class-Cake.Database.TypeMap.html