Yesterday I started thinking about something like a component manager. My
first implementation supports:

- Class/File loading on demand (using Zend_Loader)
- Configuration in the bootstrap file without loading the classes/files (you
can specify arguments that will be passed to the constructor/a static
method, e.g. Zend_Db::factory)
- Singleton pattern possible for every component (e.g. Zend_Db)
- Dependencies (e.g. Zend_Db_Table needs a database adapter)

I'm thinking about other features like automatic caching for components like
Zend_Acl. Examples:

Bootstrap:

$component = new Zend_Components_Component('db');
$component->setClassName('Zend_Db');
$component->setMethodName('factory');
$component->setArguments(array('Pdo_Mysql', array('host' => 'myhost',
'username' => 'myusername', 'password' => 'mypassword', 'dbname' =>
'mydbname')));

$component->register();

or

$components = Zend_Components::getInstance();
$components->registerComponent($component);

Controller:

$db = Zend_Components::getInstance('db');

Bootstrap:

$options = array('className' => 'Zend_Db', 'methodName' => 'factory',
'arguments' => array('Pdo_Mysql', array('host' => 'myhost', 'username' =>
'myusername', 'password' => 'mypassword', 'dbname' => 'mydbname')));

$components = Zend_Components::getInstance();
$components->registerComponent('db', $options);

Controller:

$components = Zend_Components::getInstance();
$component = $components->getComponent('db');
$db = $component->getInstance();

Bootstrap (including one of the examples above):

class accounts extends Zend_Db_Table {}
 
$component = new Zend_Components_Component('accounts');
$component->setArguments(array(array('db' =>
array(Zend_Components_Component::DEPENDENCY, 'db'))));
$component->register();

Controller:
 
$table = Zend_Components::getInstance('accounts');

Just an example for the dependency feature. Feedback? :>
-- 
View this message in context: 
http://www.nabble.com/Component-Manager-tf4206384s16154.html#a11965335
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to