Fr3nch13/CakePHP Utilities

TypeMap
in package

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

Table of Contents

Properties

$_defaults  : array<int|string, string>
Array with the default fields and the related types this query might contain.
$_types  : array<int|string, string>
Array with the fields and the related types that override defaults this query might contain

Methods

__construct()  : mixed
Creates an instance with the given defaults
addDefaults()  : void
Add additional default types into the type map.
getDefaults()  : array<int|string, string>
Returns the currently configured types.
getTypes()  : array<int|string, string>
Gets a map of fields and their associated types for single-use.
setDefaults()  : $this
Configures a map of fields and associated type.
setTypes()  : $this
Sets a map of fields and their associated types for single-use.
toArray()  : array<int|string, string>
Returns an array of all types mapped types
type()  : string|null
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.

Properties

$_defaults

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

protected array<int|string, string> $_defaults = []

Used to avoid repetition when calling multiple functions inside this class that may require a custom type for a specific field.

$_types

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

protected array<int|string, string> $_types = []

Used to avoid repetition when calling multiple functions inside this class that may require a custom type for a specific field.

Methods

__construct()

Creates an instance with the given defaults

public __construct([array<int|string, string> $defaults = [] ]) : mixed
Parameters
$defaults : array<int|string, string> = []

The defaults to use.

addDefaults()

Add additional default types into the type map.

public addDefaults(array<int|string, string> $types) : void

If a key already exists it will not be overwritten.

Parameters
$types : array<int|string, string>

The additional types to add.

getDefaults()

Returns the currently configured types.

public getDefaults() : array<int|string, string>
Return values
array<int|string, string>

getTypes()

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

public getTypes() : array<int|string, string>
Return values
array<int|string, string>

setDefaults()

Configures a map of fields and associated type.

public setDefaults(array<int|string, string> $defaults) : $this

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
$defaults : array<int|string, string>

Array where keys are field names / positions and values are the correspondent type.

Return values
$this

setTypes()

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

public setTypes(array<int|string, string> $types) : $this

Example

$query->setTypes(['created' => 'time']);

This method will replace all the existing type maps with the ones provided.

Parameters
$types : array<int|string, string>

Array where keys are field names / positions and values are the correspondent type.

Return values
$this

toArray()

Returns an array of all types mapped types

public toArray() : array<int|string, string>
Return values
array<int|string, string>

type()

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.

public type(string|int $column) : string|null
Parameters
$column : string|int

The type for a given column

Return values
string|null

        
On this page

Search results