Skip to content
Open
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
14 changes: 7 additions & 7 deletions source/FluidXml/FluidXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class FluidXml implements FluidInterface
private ?\FluidXml\FluidContext $context = null;
private $contextEl;

public static function load($document)
public static function load($document, int $flags = 0)
{
$file = $document;
$document = \file_get_contents($file);
$dom = new \DOMDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;

// file_get_contents() returns false in case of error.
if (! $document) {
throw new \Exception("File '$file' not accessible.");
if (! @$dom->load($document, $flags)) {
throw new \Exception("File '$document' not accessible.");
}

return (new FluidXml(null))->addChild($document);
return (new FluidXml(null))->addChild($dom);
}

public function __construct(...$arguments)
Expand Down
14 changes: 14 additions & 0 deletions specs/FluidXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@

assert_is_a($actual, \Exception::class);
});

it('should accept libxml flags', function () {
$file = "{$this->out_dir}.test_load_flags.xml";
$doc = "<root>\n"
. " <item>value</item>\n"
. "</root>";

\file_put_contents($file, $doc);
$xml = FluidXml::load($file, \LIBXML_PARSEHUGE);
\unlink($file);

$expected = $doc;
assert_equal_xml($xml, $expected);
});
});

if (\version_compare(\phpversion(), '7', '>=')) {
Expand Down