1
1
<?xml version =" 1.0" encoding =" utf-8" ?>
2
2
<!-- $Revision$ -->
3
- <!-- EN-Revision: 4f5e2b22575131fa5e9c3004b1c874e1acb06573 Maintainer: takagi Status: ready -->
3
+ <!-- EN-Revision: 2bd9a67c8c6c5961189f868364837a5c3ba7e063 Maintainer: takagi Status: ready -->
4
4
5
5
<refentry xml : id =" domxpath.registerphpfunctions" xmlns =" http://docbook.org/ns/docbook" xmlns : xlink =" http://www.w3.org/1999/xlink" >
6
6
<refnamediv >
31
31
このパラメータを使って、特定の関数のみを XPath からコールできるように制限することができます。
32
32
</para >
33
33
<para >
34
- このパラメータには、文字列 (関数名) あるいは関数名の配列を指定します。
34
+ このパラメータは、以下のいずれかになります:
35
+ <type >string</type > (関数名),
36
+ 関数名の <type >array</type >,
37
+ 関数名がキーで <type >callable</type > な値を持つ連想配列。
35
38
</para >
36
39
</listitem >
37
40
</varlistentry >
46
49
</para >
47
50
</refsect1 >
48
51
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
+
49
75
<refsect1 role =" examples" >
50
76
&reftitle.examples;
51
77
<para >
@@ -145,6 +171,38 @@ foreach ($books as $book) {
145
171
echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n";
146
172
}
147
173
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
+
148
206
?>
149
207
]]>
150
208
</programlisting >
@@ -166,6 +224,7 @@ PHP Basics
166
224
<member ><methodname >DOMXPath::registerNamespace</methodname ></member >
167
225
<member ><methodname >DOMXPath::query</methodname ></member >
168
226
<member ><methodname >DOMXPath::evaluate</methodname ></member >
227
+ <member ><methodname >XSLTProcessor::registerPHPFunctions</methodname ></member >
169
228
</simplelist >
170
229
</para >
171
230
</refsect1 >
0 commit comments