From 745515b11f438d3658203aaaaf151c72e30d5e7c Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Mon, 17 Oct 2016 23:26:48 +0200 Subject: [FEATURE] Add config and use composer autoloader. We use composer already to install SabreDAV. Include config composer.(json|lock) to install and manage more dependencies in future. Also provide PSR-4 autoloading for our namespaced classes, e.g. "Zotlabs\". To regenerate autoloader maps use: $ composer install --optimize-autoloader --no-dev We could also remove the whole vendor/ folder from our repository, but that would need changes in deployment and how to install hubs and needs more discussion first. --- vendor/sabre/xml/lib/Reader.php | 122 +++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 58 deletions(-) (limited to 'vendor/sabre/xml/lib/Reader.php') 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)) { -- cgit v1.2.3