11<?xml version =" 1.0" encoding =" utf-8" ?>
22<!-- $Revision$ -->
3- <!-- EN-Revision: 4f5e2b22575131fa5e9c3004b1c874e1acb06573 Maintainer: takagi Status: ready -->
3+ <!-- EN-Revision: 2bd9a67c8c6c5961189f868364837a5c3ba7e063 Maintainer: takagi Status: ready -->
44
55<refentry xml : id =" domxpath.registerphpfunctions" xmlns =" http://docbook.org/ns/docbook" xmlns : xlink =" http://www.w3.org/1999/xlink" >
66 <refnamediv >
3131 このパラメータを使って、特定の関数のみを XPath からコールできるように制限することができます。
3232 </para >
3333 <para >
34- このパラメータには、文字列 (関数名) あるいは関数名の配列を指定します。
34+ このパラメータは、以下のいずれかになります:
35+ <type >string</type > (関数名),
36+ 関数名の <type >array</type >,
37+ 関数名がキーで <type >callable</type > な値を持つ連想配列。
3538 </para >
3639 </listitem >
3740 </varlistentry >
4649 </para >
4750 </refsect1 >
4851
52+ <refsect1 role =" changelog" >
53+ &reftitle.changelog;
54+ <informaltable >
55+ <tgroup cols =" 2" >
56+ <thead >
57+ <row >
58+ <entry >&Version; </entry >
59+ <entry >&Description; </entry >
60+ </row >
61+ </thead >
62+ <tbody >
63+ <row >
64+ <entry >8.4.0</entry >
65+ <entry >
66+ <parameter >restrict</parameter > を <type >配列</type > にする際、
67+ コールバックとして <type >callable</type > を使用できるようになりました。
68+ </entry >
69+ </row >
70+ </tbody >
71+ </tgroup >
72+ </informaltable >
73+ </refsect1 >
74+
4975 <refsect1 role =" examples" >
5076 &reftitle.examples;
5177 <para >
@@ -145,6 +171,38 @@ foreach ($books as $book) {
145171 echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n";
146172}
147173
174+ ?>
175+ ]]>
176+ </programlisting >
177+ &example.outputs.similar;
178+ <screen >
179+ <![CDATA[
180+ Books with multiple authors:
181+ PHP Basics
182+ ]]>
183+ </screen >
184+ </example >
185+ </para >
186+ <para >
187+ <example >
188+ <title ><methodname >DOMXPath::registerPHPFunctions</methodname > with a <type >callable</type ></title >
189+ <programlisting role =" php" >
190+ <![CDATA[
191+ <?php
192+ $doc = new DOMDocument;
193+ $doc->load('book.xml');
194+ $xpath = new DOMXPath($doc);
195+ // 名前空間 php: を登録します (必須)
196+ $xpath->registerNamespace("php", "http://php.net/xpath");
197+ // PHP の関数を登録します (has_multiple 限定)
198+ $xpath->registerPHPFunctions(["has_multiple" => fn ($nodes) => count($nodes) > 1]);
199+ // 複数の author がいる book のみを取り出します
200+ $books = $xpath->query('//book[php:function("has_multiple", author)]');
201+ echo "Books with multiple authors:\n";
202+ foreach ($books as $book) {
203+ echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n";
204+ }
205+
148206?>
149207]]>
150208 </programlisting >
@@ -166,6 +224,7 @@ PHP Basics
166224 <member ><methodname >DOMXPath::registerNamespace</methodname ></member >
167225 <member ><methodname >DOMXPath::query</methodname ></member >
168226 <member ><methodname >DOMXPath::evaluate</methodname ></member >
227+ <member ><methodname >XSLTProcessor::registerPHPFunctions</methodname ></member >
169228 </simplelist >
170229 </para >
171230 </refsect1 >
0 commit comments