2008年11月25日星期二

Re: [fw-mvc] Register a plugin within a plugins routeShutdown() method

-- Ralf Eggert <r.eggert@travello.de> wrote
(on Tuesday, 25 November 2008, 05:36 PM +0100):
> I have a plugin called Plugin_ModuleSetup which has a routeShutdown()
> method implemented. In this method there is check if there is a plugin
> called Plugin_ModuleInit for the current module. If yes, this plugin is
> loaded and registered. This works fine for dispatchLoopStartup() method
> and all other methods that follow. But the routeShutdown() method is not
> called for this new plugin.

Right -- because it was not registered when the hook started execution.

Each of the various Plugin_Broker hook methods basically does this:

foreach ($plugins as $plugin) {
$plugin->{hook name here}(...);
}

So the plugin *must* be registered prior to the foreach call being made
if it's going to execute during execution of that hook.

> My idea is to register the module-dependent Plugin_ModuleInit in the
> frontcontroller and manually call the Plugin_ModuleInit::routeShutdown()
> method from within the Plugin_ModuleSetup::routeShutdown(). But I don't
> know if this is really good practice.
>
> Any other ideas how to solve this?

You could always move the initialization to dispatchLoopStartup() --
nothing executes between that hook and the routeShutdown() hook.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: