-- David Mintz <vtbludg...@gmail.com> wrote (on Thursday, 11 June 2009, 02:30 PM -0400): > On Thu, Jun 11, 2009 at 4:40 AM, Jurian Sluiman <subscr...@juriansluiman.nl> > wrote: > > Op Thursday 11 June 2009 02:23:08 schreef Michael Depetrillo: > > > I figured it out. > > > > $front = Zend_Controller_Front::getInstance(); > > $db = $front->getParam('bootstrap')->getResource('db'); > > > > Michael DePetrillo > > the...@michaeldepetrillo.com > > Mobile: (858) 761-1605 > > www.michaeldepetrillo.com > > > > On Wed, Jun 10, 2009 at 5:13 PM, Michael Depetrillo <klass...@gmail.com> > wrote: > > > What is the best way to access bootstrap object from a controller > plugin? > > > > > > Or even more simple: > $this->getInvokeArg('bootstrap')->getResource('myResource'); > > > In case of the db, you could better use the > Zend_Db_Table::getDefaultAdapter() method and in some cases for resources > it's much easier to load them into the (global!) Zend_Registry :) > > > > Which brings me to a general question. What are the relative merits of doing > $this->getInvokeArg('bootstrap')->getResource('myResource') versus storing > things in good old Zend_Registry?
Global, static registries are a pain to test against. I've discovered this the hard way in maintaining Zend_Controller, creating Zend_Test_PHPUnit_ControllerTestCase, and other functionality. Ask any testing bigot, and you'll get the same answer: singletons are the bane of testing. Singletons make it hard to determine when and where dependencies are initialized, and also force you to do a bunch of acrobatics to reset them between tests. Most of the ControllerTestCase would be unnecessary if we did not use singletons within the framework, and the Zend_Controller suite would be tons easier to test and maintain as well. Local registries and dependency injection, however, are very easy to test, and provide for a lot of flexibility in implementation. To this end, I made Zend_Application utilize a local registry and inject it into the front controller. This will make it easier in the future to wean away from static registries (and also make it trivial to remove the singleton from Z_C_F). -- Matthew Weier O'Phinney Project Lead | matt...@zend.com Zend Framework | http://framework.zend.com/