@@ -92,7 +92,9 @@ class Xml
92
92
* - `readFile` Set to false to disable file reading. This is important to disable when
93
93
* putting user data into Xml::build(). If enabled local files will be read if they exist.
94
94
* Defaults to true for backwards compatibility reasons.
95
- * - If using array as input, you can pass `options` from Xml::fromArray.
95
+ * - `parseHuge` Enable the `LIBXML_PARSEHUGE` flag.
96
+ *
97
+ * If using array as input, you can pass `options` from Xml::fromArray.
96
98
*
97
99
* @param string|array $input XML string, a path to a file, a URL or an array
98
100
* @param string|array $options The options to use
@@ -104,7 +106,8 @@ public static function build($input, array $options = [])
104
106
$ defaults = [
105
107
'return ' => 'simplexml ' ,
106
108
'loadEntities ' => false ,
107
- 'readFile ' => true
109
+ 'readFile ' => true ,
110
+ 'parseHuge ' => true ,
108
111
];
109
112
$ options += $ defaults ;
110
113
@@ -142,9 +145,13 @@ protected static function _loadXml($input, $options)
142
145
if ($ hasDisable && !$ options ['loadEntities ' ]) {
143
146
libxml_disable_entity_loader (true );
144
147
}
148
+ $ flags = LIBXML_NOCDATA ;
149
+ if (!empty ($ options ['parseHuge ' ])) {
150
+ $ flags |= LIBXML_PARSEHUGE ;
151
+ }
145
152
try {
146
153
if ($ options ['return ' ] === 'simplexml ' || $ options ['return ' ] === 'simplexmlelement ' ) {
147
- $ xml = new SimpleXMLElement ($ input , LIBXML_NOCDATA );
154
+ $ xml = new SimpleXMLElement ($ input , $ flags );
148
155
} else {
149
156
$ xml = new DOMDocument ();
150
157
$ xml ->loadXML ($ input );
0 commit comments