There are two thoughts below:

Bill Karwin wrote:


// current behavior: specifying literals
$db = Zend_Db::factory('mysqli', array(...));
// current behavior: specifying values from config
$db = Zend_Db::factory($config->db->adapter,
$config->db->options->toArray());
// new behavior: factory knows how to recognize Zend_Config object
$db = Zend_Db::factory($config->db);

I talked about this with Kevin McArthur some time back actually.

I see a couple of improvement points in this area. First perhaps Zend_Db::factory().. checks to see that arg1 is of type Zend_Config. In that case, it can parse the object as such, not only looking for the type of adapter, but also the arguments. Given that php is very good at instanceof decomposition, I don't see why the following signatures wouldn't be valid for the factory:

factory(Zend_Config $config);
factory(string $type, Array $args);
factory(string $type, Zend_Config $args);

Beyond that though, I see TONS of value in creating a Zend_Db_Registry. This would allow modules to require that a named db instance exist in a STRUCTURED registry (presumably defined in a bootstrap, with default perhaps being set automatically) in order for execution of said module to work initialize. This would allow for more portable code.

For example: my blog module imposes that a db adapter key named 'blog' exist.

I would then have this in the bootstrap:

$db = Zend_Db::factory(...); // default adapter

// perhaps this is done automatically for the first call of factory?
Zend_Db_Registry::getInstance()->default = $db;

Zend_Db_Registry::getInstance()->BlogAdapter = $db;



From my perspective, a factory pattern really does lend itself well for use with a registry pattern. IMHO of course ;)

-ralph


The factory and constructor methods of individual components would need
to define some names of config elements, but this is no different and no
more difficult than defining names of keys in the $options arrays.

And I think we should make sure that no components require a Config
object.  It's a good feature that distinguishes ZF from other frameworks
that it does not require configuration files.  So anything you can
specify with a Config object must be specifiable with traditional
arguments, as in the Zend_Db::factory() example above.

Regards,
Bill Karwin


Reply via email to