document xslt_set_option()

better OO example for xslt_set_sax_handlers() using xslt_set_option()
tell xslt_set_error_handler() users to use xslt_set_option() instead of passing an array with a reference to the object


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@164722 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Mehdi Achour 2004-07-30 13:51:43 +00:00
parent 284476507c
commit dfb1b69554
3 changed files with 77 additions and 31 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<!-- $Revision: 1.4 $ -->
<!-- splitted from ./en/functions/xslt.xml, last change in rev 1.1 -->
<refentry id="function.xslt-set-error-handler">
<refnamediv>
@ -102,8 +102,8 @@ array(4) {
</example>
</para>
<para>
Instead of a function name, an array containing an object reference and
a method name can also be supplied.
See also <function>xslt_set_object</function> if you want to use an
object method as handler.
</para>
</refsect1>
</refentry>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.1 $ -->
<!-- $Revision: 1.2 $ -->
<refentry id="function.xslt-set-object">
<refnamediv>
<refname>xslt_set_object</refname>
@ -11,12 +11,55 @@
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>xslt_set_object</methodname>
<methodparam><type>resource</type><parameter>parser</parameter></methodparam>
<methodparam><type>resource</type><parameter>processor</parameter></methodparam>
<methodparam><type>object</type><parameter>obj</parameter></methodparam>
</methodsynopsis>
<para>
This function allows to use the <parameter>processor</parameter> inside
an <parameter>object</parameter> and to resolve all callback functions
in it.
</para>
<para>
The callback functions can be declared with
<function>xml_set_sax_handlers</function>,
<function>xslt_set_scheme_handlers</function> or
<function>xslt_set_error_handler</function> and are assumed to be methods
of <parameter>object</parameter>.
</para>
<para>
<example>
<title>Using your own error handler as a method</title>
<programlisting role="php">
<![CDATA[
<?php
&warn.undocumented.func;
class my_xslt_processor {
var $_xh; // our XSLT processor
function my_xslt_processor()
{
$this->_xh = xslt_create();
// Make $this object the callback resolver
xslt_set_object($this->_xh, $this);
// Let's handle the errors
xslt_set_error_handler($this->_xh, "my_xslt_error_handler");
}
function my_xslt_error_handler($handler, $errno, $level, $info)
{
// for now, let's just see the arguments
var_dump(func_get_args());
}
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- $Revision: 1.6 $ -->
<!-- splitted from ./en/functions/xslt.xml, last change in rev 1.29 -->
<refentry id='function.xslt-set-sax-handlers'>
<refnamediv>
@ -237,9 +237,8 @@ xslt_free($xh);
</example>
</para>
<para>
Every values of the <parameter>handlers</parameter> array is either a
string containing the function name, or an array in the following format:
<command>array(&amp;$obj, "method")</command>.
You can also use <function>xslt_set_object</function> if you want to
implement your handlers in an object.
</para>
<para>
<example>
@ -252,6 +251,30 @@ class data_sax_handler {
var $buffer, $tag, $attrs;
var $_xh;
function data_sax_handler($xml, $xsl)
{
// our xslt resource
$this->_xh = xslt_create();
xslt_set_object($this->_xs, $this);
// configure sax handlers
$handlers = array(
"document" => array('start_document', 'end_document'),
"element" => array('start_element', 'end_element'),
"character" => 'characters'
);
xslt_set_sax_handlers($this->_xh, $handlers);
xslt_process($this->_xh, 'arg:/_xml', 'arg:/_xsl', NULL, array("/_xml"=>$xml, "/_xsl"=>$xsl));
xslt_free($this->_xh);
}
function start_document()
{
// start reading the document
@ -287,27 +310,7 @@ class data_sax_handler {
}
// our xsl handle
$xh = xslt_create();
$handler = new data_sax_handler();
// configure sax handlers
$handlers = array(
"document" => array(
array(&$handler, 'start_document'),
array(&$handler, 'end_document')
),
"element" => array(
array(&$handler, 'start_element'),
array(&$handler, 'end_element')
),
"character" => array(&$handler, 'characters')
);
xslt_set_sax_handlers($xh, $handlers);
xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, array("/_xml"=>$xml, "/_xsl"=>$xsl));
xslt_free($xh);
$exec = new data_sax_handler($xml, $xsl);
?>
]]>