plugin interface
| From: | Monte Ohrt | Date: | Tue, 09 Oct 2001 15:36:44 +0000 |
| Subject: | plugin interface | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1648@lists.php.net to get a copy of this message | ||
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
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
* 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)
* 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)
Q's:
* do we keep function/modifier registration around for backward
compatability? If so, it will be added to above steps.
* how does this affect template security?
Monte