-- Guillaume ORIOL <[email protected]> wrote
(on Wednesday, 16 December 2009, 11:18 PM +0100):
> Thank you Matthew but I don't understand your last remark.
> 
> Let's say I have two modules, each of which has its own plugin
> registered at bootstrap:
> class Default_Bootstrap extends Zend_Application_Module_Bootstrap
> {
>     public function _initPlugin()
>     {
>         $plugin = new Plugin_Foo();
>         $front = Zend_Controller_Front::getInstance();
>         $front->registerPlugin($plugin);
>     }
> }
> 
> class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
> {
>     public function _initPlugin()
>     {
>         $plugin = new Admin_Plugin_Bar();
>         $front = Zend_Controller_Front::getInstance();
>         $front->registerPlugin($plugin);
>     }
> }
> 
> If I perform a request on the default module, both plugins are executed.
> According to your last remark, I thought only one plugin should have
> bee executed.

Yes, both will be executed -- but within your plugin logic, assuming the
plugin is in a hook later than routeStartup(), you can test for the
module and exit early if it doesn't match:

    class Admin_Plugin_Bar extends Zend_Controller_Plugin_Abstract
    {
        public function _routeShutdown(Zend_Controller_Request_Abstract 
$request)
        {
            if ($request->getModuleName() !== 'admin') {
                return;
            }

            // ... plugin logic ...
        }
    }


> Guillaume
> 
> Le 16/12/09 21:54, Matthew Weier O'Phinney a écrit :
> >-- Guillaume ORIOL<[email protected]>  wrote
> >(on Wednesday, 16 December 2009, 09:33 PM +0100):
> >>I wonder why, in a modular application, all module bootstraps are
> >>executed during initialization and not only the one corresponding to
> >>the matched module?
> >>
> >>What would be the way to get only one of them executed (I would like
> >>to connect a different plugin to each module)?
> >All module bootstraps are executed... because at bootstrap time, the
> >requested module is not yet known. (It happens during _routing_.)
> >
> >Module bootstraps should be used for:
> >
> >  * Setting up autoloading of module resources (happens already,
> >    automatically)
> >
> >  * Performing any module-specific tasks that need to happen on every
> >    request
> >
> >  * Registering module-specific plugins
> >
> >This latter area is where you should execute code that should only be
> >executed if the module is the one requested.
> 
> 

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to