@@ -64,23 +64,51 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
64
64
if (false === preg_match ('//u ' , $ value )) {
65
65
throw new ParseException ('The YAML value does not appear to be valid UTF-8. ' );
66
66
}
67
+
68
+ $ this ->refs = array ();
69
+
70
+ $ mbEncoding = null ;
71
+ $ e = null ;
72
+ $ data = null ;
73
+
74
+ if (2 /* MB_OVERLOAD_STRING */ & (int ) ini_get ('mbstring.func_overload ' )) {
75
+ $ mbEncoding = mb_internal_encoding ();
76
+ mb_internal_encoding ('UTF-8 ' );
77
+ }
78
+
79
+ try {
80
+ $ data = $ this ->doParse ($ value , $ exceptionOnInvalidType , $ objectSupport , $ objectForMap );
81
+ } catch (\Exception $ e ) {
82
+ } catch (\Throwable $ e ) {
83
+ }
84
+
85
+ if (null !== $ mbEncoding ) {
86
+ mb_internal_encoding ($ mbEncoding );
87
+ }
88
+
89
+ if (null !== $ e ) {
90
+ throw $ e ;
91
+ }
92
+
93
+ return $ data ;
94
+ }
95
+
96
+ private function doParse ($ value , $ exceptionOnInvalidType = false , $ objectSupport = false , $ objectForMap = false )
97
+ {
67
98
$ this ->currentLineNb = -1 ;
68
99
$ this ->currentLine = '' ;
69
100
$ value = $ this ->cleanup ($ value );
70
101
$ this ->lines = explode ("\n" , $ value );
102
+ $ this ->locallySkippedLineNumbers = array ();
71
103
72
104
if (null === $ this ->totalNumberOfLines ) {
73
105
$ this ->totalNumberOfLines = count ($ this ->lines );
74
106
}
75
107
76
- if (2 /* MB_OVERLOAD_STRING */ & (int ) ini_get ('mbstring.func_overload ' )) {
77
- $ mbEncoding = mb_internal_encoding ();
78
- mb_internal_encoding ('UTF-8 ' );
79
- }
80
-
81
108
$ data = array ();
82
109
$ context = null ;
83
110
$ allowOverwrite = false ;
111
+
84
112
while ($ this ->moveToNextLine ()) {
85
113
if ($ this ->isCurrentLineEmpty ()) {
86
114
continue ;
@@ -246,21 +274,13 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
246
274
throw $ e ;
247
275
}
248
276
249
- if (isset ($ mbEncoding )) {
250
- mb_internal_encoding ($ mbEncoding );
251
- }
252
-
253
277
return $ value ;
254
278
}
255
279
256
280
throw new ParseException ('Unable to parse. ' , $ this ->getRealCurrentLineNb () + 1 , $ this ->currentLine );
257
281
}
258
282
}
259
283
260
- if (isset ($ mbEncoding )) {
261
- mb_internal_encoding ($ mbEncoding );
262
- }
263
-
264
284
if ($ objectForMap && !is_object ($ data ) && 'mapping ' === $ context ) {
265
285
$ object = new \stdClass ();
266
286
@@ -289,7 +309,7 @@ private function parseBlock($offset, $yaml, $exceptionOnInvalidType, $objectSupp
289
309
$ parser = new self ($ offset , $ this ->totalNumberOfLines , $ skippedLineNumbers );
290
310
$ parser ->refs = &$ this ->refs ;
291
311
292
- return $ parser ->parse ($ yaml , $ exceptionOnInvalidType , $ objectSupport , $ objectForMap );
312
+ return $ parser ->doParse ($ yaml , $ exceptionOnInvalidType , $ objectSupport , $ objectForMap );
293
313
}
294
314
295
315
/**
0 commit comments