From 173815a6b76fc7e377b0de3a747d5c322f63775f Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Mon, 23 Nov 2015 09:55:16 +0100 Subject: [PATCH] Implemented a Type::buildAll() method to cleanup This helped cleanup another part of the code --- src/Database/FieldTypeConverter.php | 3 +-- src/Database/Type.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Database/FieldTypeConverter.php b/src/Database/FieldTypeConverter.php index 07913281ed1..6dff4899eba 100644 --- a/src/Database/FieldTypeConverter.php +++ b/src/Database/FieldTypeConverter.php @@ -47,8 +47,7 @@ public function __construct(TypeMap $typeMap, Driver $driver) { $this->_driver = $driver; $map = $typeMap->toArray(); - $types = array_keys(Type::map()); - $types = array_map(['Cake\Database\Type', 'build'], array_combine($types, $types)); + $types = Type::buildAll(); $result = []; foreach ($types as $k => $type) { diff --git a/src/Database/Type.php b/src/Database/Type.php index 30d9f2fc597..f24b8704614 100644 --- a/src/Database/Type.php +++ b/src/Database/Type.php @@ -105,6 +105,20 @@ public static function build($name) return static::$_builtTypes[$name] = new static::$_types[$name]($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) { + $result[$name] = isset(static::$_builtTypes[$name]) ? static::$_builtTypes[$name] : static::build($name); + } + return $result; + } + /** * Returns a Type object capable of converting a type identified by $name *