ZF-7900: Each module bootstrap creates new instance of Zend_Application_Resource_Frontcontroller to bootstrap a FrontController

Description

In Zend_Application_Module_Bootstrap __constructor() the lines below

    // ZF-6545: ensure front controller resource is loaded
    if (!$this->hasPluginResource('FrontController')) {
        $this->registerPluginResource('FrontController');
    }

ensure, that front controller plugin resource is loaded. But this causes each module to bootstrap the FrontController anew, so an instance of Zend_Application_Resource_Frontcontroller is created for each module bootstrap.

I think that module bootstrap must have access to application bootstrap resources in some way (delegation?) to be able to track dependencies on global resources and prevent such duplications.

Comments

This behavior seems questionable. I created a patch that allows the Frontcontroller resource to be reused by each module bootstrap.

http://gist.github.com/352650

This doesn't break any unit tests. However, the init() method of the Frontcontroller resource is still called 1 time per module bootstrap. This has a bizarre side effect when using resources.frontcontroller in your application.(ini|xml|php) -- each plugin is registered multiple times with the Zend_Controller_Front instance (other things are duplicated as well), and thus executed multiple times per request. However, if you don't use resources.frontcontroller, and instead use an _initFrontController() method in your bootstrap, this does not occur.

I tried forcing Frontcontroller::init() to run only once using a static variable, but this did break unit tests. I'm unsure why, and decided to take a break at this point.

Matthew do you have any insight?

Do you need a new instance of the Frontcontroller resource for every module? If not, does Frontcontroller::init() need to be called for every module? If not, why do tests break if I force it once?

Fun. :)