Skip to content

Commit

Permalink
Implemented a Type::buildAll() method to cleanup
Browse files Browse the repository at this point in the history
This helped cleanup another part of the code
  • Loading branch information
lorenzo committed Nov 23, 2015
1 parent bff580d commit 173815a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Database/FieldTypeConverter.php
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/Database/Type.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 173815a

Please sign in to comment.