thekid/rfc — Issue #104: RFC 0104: PHP callback from XSLT
Author: thekid
Created: 2011-10-09 15:07:16+00:00
State: closed
Labels: implemented, rfc

Scope of Change
====
Enable callbacks to PHP functions from within XSL through the
php:function() callback supplied by PHP 5.

Rationale
====
Sometimes complex functionality can be (more) easily calculated with
PHP rather than with XSL. Even more, sometimes results depend on huge
amount of information that would need to be transferred into XML to
be available in the XSL transformation.

Having callbacks eases complex calculations and circumvents the need to
have large data serialized (bloated) into XML.

Functionality
====
The DomXSLProcessor will have a method registerInstance() where a
PHP object instance can be registered under a defined name:

```php
registerInstance('context', $myContext);
// ...
?>
```

From within XSL one can call the an invoke method which takes
define name, method name and method arguments and invokes the
given method in a non-static context:

```

```

This invokation translates into the PHP function call on a method hasPermission() with the
argument "view" on the object formerly registered as "context". The method _must_ have
the annotation @xslmethod:

```php

```

Security considerations
====
As every callable method must be explicitely annotated fine grained control
over methods that can be called is achieved and thus good security.

Speed impact
====
When not using the callback, there's no impact. When using it, there's a negative
impact through the context switch from XSL to PHP which is believed to be more
than equalized by the advantage of faster calculations in PHP and the removal of
lots of XML nodes in the tree.

Dependencies
====
n/a

Related documents
====
- http://xp-framework.net/rfc/contrib/rfc0104.diff

Comments
====
- kiesel, Thu Dec 28 19:52:56 CET 2006
We could also just allow every PHP method to be called, simplifying this
callback issue. But, then we have no control over what is called.

- friebe, Fri Dec 29 11:18:39 2006
Why is the annotation named "xml"callback while it actually is a callback
from the XSL processor - shouldn't it be called "xsl"callback?

- kiesel, Fri Dec 29 11:34:53 CET 2006
I don't like the word callback, so the annotation's name was changed to
"xslmethod".

- kiesel, Fri Dec 29 14:26:38 CET 2006
Changed RFC to simplify using existing objects within XSL, does not longer
use special facades.
Patch was updated.

- kiesel, Fri Dec 29 14:27:49 CET 2006
Now, through callback functions there can be all kinds of exceptions. Should
they be caught and re-wrapped in a TransformerException?