Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions reference/dom/domxpath/registerphpfunctions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
Use this parameter to only allow certain functions to be called from XPath.
</para>
<para>
This parameter can be either a <type>string</type> (a function name) or
an <type>array</type> of function names.
This parameter can be one of the following:
a <type>string</type> (a function name),
an indexed <type>array</type> of function names,
or an associative <type>array</type> with keys being the function name
and the associated value being the <type>callable</type>.
</para>
</listitem>
</varlistentry>
Expand All @@ -45,6 +48,30 @@
</para>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
It is now possible to use <type>callable</type>s for callbacks
when using <parameter>restrict</parameter> with <type>array</type>
entries.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
Expand Down Expand Up @@ -144,6 +171,43 @@ foreach ($books as $book) {
echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n";
}

?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Books with multiple authors:
PHP Basics
]]>
</screen>
</example>
</para>
<para>
<example>
<title><methodname>DOMXPath::registerPHPFunctions</methodname> with a <type>callable</type></title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DOMDocument;
$doc->load('book.xml');

$xpath = new DOMXPath($doc);

// Register the php: namespace (required)
$xpath->registerNamespace("php", "http://php.net/xpath");

// Register PHP functions (has_multiple only)
$xpath->registerPHPFunctions(["has_multiple" => fn ($nodes) => count($nodes) > 1]);

// Filter books with multiple authors
$books = $xpath->query('//book[php:function("has_multiple", author)]');

echo "Books with multiple authors:\n";
foreach ($books as $book) {
echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n";
}

?>
]]>
</programlisting>
Expand All @@ -157,14 +221,15 @@ PHP Basics
</example>
</para>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>DOMXPath::registerNamespace</methodname></member>
<member><methodname>DOMXPath::query</methodname></member>
<member><methodname>DOMXPath::evaluate</methodname></member>
<member><methodname>XSLTProcessor::registerPHPFunctions</methodname></member>
</simplelist>
</para>
</refsect1>
Expand Down
41 changes: 39 additions & 2 deletions reference/xsl/xsltprocessor/registerphpfunctions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,49 @@
XSLT.
</para>
<para>
This parameter can be either a string (a function name) or an array of
functions.
This parameter can be one of the following:
a <type>string</type> (a function name),
an indexed <type>array</type> of function names,
or an associative <type>array</type> with keys being the function name
and the associated value being the <type>callable</type>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.void;
</para>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
It is now possible to use <type>callable</type>s for callbacks
when using <parameter>restrict</parameter> with <type>array</type>
entries.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
Expand Down Expand Up @@ -92,6 +121,14 @@ echo $proc->transformToXML($xmldoc);
</example>
</para>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>DOMXPath::registerPhpFunctions</methodname></member>
</simplelist>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
Expand Down