aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/xml/lib/Reader.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/xml/lib/Reader.php')
-rw-r--r--vendor/sabre/xml/lib/Reader.php122
1 files changed, 64 insertions, 58 deletions
diff --git a/vendor/sabre/xml/lib/Reader.php b/vendor/sabre/xml/lib/Reader.php
index f35dc8537..92e5dba96 100644
--- a/vendor/sabre/xml/lib/Reader.php
+++ b/vendor/sabre/xml/lib/Reader.php
@@ -59,22 +59,26 @@ class Reader extends XMLReader {
$previousEntityState = libxml_disable_entity_loader(true);
$previousSetting = libxml_use_internal_errors(true);
- // Really sorry about the silence operator, seems like I have no
- // choice. See:
- //
- // https://bugs.php.net/bug.php?id=64230
- while ($this->nodeType !== self::ELEMENT && @$this->read()) {
- // noop
- }
- $result = $this->parseCurrentElement();
+ try {
+
+ // Really sorry about the silence operator, seems like I have no
+ // choice. See:
+ //
+ // https://bugs.php.net/bug.php?id=64230
+ while ($this->nodeType !== self::ELEMENT && @$this->read()) {
+ // noop
+ }
+ $result = $this->parseCurrentElement();
- $errors = libxml_get_errors();
- libxml_clear_errors();
- libxml_use_internal_errors($previousSetting);
- libxml_disable_entity_loader($previousEntityState);
+ $errors = libxml_get_errors();
+ libxml_clear_errors();
+ if ($errors) {
+ throw new LibXMLException($errors);
+ }
- if ($errors) {
- throw new LibXMLException($errors);
+ } finally {
+ libxml_use_internal_errors($previousSetting);
+ libxml_disable_entity_loader($previousEntityState);
}
return $result;
@@ -138,60 +142,62 @@ class Reader extends XMLReader {
$this->elementMap = $elementMap;
}
- // Really sorry about the silence operator, seems like I have no
- // choice. See:
- //
- // https://bugs.php.net/bug.php?id=64230
- if (!@$this->read()) {
- if (!is_null($elementMap)) {
- $this->popContext();
- }
- return false;
- }
-
- while (true) {
-
- if (!$this->isValid()) {
+ try {
+ // Really sorry about the silence operator, seems like I have no
+ // choice. See:
+ //
+ // https://bugs.php.net/bug.php?id=64230
+ if (!@$this->read()) {
$errors = libxml_get_errors();
-
+ libxml_clear_errors();
if ($errors) {
- libxml_clear_errors();
- if (!is_null($elementMap)) {
- $this->popContext();
- }
throw new LibXMLException($errors);
}
+ throw new ParseException('This should never happen (famous last words)');
}
- switch ($this->nodeType) {
- case self::ELEMENT :
- $elements[] = $this->parseCurrentElement();
- break;
- case self::TEXT :
- case self::CDATA :
- $text .= $this->value;
- $this->read();
- break;
- case self::END_ELEMENT :
- // Ensuring we are moving the cursor after the end element.
- $this->read();
- break 2;
- case self::NONE :
- if (!is_null($elementMap)) {
- $this->popContext();
+ while (true) {
+
+ if (!$this->isValid()) {
+
+ $errors = libxml_get_errors();
+
+ if ($errors) {
+ libxml_clear_errors();
+ throw new LibXMLException($errors);
}
- throw new ParseException('We hit the end of the document prematurely. This likely means that some parser "eats" too many elements. Do not attempt to continue parsing.');
- default :
- // Advance to the next element
- $this->read();
- break;
+ }
+
+ switch ($this->nodeType) {
+ case self::ELEMENT :
+ $elements[] = $this->parseCurrentElement();
+ break;
+ case self::TEXT :
+ case self::CDATA :
+ $text .= $this->value;
+ $this->read();
+ break;
+ case self::END_ELEMENT :
+ // Ensuring we are moving the cursor after the end element.
+ $this->read();
+ break 2;
+ case self::NONE :
+ throw new ParseException('We hit the end of the document prematurely. This likely means that some parser "eats" too many elements. Do not attempt to continue parsing.');
+ default :
+ // Advance to the next element
+ $this->read();
+ break;
+ }
+
}
- }
+ } finally {
+
+ if (!is_null($elementMap)) {
+ $this->popContext();
+ }
- if (!is_null($elementMap)) {
- $this->popContext();
}
return ($elements ? $elements : $text);
@@ -304,7 +310,7 @@ class Reader extends XMLReader {
$deserializer = $this->elementMap[$name];
if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) {
- return [ $deserializer, 'xmlDeserialize' ];
+ return [$deserializer, 'xmlDeserialize'];
}
if (is_callable($deserializer)) {