Re: plugin interface

From: Date: Wed, 10 Oct 2001 09:34:29 +0000
Subject: Re: plugin interface
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1662@lists.php.net to get a copy of this message
Monte Ohrt wrote: > We've been kicking around some ideas internally, what do you think? > > Example of a plugin function in Smarty: > > *) Plugins are not registered or preloaded. They are dropped into a > plugins directory that Smarty has access to. > *) When a function is called in a Smarty template, {myfunc x=foo y=bar}, > the following takes place: > > 1) If the function is built-in ({if ...}, {include ...}, etc.), process > function normally > 2) If a PHP function exists of the name 'smarty_func_myfunc()', use this > function Just a side note here: If it exists, it must have been included already. Then it wouldn't really be a true plugin :) But at least this means that custom functions does not need to be registered, mostly a good thing, I think. > > 3) If the file exists 'plugins/smarty_func_myfunc.php', include and use > smarty_func_myfunc() (function must be defined in here!) > 4) If none of the above exist, use built-in default function (which may > trigger error or whatever) > > PROS: > > * no need to register functions or modifiers If security doesn't suffer, then this is a good thing. > > * no need to preload functions or modifiers, they are loaded on an > as-needed basis > * no need to scan plugin directory, just grab them as needed > * Smarty size is very slim, no unused plugins are ever loaded > * most or all existing functions/modifers can be moved over to plugins > * default function handling > > CONS: > > * plugins only work with functions and modifiers, nothing fancy like > your own {myfunc}{/myfunc} kind of things > * functions that are mapped directly to php funcs must be written as a > wrapper (IMHO, this is how it should be anyways) Not a problem, as I see it. > > * must stat() plugin directory file for each plugin called in templates, > may be a performance issue? maybe we can put "core" plugins in one file > to alleviate this (leave in addons file) Personally, I could accept some minor compile time performance issues, since I almost always will test my templates (=compile them) myself. Compiled templates should only have the "include" statement compiled into them. And if you put all "core" plugins in one file, then what have we won? It's just as good/bad as the addon file today. It's all or nothing. > > > Q's: > * do we keep function/modifier registration around for backward > compatability? If so, it will be added to above steps. Keep the registration for a while, at least as dummy entries. Make it very clear in the documentation that these functions will be gone in some future version. If you decide to skip registration, that is! I really hate compatibility breakers ;) /Anders

« previous php.smarty.general (#1662) next »