@@ -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 (function_exists ('mb_internal_encoding ' ) && ((int ) ini_get ('mbstring.func_overload ' )) & 2 ) {
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 (function_exists ('mb_internal_encoding ' ) && ((int ) ini_get ('mbstring.func_overload ' )) & 2 ) {
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 ;
@@ -250,21 +278,13 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
250
278
throw $ e ;
251
279
}
252
280
253
- if (isset ($ mbEncoding )) {
254
- mb_internal_encoding ($ mbEncoding );
255
- }
256
-
257
281
return $ value ;
258
282
}
259
283
260
284
throw new ParseException ('Unable to parse. ' , $ this ->getRealCurrentLineNb () + 1 , $ this ->currentLine );
261
285
}
262
286
}
263
287
264
- if (isset ($ mbEncoding )) {
265
- mb_internal_encoding ($ mbEncoding );
266
- }
267
-
268
288
return empty ($ data ) ? null : $ data ;
269
289
}
270
290
@@ -283,7 +303,7 @@ private function parseBlock($offset, $yaml, $exceptionOnInvalidType, $objectSupp
283
303
$ parser = new self ($ offset , $ this ->totalNumberOfLines , $ skippedLineNumbers );
284
304
$ parser ->refs = &$ this ->refs ;
285
305
286
- return $ parser ->parse ($ yaml , $ exceptionOnInvalidType , $ objectSupport , $ objectForMap );
306
+ return $ parser ->doParse ($ yaml , $ exceptionOnInvalidType , $ objectSupport , $ objectForMap );
287
307
}
288
308
289
309
/**
0 commit comments