Add missing properties to xsl stub (#12334)

* Define doXInclude for XSLTProcessor, and test the property

This was added in 8d1427dd98, 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 in 5c039bbad9, 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:
Niels Dossche 2023-10-06 17:42:47 +02:00 committed by GitHub
parent 42a85fc5d9
commit 3bb56ae418
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 115 additions and 11 deletions

View file

@ -43,6 +43,8 @@ PHP 8.4 UPGRADE NOTES
. XSLTProcessor::setParameter() will now throw a ValueError when its arguments . XSLTProcessor::setParameter() will now throw a ValueError when its arguments
contain null bytes. This never actually worked correctly in the first place, contain null bytes. This never actually worked correctly in the first place,
which is why it throws an exception nowadays. which is why it throws an exception nowadays.
. The typed properties XSLTProcessor::$cloneDocument and
XSLTProcessor::$doXInclude are now declared.
======================================== ========================================
2. New Features 2. New Features

View file

@ -71,6 +71,10 @@ const LIBEXSLT_DOTTED_VERSION = UNKNOWN;
class XSLTProcessor class XSLTProcessor
{ {
public bool $doXInclude = false;
public bool $cloneDocument = false;
/** /**
* @param DOMDocument|SimpleXMLElement $stylesheet * @param DOMDocument|SimpleXMLElement $stylesheet
* @tentative-return-type * @tentative-return-type

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead. /* 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_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) 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); INIT_CLASS_ENTRY(ce, "XSLTProcessor", class_XSLTProcessor_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL); 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; return class_entry;
} }

View 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

View 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>

View 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/>

View file

@ -0,0 +1,2 @@
<?xml version="1.0"?>
<content>This is sample content</content>

View file

@ -313,11 +313,8 @@ PHP_METHOD(XSLTProcessor, importStylesheet)
intern = Z_XSL_P(id); intern = Z_XSL_P(id);
member = ZSTR_INIT_LITERAL("cloneDocument", 0); member = ZSTR_INIT_LITERAL("cloneDocument", 0);
cloneDocu = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_IS, NULL, &rv); cloneDocu = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_R, NULL, &rv);
if (Z_TYPE_P(cloneDocu) != IS_NULL) { clone_docu = zend_is_true(cloneDocu);
convert_to_long(cloneDocu);
clone_docu = Z_LVAL_P(cloneDocu);
}
zend_string_release_ex(member, 0); zend_string_release_ex(member, 0);
if (clone_docu == 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 */ /* 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); member = ZSTR_INIT_LITERAL("doXInclude", 0);
doXInclude = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_IS, NULL, &rv); doXInclude = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_R, NULL, &rv);
if (Z_TYPE_P(doXInclude) != IS_NULL) { ctxt->xinclude = zend_is_true(doXInclude);
convert_to_long(doXInclude);
ctxt->xinclude = Z_LVAL_P(doXInclude);
}
zend_string_release_ex(member, 0); zend_string_release_ex(member, 0);
secPrefsValue = intern->securityPrefs; secPrefsValue = intern->securityPrefs;