Skip to content

Commit f4cd4d3

Browse files
committed
Refactor code to allow multiple namespaces
1 parent cd5c8d0 commit f4cd4d3

File tree

5 files changed

+206
-122
lines changed

5 files changed

+206
-122
lines changed

ext/dom/tests/DOMXPath_callables.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ $xpath->registerNamespace("php", "http://php.net/xpath");
6565
$xpath->registerCycle();
6666
$xpath->evaluate("//a[php:function('cycle', string(@href))]");
6767

68+
echo "--- Legit cases: reset to null ---\n";
69+
70+
$xpath->registerPhpFunctions(null);
71+
$xpath->evaluate("//a[php:function('var_dump', string(@href))]");
72+
6873
echo "--- Error cases ---\n";
6974

7075
$xpath = new DOMXPath($doc);
@@ -118,6 +123,8 @@ string(15) "https://php.net"
118123
No callback handler "notinset" registered
119124
--- Legit cases: set with cycle ---
120125
dummy: https://php.net
126+
--- Legit cases: reset to null ---
127+
string(15) "https://php.net"
121128
--- Error cases ---
122129
DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a callable, function "nonexistent" not found or invalid function name
123130
DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be of type array|string|null, Closure given

ext/dom/xpath.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
7777
"xmlExtFunctionTest: failed to get the internal object\n");
7878
error = true;
7979
}
80-
else if (intern->xpath_callbacks.mode == PHP_DOM_REG_FUNC_MODE_NONE) {
81-
zend_throw_error(NULL, "No callbacks were registered");
82-
error = true;
83-
}
8480
}
8581

8682
if (error) {
@@ -381,7 +377,16 @@ PHP_METHOD(DOMXPath, evaluate)
381377
PHP_METHOD(DOMXPath, registerPhpFunctions)
382378
{
383379
dom_xpath_object *intern = Z_XPATHOBJ_P(ZEND_THIS);
384-
php_dom_xpath_callbacks_update_method_handler(&intern->xpath_callbacks, INTERNAL_FUNCTION_PARAM_PASSTHRU);
380+
381+
zend_string *name = NULL;
382+
HashTable *callable_ht = NULL;
383+
384+
ZEND_PARSE_PARAMETERS_START(0, 1)
385+
Z_PARAM_OPTIONAL
386+
Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(callable_ht, name)
387+
ZEND_PARSE_PARAMETERS_END();
388+
389+
php_dom_xpath_callbacks_update_method_handler(&intern->xpath_callbacks, NULL, name, callable_ht);
385390
}
386391
/* }}} end dom_xpath_register_php_functions */
387392

0 commit comments

Comments
 (0)