I don't know if you can access that data directly from the extension
callback, but you can certainly wire it in without *too* bad a hack:
foreach( array( 'foo', 'bar', 'baz', quok' ) as $var ){
$parser->setHook( $var, "WrapperClass::myCallback_$var" );
}
class WrapperClass {
function __callStatic( $fname, $args ){
list( $junk, $var ) = explode( '_', $fname );
$args[] = $var;
return call_user_func_array( 'myCallback', $args );
}
}
function myCallback( $input, $args, $parser, $frame, $var ) {
return 'hello world';
}
It's pretty obviously a retrofitted design change, but it's fairly robust,
especially if you keep the first two bits of code together...
--HM
On 21 December 2011 15:29, Daniel Barrett <danb(a)vistaprint.com> wrote:
If I create a tag extension like this:
$parser->setHook('foobar', 'myCallback');
function myCallback($input, $args, $parser, $frame) {
return 'hello world';
}
can the callback "myCallback" efficiently detect the name of the parser
tag, "foobar", that invoked it?
The business problem is this: I use the same callback with 20 different
tag names, and I'd like the behavior to change slightly depending on which
tag name was used. (The tag names are the names of database servers in my
company, and the callback accesses the particular database.)
Right now I am using a very inefficient solution: dynamically creating 20
callbacks (one for each tag name), each with slightly customized behavior.
I'd rather do it with one callback.
I realize this would be easy if I'd used a single tag name plus a variable
argument, but it's too late to make that change. (The tags have been used
10,000 times and are widely known in our company.)
Thank you very much.
DanB
ps: I asked this a few years ago, when the answer was "no," but maybe
things have changed by now.....
_______________________________________________
Wikitech-l mailing list
Wikitech-l(a)lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l