1--TEST--
2libxml_set_external_entity_loader() basic test
3--SKIPIF--
4<?php if (!extension_loaded('dom')) die('skip dom extension not available'); ?>
5--FILE--
6<?php
7$xml = <<<XML
8<!DOCTYPE foo PUBLIC "-//FOO/BAR" "http://example.com/foobar">
9<foo>bar</foo>
10XML;
11
12$dtd = <<<DTD
13<!ELEMENT foo (#PCDATA)>
14DTD;
15
16libxml_set_external_entity_loader(
17    function ($public, $system, $context) use($dtd){
18        var_dump($public);
19        var_dump($system);
20        var_dump($context);
21        $f = fopen("php://temp", "r+");
22        fwrite($f, $dtd);
23        rewind($f);
24        return $f;
25    }
26);
27
28$dd = new DOMDocument;
29$r = $dd->loadXML($xml);
30var_dump($dd->validate());
31
32echo "Done.\n";
33
34?>
35--EXPECT--
36string(10) "-//FOO/BAR"
37string(25) "http://example.com/foobar"
38array(4) {
39  ["directory"]=>
40  NULL
41  ["intSubName"]=>
42  NULL
43  ["extSubURI"]=>
44  NULL
45  ["extSubSystem"]=>
46  NULL
47}
48bool(true)
49Done.
50