Browse Source

Implemented a Type::buildAll() method to cleanup

This helped cleanup another part of the code
Jose Lorenzo Rodriguez 10 years ago
parent
commit
173815a6b7
2 changed files with 15 additions and 2 deletions
  1. 1 2
      src/Database/FieldTypeConverter.php
  2. 14 0
      src/Database/Type.php

+ 1 - 2
src/Database/FieldTypeConverter.php

@@ -47,8 +47,7 @@ class FieldTypeConverter
     {
         $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) {

+ 14 - 0
src/Database/Type.php

@@ -106,6 +106,20 @@ class Type
     }
 
     /**
+     * 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
      *
      * @param string $name The type identifier you want to set.