|
|
@@ -29,7 +29,7 @@ class Type implements TypeInterface
|
|
|
* identifier is used as key and a complete namespaced class name as value
|
|
|
* representing the class that will do actual type conversions.
|
|
|
*
|
|
|
- * @var array
|
|
|
+ * @var string[]|\Cake\Database\Type[]
|
|
|
*/
|
|
|
protected static $_types = [
|
|
|
'tinyinteger' => 'Cake\Database\Type\IntegerType',
|
|
|
@@ -53,7 +53,7 @@ class Type implements TypeInterface
|
|
|
|
|
|
/**
|
|
|
* List of basic type mappings, used to avoid having to instantiate a class
|
|
|
- * for doing conversion on these
|
|
|
+ * for doing conversion on these.
|
|
|
*
|
|
|
* @var array
|
|
|
* @deprecated 3.1 All types will now use a specific class
|
|
|
@@ -68,9 +68,9 @@ class Type implements TypeInterface
|
|
|
];
|
|
|
|
|
|
/**
|
|
|
- * Contains a map of type object instances to be reused if needed
|
|
|
+ * Contains a map of type object instances to be reused if needed.
|
|
|
*
|
|
|
- * @var array
|
|
|
+ * @var \Cake\Database\Type[]
|
|
|
*/
|
|
|
protected static $_builtTypes = [];
|
|
|
|
|
|
@@ -92,7 +92,7 @@ class Type implements TypeInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns a Type object capable of converting a type identified by $name
|
|
|
+ * Returns a Type object capable of converting a type identified by name.
|
|
|
*
|
|
|
* @param string $name type identifier
|
|
|
* @throws \InvalidArgumentException If type identifier is unknown
|
|
|
@@ -114,14 +114,14 @@ class Type implements TypeInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns an arrays with all the mapped type objects, indexed by name
|
|
|
+ * Returns an arrays with all the mapped type objects, indexed by name.
|
|
|
*
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function buildAll()
|
|
|
{
|
|
|
$result = [];
|
|
|
- foreach (self::$_types as $name => $type) {
|
|
|
+ foreach (static::$_types as $name => $type) {
|
|
|
$result[$name] = isset(static::$_builtTypes[$name]) ? static::$_builtTypes[$name] : static::build($name);
|
|
|
}
|
|
|
|
|
|
@@ -145,27 +145,30 @@ class Type implements TypeInterface
|
|
|
* If called with no arguments it will return current types map array
|
|
|
* If $className is omitted it will return mapped class for $type
|
|
|
*
|
|
|
- * @param string|array|\Cake\Database\Type|null $type if string name of type to map, if array list of arrays to be mapped
|
|
|
- * @param string|null $className The classname to register.
|
|
|
- * @return array|string|null if $type is null then array with current map, if $className is null string
|
|
|
+ * Deprecated: The usage of $type as \Cake\Database\Type[] is deprecated. Please always use string[] if you pass an array
|
|
|
+ * as first argument.
|
|
|
+ *
|
|
|
+ * @param string|string[]|\Cake\Database\Type[]|null $type If string name of type to map, if array list of arrays to be mapped
|
|
|
+ * @param string|\Cake\Database\Type|null $className The classname or object instance of it to register.
|
|
|
+ * @return array|string|null If $type is null then array with current map, if $className is null string
|
|
|
* configured class name for give $type, null otherwise
|
|
|
*/
|
|
|
public static function map($type = null, $className = null)
|
|
|
{
|
|
|
if ($type === null) {
|
|
|
- return self::$_types;
|
|
|
+ return static::$_types;
|
|
|
}
|
|
|
if (is_array($type)) {
|
|
|
- self::$_types = $type;
|
|
|
+ static::$_types = $type;
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
if ($className === null) {
|
|
|
- return isset(self::$_types[$type]) ? self::$_types[$type] : null;
|
|
|
+ return isset(static::$_types[$type]) ? static::$_types[$type] : null;
|
|
|
}
|
|
|
|
|
|
- self::$_types[$type] = $className;
|
|
|
- unset(self::$_builtTypes[$type]);
|
|
|
+ static::$_types[$type] = $className;
|
|
|
+ unset(static::$_builtTypes[$type]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -175,8 +178,8 @@ class Type implements TypeInterface
|
|
|
*/
|
|
|
public static function clear()
|
|
|
{
|
|
|
- self::$_types = [];
|
|
|
- self::$_builtTypes = [];
|
|
|
+ static::$_types = [];
|
|
|
+ static::$_builtTypes = [];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -206,8 +209,8 @@ class Type implements TypeInterface
|
|
|
/**
|
|
|
* Casts given value from a database type to PHP equivalent
|
|
|
*
|
|
|
- * @param mixed $value value to be converted to PHP equivalent
|
|
|
- * @param \Cake\Database\Driver $driver object from which database preferences and configuration will be extracted
|
|
|
+ * @param mixed $value Value to be converted to PHP equivalent
|
|
|
+ * @param \Cake\Database\Driver $driver Object from which database preferences and configuration will be extracted
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public function toPHP($value, Driver $driver)
|
|
|
@@ -219,7 +222,7 @@ class Type implements TypeInterface
|
|
|
* Checks whether this type is a basic one and can be converted using a callback
|
|
|
* If it is, returns converted value
|
|
|
*
|
|
|
- * @param mixed $value value to be converted to PHP equivalent
|
|
|
+ * @param mixed $value Value to be converted to PHP equivalent
|
|
|
* @return mixed
|
|
|
* @deprecated 3.1 All types should now be a specific class
|
|
|
*/
|
|
|
@@ -229,8 +232,8 @@ class Type implements TypeInterface
|
|
|
if ($value === null) {
|
|
|
return null;
|
|
|
}
|
|
|
- if (!empty(self::$_basicTypes[$this->_name])) {
|
|
|
- $typeInfo = self::$_basicTypes[$this->_name];
|
|
|
+ if (!empty(static::$_basicTypes[$this->_name])) {
|
|
|
+ $typeInfo = static::$_basicTypes[$this->_name];
|
|
|
if (isset($typeInfo['callback'])) {
|
|
|
return $typeInfo['callback']($value);
|
|
|
}
|
|
|
@@ -304,4 +307,17 @@ class Type implements TypeInterface
|
|
|
{
|
|
|
return $this->_basicTypeCast($value);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns an array that can be used to describe the internal state of this
|
|
|
+ * object.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function __debugInfo()
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ 'name' => $this->_name,
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|