public factory ( $key, $factory ) |
function factory($key, $factory)
{
if ($factory instanceof Factory) {
$this->_registry[$key] = function () use($factory) {
return $factory->create();
};
} else {
if (is_callable($factory)) {
$this->_registry[$key] = $factory;
} else {
throw new RegistryException("Parameter must be a Factory or Closure");
}
}
return $this;
}
public function testRegisteringAClosureAsAFactory() { $registry = new Registry(); $registry->factory('my_key', function () { return (object) array('test' => 'blargh'); }); $this->assertTrue($registry->isRegistered('my_key')); $this->assertEquals($registry->lookup('my_key')->test, 'blargh'); }