Yaffs site version 1.1
[yaffs-website] / vendor / symfony / yaml / Parser.php
index 25da4e9f2b14b2bd999a05cea23746c95217bace..96a85a8fe7c9bfeb391134c5558bbbb119f8be4a 100644 (file)
@@ -64,23 +64,57 @@ class Parser
         if (false === preg_match('//u', $value)) {
             throw new ParseException('The YAML value does not appear to be valid UTF-8.');
         }
+
+        $this->refs = array();
+
+        $mbEncoding = null;
+        $e = null;
+        $data = null;
+
+        if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
+            $mbEncoding = mb_internal_encoding();
+            mb_internal_encoding('UTF-8');
+        }
+
+        try {
+            $data = $this->doParse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap);
+        } catch (\Exception $e) {
+        } catch (\Throwable $e) {
+        }
+
+        if (null !== $mbEncoding) {
+            mb_internal_encoding($mbEncoding);
+        }
+
+        $this->lines = array();
+        $this->currentLine = '';
+        $this->refs = array();
+        $this->skippedLineNumbers = array();
+        $this->locallySkippedLineNumbers = array();
+
+        if (null !== $e) {
+            throw $e;
+        }
+
+        return $data;
+    }
+
+    private function doParse($value, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false)
+    {
         $this->currentLineNb = -1;
         $this->currentLine = '';
         $value = $this->cleanup($value);
         $this->lines = explode("\n", $value);
+        $this->locallySkippedLineNumbers = array();
 
         if (null === $this->totalNumberOfLines) {
             $this->totalNumberOfLines = count($this->lines);
         }
 
-        if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
-            $mbEncoding = mb_internal_encoding();
-            mb_internal_encoding('UTF-8');
-        }
-
         $data = array();
         $context = null;
         $allowOverwrite = false;
+
         while ($this->moveToNextLine()) {
             if ($this->isCurrentLineEmpty()) {
                 continue;
@@ -246,10 +280,6 @@ class Parser
                         throw $e;
                     }
 
-                    if (isset($mbEncoding)) {
-                        mb_internal_encoding($mbEncoding);
-                    }
-
                     return $value;
                 }
 
@@ -257,10 +287,6 @@ class Parser
             }
         }
 
-        if (isset($mbEncoding)) {
-            mb_internal_encoding($mbEncoding);
-        }
-
         if ($objectForMap && !is_object($data) && 'mapping' === $context) {
             $object = new \stdClass();
 
@@ -289,7 +315,7 @@ class Parser
         $parser = new self($offset, $this->totalNumberOfLines, $skippedLineNumbers);
         $parser->refs = &$this->refs;
 
-        return $parser->parse($yaml, $exceptionOnInvalidType, $objectSupport, $objectForMap);
+        return $parser->doParse($yaml, $exceptionOnInvalidType, $objectSupport, $objectForMap);
     }
 
     /**