Skip to content

Commit 95f07fe

Browse files
committed
Instead add libxml_get_external_entity_loader()
1 parent b6f5acc commit 95f07fe

File tree

6 files changed

+61
-43
lines changed

6 files changed

+61
-43
lines changed

ext/libxml/libxml.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ static PHP_RSHUTDOWN_FUNCTION(libxml)
844844
zval_ptr_dtor_nogc(&LIBXML(entity_loader).callback);
845845
ZVAL_NULL(&LIBXML(entity_loader).callback);
846846
}
847-
847+
848848
return SUCCESS;
849849
}
850850

@@ -1060,13 +1060,13 @@ PHP_FUNCTION(libxml_disable_entity_loader)
10601060
}
10611061
/* }}} */
10621062

1063-
/* {{{ Change the default external entity loader and return the previous loader */
1063+
/* {{{ Changes the default external entity loader */
10641064
PHP_FUNCTION(libxml_set_external_entity_loader)
10651065
{
1066-
zval *callback;
1066+
zval *callback;
10671067
zend_fcall_info fci;
1068-
zend_fcall_info_cache fcc;
1069-
char *error = NULL;
1068+
zend_fcall_info_cache fcc;
1069+
char error = NULL;
10701070

10711071
ZEND_PARSE_PARAMETERS_START(1, 1)
10721072
Z_PARAM_ZVAL(callback)
@@ -1085,11 +1085,19 @@ PHP_FUNCTION(libxml_set_external_entity_loader)
10851085
LIBXML(entity_loader).fci = fci;
10861086
LIBXML(entity_loader).fcc = fcc;
10871087
}
1088-
ZVAL_COPY(return_value, &LIBXML(entity_loader).callback);
10891088
if (!Z_ISNULL(LIBXML(entity_loader).callback)) {
10901089
zval_ptr_dtor_nogc(&LIBXML(entity_loader).callback);
10911090
}
10921091
ZVAL_COPY(&LIBXML(entity_loader).callback, callback);
1092+
RETURN_TRUE;
1093+
}
1094+
/* }}} */
1095+
1096+
/* {{{ Get the current external entity loader, or null if the default loader is installer. */
1097+
PHP_FUNCTION(libxml_get_external_entity_loader)
1098+
{
1099+
ZEND_PARSE_PARAMETERS_NONE();
1100+
RETURN_COPY(&LIBXML(entity_loader).callback);
10931101
}
10941102
/* }}} */
10951103

ext/libxml/libxml.stub.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,6 @@ function libxml_clear_errors(): void {}
176176
/** @deprecated */
177177
function libxml_disable_entity_loader(bool $disable = true): bool {}
178178

179-
function libxml_set_external_entity_loader(?callable $resolver_function): callable|bool|null {}
179+
function libxml_set_external_entity_loader(?callable $resolver_function): bool {}
180+
181+
function libxml_get_external_entity_loader(): ?callable {}

ext/libxml/libxml_arginfo.h

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
libxml_get_external_entity_loader() returns current handler
3+
--SKIPIF--
4+
<?php if (!extension_loaded('dom')) die('skip dom extension not available'); ?>
5+
--FILE--
6+
<?php
7+
8+
class Handler {
9+
private $name;
10+
11+
public function __construct($name) {
12+
$this->name = $name;
13+
}
14+
15+
public function handle($public, $system, $context) {
16+
return null;
17+
}
18+
19+
public function __toString() {
20+
return "Handler#{$this->name}";
21+
}
22+
}
23+
24+
var_dump(libxml_get_external_entity_loader());
25+
libxml_set_external_entity_loader([new Handler('A'), 'handle']);
26+
print libxml_get_external_entity_loader()[0] . "\n";
27+
libxml_set_external_entity_loader([new Handler('B'), 'handle']);
28+
print libxml_get_external_entity_loader()[0] . "\n";
29+
libxml_set_external_entity_loader(null);
30+
var_dump(libxml_get_external_entity_loader());
31+
32+
--EXPECT--
33+
NULL
34+
Handler#A
35+
Handler#B
36+
NULL

ext/libxml/tests/libxml_set_external_entity_loader_error1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ try {
2222
echo "Done.\n";
2323
?>
2424
--EXPECT--
25-
NULL
25+
bool(true)
2626
Exception: Too few arguments to function {closure}(), 3 passed and exactly 4 expected
2727
Done.

ext/libxml/tests/libxml_set_external_entity_loader_return.phpt

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)