Skip to content
Permalink
Browse files

Add Type::set()

This method allows userland code to inject constructed instances into
the Type registry allowing userland instances to be used later via
build().

Refs #6474
  • Loading branch information...
markstory committed May 4, 2015
1 parent 7225b22 commit cef9f1cc74e0bbe8b3f5b1b0f39f1c450f0f99e3
Showing with 24 additions and 0 deletions.
  1. +12 −0 src/Database/Type.php
  2. +12 −0 tests/TestCase/Database/TypeTest.php
@@ -105,6 +105,18 @@ public static function build($name)
return static::$_builtTypes[$name] = new static::$_types[$name]($name);
}
/**
* Returns a Type object capable of converting a type identified by $name
*
* @param string $name The type identifier you want to set.
* @param \Cake\Databse\Type $type The type instance you want to set.
* @return void
*/
public static function set($name, Type $instance)
{
static::$_builtTypes[$name] = $instance;
}
/**
* Registers a new type identifier and maps it to a fully namespaced classname,
* If called with no arguments it will return current types map array
@@ -380,4 +380,16 @@ public function testDecimalToStatement()
$driver = $this->getMock('\Cake\Database\Driver');
$this->assertEquals(PDO::PARAM_STR, $type->toStatement($string, $driver));
}
/**
* Test setting instances into the factory/registry.
*
* @return void
*/
public function testSet()
{
$instance = $this->getMock('Cake\Database\Type');
Type::set('random', $instance);
$this->assertSame($instance, Type::build('random'));
}
}

0 comments on commit cef9f1c

Please sign in to comment.
You can’t perform that action at this time.