Skip to content

Commit 601be21

Browse files
PHP 8.4: Document registerPhpFunctions() changes (php#261)
* registerPhpFunctionsの翻訳 * 型名を正式化 --------- Co-authored-by: 武田 憲太郎 <[email protected]>
1 parent 473b334 commit 601be21

File tree

2 files changed

+96
-5
lines changed

2 files changed

+96
-5
lines changed

reference/dom/domxpath/registerphpfunctions.xml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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>
@@ -31,7 +31,10 @@
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>
@@ -46,6 +49,29 @@
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>

reference/xsl/xsltprocessor/registerphpfunctions.xml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 1d574504ad4c2a183f6f858694b35168af23de46 Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: 2bd9a67c8c6c5961189f868364837a5c3ba7e063 Maintainer: takagi Status: ready -->
44
<!-- Credits: mumumu -->
55
<refentry xml:id="xsltprocessor.registerphpfunctions" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>
@@ -29,8 +29,10 @@
2929
このパラメータは、XSLT からコールされる信頼できる関数のみを許可します。
3030
</para>
3131
<para>
32-
このパラメータには文字列 (関数名)
33-
あるいは関数の配列のいずれかを指定します。
32+
このパラメータは、以下のいずれかになります:
33+
<type>string</type> (関数名),
34+
関数名の <type>array</type>,
35+
関数名がキーで <type>callable</type> な値を持つ連想配列。
3436
</para>
3537
</listitem>
3638
</varlistentry>
@@ -43,6 +45,28 @@
4345
&return.void;
4446
</para>
4547
</refsect1>
48+
<refsect1 role="changelog">
49+
&reftitle.changelog;
50+
<informaltable>
51+
<tgroup cols="2">
52+
<thead>
53+
<row>
54+
<entry>&Version;</entry>
55+
<entry>&Description;</entry>
56+
</row>
57+
</thead>
58+
<tbody>
59+
<row>
60+
<entry>8.4.0</entry>
61+
<entry>
62+
<parameter>restrict</parameter> を <type>配列</type> にする際、
63+
コールバックとして <type>callable</type> を使用できるようになりました。
64+
</entry>
65+
</row>
66+
</tbody>
67+
</tgroup>
68+
</informaltable>
69+
</refsect1>
4670
<refsect1 role="examples">
4771
&reftitle.examples;
4872
<para>
@@ -93,6 +117,14 @@ echo $proc->transformToXML($xmldoc);
93117
</example>
94118
</para>
95119
</refsect1>
120+
121+
<refsect1 role="seealso">
122+
&reftitle.seealso;
123+
<simplelist>
124+
<member><methodname>DOMXPath::registerPhpFunctions</methodname></member>
125+
</simplelist>
126+
</refsect1>
127+
96128
</refentry>
97129
<!-- Keep this comment at the end of the file
98130
Local variables:

0 commit comments

Comments
 (0)