[dev] Hooks config change proposal

Chuck Hagenbuch chuck at horde.org
Sun Jul 26 15:19:44 UTC 2009


Quoting Michael M Slusarz <slusarz at horde.org>:

> For hooks, what about changing the config file to a class.  So an  
> app's config file would look like:
>
> class App_Hooks
> {
>     // Example Hook
>     // static public function hook_name
>     // {
>     // }
> }
>
> Then Horde::callHook() just needs to include the config file and do  
> a method_exists check.  This would get rid of the function_exists()  
> calls that litter hooks.php, gets rid of the static $_hooksLoaded  
> variable in Horde::callHook (we can rely on require_once instead, or  
> configure Autoloader to look for *_Hooks classes in the config  
> directory), and would also get rid of the need to have a config  
> entry to activate the hooks.  IMHO, defining the hook in the  
> hooks.php file should be sufficient to activate.

I agree. One request: make the methods instance methods (not static)  
and create an instance of the App_Hooks class to use it. I haven't  
quite figured it out yet, but this could let us do some interesting  
things for making a config-like class using PHP 5.3's closures.  
Something like:

class Imp_Hooks
{
     public $hook_name = new Hook_Strategy_Awesome();
}

that doesn't parse, but we could have a Horde_Application_Hooks base  
class that translated strings into callable variables.

That would allow people to distribute classes that implemented a hook,  
while keeping the main body of code out of the config file.

-chuck


More information about the dev mailing list