Skip to content

Commit

Permalink
XMLParser: add $isFinal variable
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre committed Aug 4, 2023
1 parent eee5610 commit a9dbecb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/XMLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ private function parseNextChunk(): void
{
// the nodes stack has been iterated over, consume and parse the next piece of the XML stream
$data = stream_get_contents($this->stream, length: self::BATCH_READ_SIZE);
$res = xml_parse($this->parser, $data, is_final: $data === false);
$isFinal = ($data === false);

$res = xml_parse($this->parser, $data, $isFinal);

if ($res === 0 /* returns 0 on failure */) {
// take more details from the parser instance and throw an exception
throw ParsingError::fromParserInstance($this->parser, is_string($data) ? $data : null);
}

// we're done with reading and parsing the stream, close the XML parser instance
if ($data === false) {
if ($isFinal) {
$this->close();
}
}
Expand Down

0 comments on commit a9dbecb

Please sign in to comment.