mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Add missing properties to xsl stub (#12334)
* Define doXInclude for XSLTProcessor, and test the property This was added in8d1427dd98, but never defined on the stub. It was more or less fine when dynamic properties were not deprecated, but now they throw a deprecation warning. To fix it, define on the stub. This should also help discoverability of the functionality. * Define cloneDocument for XSLTProcessor, and test the property This was introduced in5c039bbad9, but never defined on the stub. It was more or less fine when dynamic properties were not deprecated, but now they throw a deprecation warning. To fix it, define on the stub. This should also help discoverability of the functionality.
This commit is contained in:
@@ -43,6 +43,8 @@ PHP 8.4 UPGRADE NOTES
|
||||
. XSLTProcessor::setParameter() will now throw a ValueError when its arguments
|
||||
contain null bytes. This never actually worked correctly in the first place,
|
||||
which is why it throws an exception nowadays.
|
||||
. The typed properties XSLTProcessor::$cloneDocument and
|
||||
XSLTProcessor::$doXInclude are now declared.
|
||||
|
||||
========================================
|
||||
2. New Features
|
||||
|
||||
@@ -71,6 +71,10 @@ const LIBEXSLT_DOTTED_VERSION = UNKNOWN;
|
||||
|
||||
class XSLTProcessor
|
||||
{
|
||||
public bool $doXInclude = false;
|
||||
|
||||
public bool $cloneDocument = false;
|
||||
|
||||
/**
|
||||
* @param DOMDocument|SimpleXMLElement $stylesheet
|
||||
* @tentative-return-type
|
||||
|
||||
14
ext/xsl/php_xsl_arginfo.h
generated
14
ext/xsl/php_xsl_arginfo.h
generated
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 606e6ceba2381588b28e25e140fbcfec8a4dbe84 */
|
||||
* Stub hash: 5518a63a4adec49c81e650d620ce2dbce41d8d65 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XSLTProcessor_importStylesheet, 0, 1, _IS_BOOL, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, stylesheet, IS_OBJECT, 0)
|
||||
@@ -113,5 +113,17 @@ static zend_class_entry *register_class_XSLTProcessor(void)
|
||||
INIT_CLASS_ENTRY(ce, "XSLTProcessor", class_XSLTProcessor_methods);
|
||||
class_entry = zend_register_internal_class_ex(&ce, NULL);
|
||||
|
||||
zval property_doXInclude_default_value;
|
||||
ZVAL_FALSE(&property_doXInclude_default_value);
|
||||
zend_string *property_doXInclude_name = zend_string_init("doXInclude", sizeof("doXInclude") - 1, 1);
|
||||
zend_declare_typed_property(class_entry, property_doXInclude_name, &property_doXInclude_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
|
||||
zend_string_release(property_doXInclude_name);
|
||||
|
||||
zval property_cloneDocument_default_value;
|
||||
ZVAL_FALSE(&property_cloneDocument_default_value);
|
||||
zend_string *property_cloneDocument_name = zend_string_init("cloneDocument", sizeof("cloneDocument") - 1, 1);
|
||||
zend_declare_typed_property(class_entry, property_cloneDocument_name, &property_cloneDocument_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
|
||||
zend_string_release(property_cloneDocument_name);
|
||||
|
||||
return class_entry;
|
||||
}
|
||||
|
||||
45
ext/xsl/tests/cloneDocument.phpt
Normal file
45
ext/xsl/tests/cloneDocument.phpt
Normal file
@@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
cloneDocument
|
||||
--EXTENSIONS--
|
||||
xsl
|
||||
dom
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$xml = new DOMDocument;
|
||||
$xml->loadXML('<?xml version="1.0"?><root><foo>hello</foo></root>');
|
||||
|
||||
function test() {
|
||||
global $xml;
|
||||
$xml->documentElement->firstChild->textContent = "bye";
|
||||
}
|
||||
|
||||
$xsl = new DOMDocument;
|
||||
$xsl->loadXML(<<<XML
|
||||
<?xml version="1.0"?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="1.0">
|
||||
<xsl:template match="/root">
|
||||
<xsl:value-of select="php:function('test')"/>
|
||||
<xsl:value-of select="//root/foo"/>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
XML);
|
||||
|
||||
$xslt = new XSLTProcessor;
|
||||
$xslt->registerPHPFunctions();
|
||||
$xslt->cloneDocument = true;
|
||||
$xslt->importStylesheet($xsl);
|
||||
echo $xslt->transformToXml($xml);
|
||||
|
||||
$xslt = new XSLTProcessor;
|
||||
$xslt->registerPHPFunctions();
|
||||
$xslt->cloneDocument = false;
|
||||
$xslt->importStylesheet($xsl);
|
||||
echo $xslt->transformToXml($xml);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
<?xml version="1.0"?>
|
||||
hello
|
||||
<?xml version="1.0"?>
|
||||
bye
|
||||
4
ext/xsl/tests/xinclude/data.xml
Normal file
4
ext/xsl/tests/xinclude/data.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<data>
|
||||
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="xincluded.xml" parse="xml"/>
|
||||
</data>
|
||||
41
ext/xsl/tests/xinclude/xinclude.phpt
Normal file
41
ext/xsl/tests/xinclude/xinclude.phpt
Normal file
@@ -0,0 +1,41 @@
|
||||
--TEST--
|
||||
doXInclude
|
||||
--EXTENSIONS--
|
||||
xsl
|
||||
dom
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
chdir(__DIR__);
|
||||
|
||||
$xml = new DOMDocument;
|
||||
$xml->loadXML('<?xml version="1.0"?><root/>');
|
||||
|
||||
$xsl = new DOMDocument;
|
||||
$xsl->loadXML(<<<XML
|
||||
<?xml version="1.0"?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:template match="/root">
|
||||
<container>
|
||||
<xsl:value-of select="document('data.xml')/data/content"/>
|
||||
</container>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
XML);
|
||||
|
||||
$xslt = new XSLTProcessor;
|
||||
$xslt->doXInclude = true;
|
||||
$xslt->importStylesheet($xsl);
|
||||
echo $xslt->transformToXml($xml);
|
||||
|
||||
$xslt = new XSLTProcessor;
|
||||
$xslt->doXInclude = false;
|
||||
$xslt->importStylesheet($xsl);
|
||||
echo $xslt->transformToXml($xml);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
<?xml version="1.0"?>
|
||||
<container>This is sample content</container>
|
||||
<?xml version="1.0"?>
|
||||
<container/>
|
||||
2
ext/xsl/tests/xinclude/xincluded.xml
Normal file
2
ext/xsl/tests/xinclude/xincluded.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0"?>
|
||||
<content>This is sample content</content>
|
||||
@@ -313,11 +313,8 @@ PHP_METHOD(XSLTProcessor, importStylesheet)
|
||||
intern = Z_XSL_P(id);
|
||||
|
||||
member = ZSTR_INIT_LITERAL("cloneDocument", 0);
|
||||
cloneDocu = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_IS, NULL, &rv);
|
||||
if (Z_TYPE_P(cloneDocu) != IS_NULL) {
|
||||
convert_to_long(cloneDocu);
|
||||
clone_docu = Z_LVAL_P(cloneDocu);
|
||||
}
|
||||
cloneDocu = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_R, NULL, &rv);
|
||||
clone_docu = zend_is_true(cloneDocu);
|
||||
zend_string_release_ex(member, 0);
|
||||
if (clone_docu == 0) {
|
||||
/* check if the stylesheet is using xsl:key, if yes, we have to clone the document _always_ before a transformation */
|
||||
@@ -415,11 +412,8 @@ static xmlDocPtr php_xsl_apply_stylesheet(zval *id, xsl_object *intern, xsltStyl
|
||||
}
|
||||
|
||||
member = ZSTR_INIT_LITERAL("doXInclude", 0);
|
||||
doXInclude = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_IS, NULL, &rv);
|
||||
if (Z_TYPE_P(doXInclude) != IS_NULL) {
|
||||
convert_to_long(doXInclude);
|
||||
ctxt->xinclude = Z_LVAL_P(doXInclude);
|
||||
}
|
||||
doXInclude = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_R, NULL, &rv);
|
||||
ctxt->xinclude = zend_is_true(doXInclude);
|
||||
zend_string_release_ex(member, 0);
|
||||
|
||||
secPrefsValue = intern->securityPrefs;
|
||||
|
||||
Reference in New Issue
Block a user