TypeFactory
in package
Factory for building database type classes.
Table of Contents
Properties
- $_builtTypes : array<string|int, TypeInterface>
- Contains a map of type object instances to be reused if needed.
- $_types : array<string, string>
- List of supported database types. A human readable identifier is used as key and a complete namespaced class name as value representing the class that will do actual type conversions.
Methods
- build() : TypeInterface
- Returns a Type object capable of converting a type identified by name.
- buildAll() : array<string|int, TypeInterface>
- Returns an arrays with all the mapped type objects, indexed by name.
- clear() : void
- Clears out all created instances and mapped types classes, useful for testing
- getMap() : array<string|int, string>|string|null
- Get mapped class name for given type or map array.
- map() : void
- Registers a new type identifier and maps it to a fully namespaced classname.
- set() : void
- Set TypeInterface instance capable of converting a type identified by $name
- setMap() : void
- Set type to classname mapping.
Properties
$_builtTypes
Contains a map of type object instances to be reused if needed.
protected
static array<string|int, TypeInterface>
$_builtTypes
= []
$_types
List of supported database types. A human readable identifier is used as key and a complete namespaced class name as value representing the class that will do actual type conversions.
protected
static array<string, string>
$_types
= ['tinyinteger' => \Cake\Database\Type\IntegerType::class, 'smallinteger' => \Cake\Database\Type\IntegerType::class, 'integer' => \Cake\Database\Type\IntegerType::class, 'biginteger' => \Cake\Database\Type\IntegerType::class, 'binary' => \Cake\Database\Type\BinaryType::class, 'binaryuuid' => \Cake\Database\Type\BinaryUuidType::class, 'boolean' => \Cake\Database\Type\BoolType::class, 'date' => \Cake\Database\Type\DateType::class, 'datetime' => \Cake\Database\Type\DateTimeType::class, 'datetimefractional' => \Cake\Database\Type\DateTimeFractionalType::class, 'decimal' => \Cake\Database\Type\DecimalType::class, 'float' => \Cake\Database\Type\FloatType::class, 'json' => \Cake\Database\Type\JsonType::class, 'string' => \Cake\Database\Type\StringType::class, 'char' => \Cake\Database\Type\StringType::class, 'text' => \Cake\Database\Type\StringType::class, 'time' => \Cake\Database\Type\TimeType::class, 'timestamp' => \Cake\Database\Type\DateTimeType::class, 'timestampfractional' => \Cake\Database\Type\DateTimeFractionalType::class, 'timestamptimezone' => \Cake\Database\Type\DateTimeTimezoneType::class, 'uuid' => \Cake\Database\Type\UuidType::class]
Tags
Methods
build()
Returns a Type object capable of converting a type identified by name.
public
static build(string $name) : TypeInterface
Parameters
- $name : string
-
type identifier
Tags
Return values
TypeInterfacebuildAll()
Returns an arrays with all the mapped type objects, indexed by name.
public
static buildAll() : array<string|int, TypeInterface>
Return values
array<string|int, TypeInterface>clear()
Clears out all created instances and mapped types classes, useful for testing
public
static clear() : void
getMap()
Get mapped class name for given type or map array.
public
static getMap([string|null $type = null ]) : array<string|int, string>|string|null
Parameters
- $type : string|null = null
-
Type name to get mapped class for or null to get map array.
Return values
array<string|int, string>|string|null —Configured class name for given $type or map array.
map()
Registers a new type identifier and maps it to a fully namespaced classname.
public
static map(string $type, string $className) : void
Parameters
- $type : string
-
Name of type to map.
- $className : string
-
The classname to register.
Tags
set()
Set TypeInterface instance capable of converting a type identified by $name
public
static set(string $name, TypeInterface $instance) : void
Parameters
- $name : string
-
The type identifier you want to set.
- $instance : TypeInterface
-
The type instance you want to set.
setMap()
Set type to classname mapping.
public
static setMap(array<string|int, string> $map) : void
Parameters
- $map : array<string|int, string>
-
List of types to be mapped.