Skip to content

Commit 900919d

Browse files
committed
Perform some maintenance work in XSL
1 parent 534c343 commit 900919d

File tree

4 files changed

+172
-87
lines changed

4 files changed

+172
-87
lines changed

ext/xsl/php_xsl.stub.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
class XSLTProcessor
4+
{
5+
/** @return bool */
6+
public function importStylesheet(object $stylesheet) {}
7+
8+
/** @return DOMDocument|false */
9+
public function transformToDoc(DOMNode $document, ?string $return_class = null) {}
10+
11+
/**
12+
* @param DOMDocument|SimpleXMLElement $document
13+
* @return int
14+
*/
15+
public function transformToUri($document, string $uri) {}
16+
17+
/**
18+
* @param DOMDocument|SimpleXMLElement $document
19+
* @return string|false|null
20+
*/
21+
public function transformToXml($document) {}
22+
23+
/**
24+
* @param string|array $name
25+
* @return bool|null
26+
*/
27+
public function setParameter(string $namespace, $name, string $value = UNKNOWN) {}
28+
29+
/** @return string|false */
30+
public function getParameter(string $namespace, string $name) {}
31+
32+
/** @return bool */
33+
public function removeParameter(string $namespace, string $name) {}
34+
35+
/** @return bool */
36+
public function hasExsltSupport() {}
37+
38+
/**
39+
* @param string|array $restrict
40+
* @return void
41+
*/
42+
public function registerPHPFunctions($restrict) {}
43+
44+
/** @return bool */
45+
public function setProfiling(?string $filename) {}
46+
47+
/** @return int */
48+
public function setSecurityPrefs(int $securityPrefs) {}
49+
50+
/** @return int */
51+
public function getSecurityPrefs() {}
52+
}
53+
54+
function xsl_xsltprocessor_import_stylesheet(object $stylesheet): bool {}
55+
56+
function xsl_xsltprocessor_transform_to_doc(DOMNode $document, ?string $return_class = null): DOMDocument|false {}
57+
58+
/** @param DOMDocument|SimpleXMLElement $document */
59+
function xsl_xsltprocessor_transform_to_uri($document, string $uri): int {}
60+
61+
/** @param DOMDocument|SimpleXMLElement $document */
62+
function xsl_xsltprocessor_transform_to_xml($document): string|false|null {}
63+
64+
/** @param string|array $name */
65+
function xsl_xsltprocessor_set_parameter(string $namespace, $name, string $value = UNKNOWN): bool|null {}
66+
67+
function xsl_xsltprocessor_get_parameter(string $namespace, string $name): string|false {}
68+
69+
function xsl_xsltprocessor_remove_parameter(string $namespace, string $name): bool {}
70+
71+
function xsl_xsltprocessor_has_exslt_support(): bool {}
72+
73+
/** @param string|array $restrict */
74+
function xsl_xsltprocessor_register_php_functions($restrict = UNKNOWN): void {}
75+
76+
function xsl_xsltprocessor_set_profiling(?string $filename): bool {}
77+
78+
function xsl_xsltprocessor_set_security_prefs(int $securityPrefs): int {}
79+
80+
function xsl_xsltprocessor_get_security_prefs(): int {}

ext/xsl/php_xsl_arginfo.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* This is a generated file, edit the .stub.php file instead. */
2+
3+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_importStylesheet, 0, 0, 1)
4+
ZEND_ARG_TYPE_INFO(0, stylesheet, IS_OBJECT, 0)
5+
ZEND_END_ARG_INFO()
6+
7+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_transformToDoc, 0, 0, 1)
8+
ZEND_ARG_OBJ_INFO(0, document, DOMNode, 0)
9+
ZEND_ARG_TYPE_INFO(0, return_class, IS_STRING, 1)
10+
ZEND_END_ARG_INFO()
11+
12+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_transformToUri, 0, 0, 2)
13+
ZEND_ARG_INFO(0, document)
14+
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0)
15+
ZEND_END_ARG_INFO()
16+
17+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_transformToXml, 0, 0, 1)
18+
ZEND_ARG_INFO(0, document)
19+
ZEND_END_ARG_INFO()
20+
21+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_setParameter, 0, 0, 2)
22+
ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 0)
23+
ZEND_ARG_INFO(0, name)
24+
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
25+
ZEND_END_ARG_INFO()
26+
27+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_getParameter, 0, 0, 2)
28+
ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 0)
29+
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
30+
ZEND_END_ARG_INFO()
31+
32+
#define arginfo_class_XSLTProcessor_removeParameter arginfo_class_XSLTProcessor_getParameter
33+
34+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_hasExsltSupport, 0, 0, 0)
35+
ZEND_END_ARG_INFO()
36+
37+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_registerPHPFunctions, 0, 0, 0)
38+
ZEND_ARG_INFO(0, restrict)
39+
ZEND_END_ARG_INFO()
40+
41+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_setProfiling, 0, 0, 1)
42+
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 1)
43+
ZEND_END_ARG_INFO()
44+
45+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_setSecurityPrefs, 0, 0, 1)
46+
ZEND_ARG_TYPE_INFO(0, securityPrefs, IS_LONG, 0)
47+
ZEND_END_ARG_INFO()
48+
49+
#define arginfo_class_XSLTProcessor_getSecurityPrefs arginfo_class_XSLTProcessor_hasExsltSupport

ext/xsl/tests/xsltprocessor_hasExsltSupport_wrongparam_001.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
77
--FILE--
88
<?php
99
$proc = new XSLTProcessor();
10-
var_dump($proc->hasExsltSupport('stringValue'));
10+
try {
11+
$proc->hasExsltSupport('stringValue');
12+
} catch (ArgumentCountError $exception) {
13+
echo $exception->getMessage() . "\n";
14+
}
1115
?>
1216
--EXPECT--
13-
bool(true)
17+
XSLTProcessor::hasExsltSupport() expects exactly 0 parameters, 1 given

ext/xsl/xsltprocessor.c

Lines changed: 37 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -21,61 +21,9 @@
2121

2222
#include "php.h"
2323
#include "php_xsl.h"
24+
#include "php_xsl_arginfo.h"
2425
#include "ext/libxml/php_libxml.h"
2526

26-
/* {{{ arginfo */
27-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_import_stylesheet, 0, 0, 1)
28-
ZEND_ARG_INFO(0, doc)
29-
ZEND_END_ARG_INFO();
30-
31-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_transform_to_doc, 0, 0, 1)
32-
ZEND_ARG_INFO(0, doc)
33-
ZEND_END_ARG_INFO();
34-
35-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_transform_to_uri, 0, 0, 2)
36-
ZEND_ARG_INFO(0, doc)
37-
ZEND_ARG_INFO(0, uri)
38-
ZEND_END_ARG_INFO();
39-
40-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_transform_to_xml, 0, 0, 1)
41-
ZEND_ARG_INFO(0, doc)
42-
ZEND_END_ARG_INFO();
43-
44-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_set_parameter, 0, 0, 2)
45-
ZEND_ARG_INFO(0, namespace)
46-
ZEND_ARG_INFO(0, name)
47-
ZEND_ARG_INFO(0, value)
48-
ZEND_END_ARG_INFO();
49-
50-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_get_parameter, 0, 0, 2)
51-
ZEND_ARG_INFO(0, namespace)
52-
ZEND_ARG_INFO(0, name)
53-
ZEND_END_ARG_INFO();
54-
55-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_remove_parameter, 0, 0, 2)
56-
ZEND_ARG_INFO(0, namespace)
57-
ZEND_ARG_INFO(0, name)
58-
ZEND_END_ARG_INFO();
59-
60-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_has_exslt_support, 0, 0, 0)
61-
ZEND_END_ARG_INFO();
62-
63-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_register_php_functions, 0, 0, 0)
64-
ZEND_ARG_INFO(0, restrict)
65-
ZEND_END_ARG_INFO();
66-
67-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_set_profiling, 0, 0, 1)
68-
ZEND_ARG_INFO(0, filename)
69-
ZEND_END_ARG_INFO();
70-
71-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_set_security_prefs, 0, 0, 1)
72-
ZEND_ARG_INFO(0, securityPrefs)
73-
ZEND_END_ARG_INFO();
74-
75-
ZEND_BEGIN_ARG_INFO_EX(arginfo_xsl_xsltprocessor_get_security_prefs, 0, 0, 0)
76-
ZEND_END_ARG_INFO();
77-
/* }}} */
78-
7927
/*
8028
* class xsl_xsltprocessor
8129
*
@@ -84,18 +32,18 @@ ZEND_END_ARG_INFO();
8432
*/
8533

8634
const zend_function_entry php_xsl_xsltprocessor_class_functions[] = {
87-
PHP_FALIAS(importStylesheet, xsl_xsltprocessor_import_stylesheet, arginfo_xsl_xsltprocessor_import_stylesheet)
88-
PHP_FALIAS(transformToDoc, xsl_xsltprocessor_transform_to_doc, arginfo_xsl_xsltprocessor_transform_to_doc)
89-
PHP_FALIAS(transformToUri, xsl_xsltprocessor_transform_to_uri, arginfo_xsl_xsltprocessor_transform_to_uri)
90-
PHP_FALIAS(transformToXml, xsl_xsltprocessor_transform_to_xml, arginfo_xsl_xsltprocessor_transform_to_xml)
91-
PHP_FALIAS(setParameter, xsl_xsltprocessor_set_parameter, arginfo_xsl_xsltprocessor_set_parameter)
92-
PHP_FALIAS(getParameter, xsl_xsltprocessor_get_parameter, arginfo_xsl_xsltprocessor_get_parameter)
93-
PHP_FALIAS(removeParameter, xsl_xsltprocessor_remove_parameter, arginfo_xsl_xsltprocessor_remove_parameter)
94-
PHP_FALIAS(hasExsltSupport, xsl_xsltprocessor_has_exslt_support, arginfo_xsl_xsltprocessor_has_exslt_support)
95-
PHP_FALIAS(registerPHPFunctions, xsl_xsltprocessor_register_php_functions, arginfo_xsl_xsltprocessor_register_php_functions)
96-
PHP_FALIAS(setProfiling, xsl_xsltprocessor_set_profiling, arginfo_xsl_xsltprocessor_set_profiling)
97-
PHP_FALIAS(setSecurityPrefs, xsl_xsltprocessor_set_security_prefs, arginfo_xsl_xsltprocessor_set_security_prefs)
98-
PHP_FALIAS(getSecurityPrefs, xsl_xsltprocessor_get_security_prefs, arginfo_xsl_xsltprocessor_get_security_prefs)
35+
PHP_ME_MAPPING(importStylesheet, xsl_xsltprocessor_import_stylesheet, arginfo_class_XSLTProcessor_importStylesheet, ZEND_ACC_PUBLIC)
36+
PHP_ME_MAPPING(transformToDoc, xsl_xsltprocessor_transform_to_doc, arginfo_class_XSLTProcessor_transformToDoc, ZEND_ACC_PUBLIC)
37+
PHP_ME_MAPPING(transformToUri, xsl_xsltprocessor_transform_to_uri, arginfo_class_XSLTProcessor_transformToUri, ZEND_ACC_PUBLIC)
38+
PHP_ME_MAPPING(transformToXml, xsl_xsltprocessor_transform_to_xml, arginfo_class_XSLTProcessor_transformToXml, ZEND_ACC_PUBLIC)
39+
PHP_ME_MAPPING(setParameter, xsl_xsltprocessor_set_parameter, arginfo_class_XSLTProcessor_setParameter, ZEND_ACC_PUBLIC)
40+
PHP_ME_MAPPING(getParameter, xsl_xsltprocessor_get_parameter, arginfo_class_XSLTProcessor_getParameter, ZEND_ACC_PUBLIC)
41+
PHP_ME_MAPPING(removeParameter, xsl_xsltprocessor_remove_parameter, arginfo_class_XSLTProcessor_removeParameter, ZEND_ACC_PUBLIC)
42+
PHP_ME_MAPPING(hasExsltSupport, xsl_xsltprocessor_has_exslt_support, arginfo_class_XSLTProcessor_hasExsltSupport, ZEND_ACC_PUBLIC)
43+
PHP_ME_MAPPING(registerPHPFunctions, xsl_xsltprocessor_register_php_functions, arginfo_class_XSLTProcessor_registerPHPFunctions, ZEND_ACC_PUBLIC)
44+
PHP_ME_MAPPING(setProfiling, xsl_xsltprocessor_set_profiling, arginfo_class_XSLTProcessor_setProfiling, ZEND_ACC_PUBLIC)
45+
PHP_ME_MAPPING(setSecurityPrefs, xsl_xsltprocessor_set_security_prefs, arginfo_class_XSLTProcessor_setSecurityPrefs, ZEND_ACC_PUBLIC)
46+
PHP_ME_MAPPING(getSecurityPrefs, xsl_xsltprocessor_get_security_prefs, arginfo_class_XSLTProcessor_getSecurityPrefs, ZEND_ACC_PUBLIC)
9947
PHP_FE_END
10048
};
10149

@@ -765,7 +713,7 @@ PHP_FUNCTION(xsl_xsltprocessor_set_parameter)
765713
}
766714
str = zval_try_get_string(entry);
767715
if (UNEXPECTED(!str)) {
768-
return;
716+
RETURN_THROWS();
769717
}
770718
ZVAL_STR(&tmp, str);
771719
zend_hash_update(intern->parameter, string_key, &tmp);
@@ -867,11 +815,10 @@ PHP_FUNCTION(xsl_xsltprocessor_register_php_functions)
867815
zend_hash_update(intern->registered_phpfunctions, name, &new_string);
868816
intern->registerPhpFunctions = 2;
869817

870-
} else {
818+
} else if (zend_parse_parameters_none() == SUCCESS) {
871819
intern = Z_XSL_P(id);
872820
intern->registerPhpFunctions = 1;
873821
}
874-
875822
}
876823
/* }}} end xsl_xsltprocessor_register_php_functions(); */
877824

@@ -883,21 +830,21 @@ PHP_FUNCTION(xsl_xsltprocessor_set_profiling)
883830
char *filename = NULL;
884831
size_t filename_len;
885832
DOM_GET_THIS(id);
833+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p!", &filename, &filename_len) == FAILURE) {
834+
RETURN_THROWS();
835+
}
886836

887-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "p!", &filename, &filename_len) == SUCCESS) {
888-
intern = Z_XSL_P(id);
889-
if (intern->profiling) {
890-
efree(intern->profiling);
891-
}
892-
if (filename != NULL) {
893-
intern->profiling = estrndup(filename, filename_len);
894-
} else {
895-
intern->profiling = NULL;
896-
}
897-
RETURN_TRUE;
837+
intern = Z_XSL_P(id);
838+
if (intern->profiling) {
839+
efree(intern->profiling);
840+
}
841+
if (filename != NULL) {
842+
intern->profiling = estrndup(filename, filename_len);
898843
} else {
899-
WRONG_PARAM_COUNT;
844+
intern->profiling = NULL;
900845
}
846+
847+
RETURN_TRUE;
901848
}
902849
/* }}} end xsl_xsltprocessor_set_profiling */
903850

@@ -928,19 +875,24 @@ PHP_FUNCTION(xsl_xsltprocessor_get_security_prefs)
928875
xsl_object *intern;
929876

930877
DOM_GET_THIS(id);
931-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "") == SUCCESS) {
932-
intern = Z_XSL_P(id);
933-
RETURN_LONG(intern->securityPrefs);
934-
} else {
935-
WRONG_PARAM_COUNT;
878+
if (zend_parse_parameters_none() == FAILURE) {
879+
RETURN_THROWS();
936880
}
881+
882+
intern = Z_XSL_P(id);
883+
884+
RETURN_LONG(intern->securityPrefs);
937885
}
938886
/* }}} end xsl_xsltprocessor_get_security_prefs */
939887

940888
/* {{{ proto bool xsl_xsltprocessor_has_exslt_support()
941889
*/
942890
PHP_FUNCTION(xsl_xsltprocessor_has_exslt_support)
943891
{
892+
if (zend_parse_parameters_none() == FAILURE) {
893+
RETURN_THROWS();
894+
}
895+
944896
#if HAVE_XSL_EXSLT
945897
RETURN_TRUE;
946898
#else

0 commit comments

Comments
 (0)