Skip to content

Add missing properties to xsl stub #12334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ext/xsl/php_xsl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@

class XSLTProcessor
{
public bool $doXInclude = false;

public bool $cloneDocument = false;

/**
* @param DOMDocument|SimpleXMLElement $stylesheet
* @tentative-return-type
Expand Down
14 changes: 13 additions & 1 deletion ext/xsl/php_xsl_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions ext/xsl/tests/cloneDocument.phpt
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions ext/xsl/tests/xinclude/data.xml
Original file line number Diff line number Diff line change
@@ -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 changes: 41 additions & 0 deletions ext/xsl/tests/xinclude/xinclude.phpt
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions ext/xsl/tests/xinclude/xincluded.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<content>This is sample content</content>
14 changes: 4 additions & 10 deletions ext/xsl/xsltprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down