From ac733a2b6ff4b446e232818c52563cf7a1d9b03a Mon Sep 17 00:00:00 2001 From: "SUMIDA, Ippei" Date: Mon, 10 Feb 2025 16:05:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?registerPhpFunctions=E3=81=AE=E7=BF=BB?= =?UTF-8?q?=E8=A8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dom/domxpath/registerphpfunctions.xml | 63 ++++++++++++++++++- .../xsltprocessor/registerphpfunctions.xml | 38 ++++++++++- 2 files changed, 96 insertions(+), 5 deletions(-) diff --git a/reference/dom/domxpath/registerphpfunctions.xml b/reference/dom/domxpath/registerphpfunctions.xml index f93263b637..2da0076cd9 100644 --- a/reference/dom/domxpath/registerphpfunctions.xml +++ b/reference/dom/domxpath/registerphpfunctions.xml @@ -1,6 +1,6 @@ - + @@ -31,7 +31,10 @@ このパラメータを使って、特定の関数のみを XPath からコールできるように制限することができます。 - このパラメータには、文字列 (関数名) あるいは関数名の配列を指定します。 + このパラメータは、以下のいずれかになります: + 文字列 (関数名), + 関数名の 配列, + 関数名がキーで callable な値を持つ連想配列。 @@ -46,6 +49,29 @@ + + &reftitle.changelog; + + + + + &Version; + &Description; + + + + + 8.4.0 + + restrict配列 にする際、 + コールバックとして callable を使用できるようになりました。 + + + + + + + &reftitle.examples; @@ -145,6 +171,38 @@ foreach ($books as $book) { echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n"; } +?> +]]> + + &example.outputs.similar; + + + + + + + + <methodname>DOMXPath::registerPHPFunctions</methodname> with a <type>callable</type> + + load('book.xml'); +$xpath = new DOMXPath($doc); +// 名前空間 php: を登録します (必須) +$xpath->registerNamespace("php", "http://php.net/xpath"); +// PHP の関数を登録します (has_multiple 限定) +$xpath->registerPHPFunctions(["has_multiple" => fn ($nodes) => count($nodes) > 1]); +// 複数の author がいる book のみを取り出します +$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"; +} + ?> ]]> @@ -166,6 +224,7 @@ PHP Basics DOMXPath::registerNamespace DOMXPath::query DOMXPath::evaluate + XSLTProcessor::registerPHPFunctions diff --git a/reference/xsl/xsltprocessor/registerphpfunctions.xml b/reference/xsl/xsltprocessor/registerphpfunctions.xml index 2613586975..17aeef9d59 100644 --- a/reference/xsl/xsltprocessor/registerphpfunctions.xml +++ b/reference/xsl/xsltprocessor/registerphpfunctions.xml @@ -1,6 +1,6 @@ - + @@ -29,8 +29,10 @@ このパラメータは、XSLT からコールされる信頼できる関数のみを許可します。 - このパラメータには文字列 (関数名) - あるいは関数の配列のいずれかを指定します。 + このパラメータは、以下のいずれかになります: + 文字列 (関数名), + 関数名の 配列, + 関数名がキーで callable な値を持つ連想配列。 @@ -43,6 +45,28 @@ &return.void; + + &reftitle.changelog; + + + + + &Version; + &Description; + + + + + 8.4.0 + + restrict配列 にする際、 + コールバックとして callable を使用できるようになりました。 + + + + + + &reftitle.examples; @@ -93,6 +117,14 @@ echo $proc->transformToXML($xmldoc); + + + &reftitle.seealso; + + DOMXPath::registerPhpFunctions + + +