Class TypeMap
Implements default and single-use mappings for columns to their associated types
Property Summary
- 
        $_defaults protectedarray<int|string, string>Array with the default fields and the related types this query might contain. 
- 
        $_types protectedarray<int|string, string>Array with the fields and the related types that override defaults this query might contain 
Method Summary
- 
          __construct() publicCreates an instance with the given defaults 
- 
          addDefaults() publicAdd additional default types into the type map. 
- 
          getDefaults() publicReturns the currently configured types. 
- 
          getTypes() publicGets a map of fields and their associated types for single-use. 
- 
          setDefaults() publicConfigures a map of fields and associated type. 
- 
          setTypes() publicSets a map of fields and their associated types for single-use. 
- 
          toArray() publicReturns an array of all types mapped types 
- 
          type() publicReturns 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<int|string, string> $defaults = [])Creates an instance with the given defaults
Parameters
- 
                array<int|string, string>$defaults optional
- The defaults to use. 
addDefaults() ¶ public
addDefaults(array<int|string, string> $types): voidAdd additional default types into the type map.
If a key already exists it will not be overwritten.
Parameters
- 
                array<int|string, string>$types
- The additional types to add. 
Returns
voidgetDefaults() ¶ public
getDefaults(): array<int|string, string>Returns the currently configured types.
Returns
array<int|string, string>getTypes() ¶ public
getTypes(): array<int|string, string>Gets a map of fields and their associated types for single-use.
Returns
array<int|string, string>setDefaults() ¶ public
setDefaults(array<int|string, string> $defaults): $thisConfigures 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
- 
                array<int|string, string>$defaults
- Array where keys are field names / positions and values are the correspondent type. 
Returns
$thissetTypes() ¶ public
setTypes(array<int|string, string> $types): $thisSets 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<int|string, string>$types
- Array where keys are field names / positions and values are the correspondent type. 
Returns
$thistoArray() ¶ public
toArray(): array<int|string, string>Returns an array of all types mapped types
Returns
array<int|string, string>type() ¶ public
type(string|int $column): string|nullReturns 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|nullProperty Detail
$_defaults ¶ protected
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<int|string, string>$_types ¶ protected
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<int|string, string>