File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ class Utils
1414 */
1515 public static function getFormatedXml ($ string , $ asDomDocument = false )
1616 {
17+ $ dom = null ;
18+ $ formated = $ string ;
1719 if (!empty ($ string ) && class_exists ('DOMDocument ' )) {
1820 $ dom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
1921 $ dom ->formatOutput = true ;
@@ -23,12 +25,12 @@ public static function getFormatedXml($string, $asDomDocument = false)
2325 $ dom ->validateOnParse = false ;
2426 try {
2527 if ($ dom ->loadXML ($ string )) {
26- return $ asDomDocument ? $ dom : $ dom ->saveXML ();
28+ $ formated = $ dom ->saveXML ();
2729 }
2830 } catch (\Exception $ exception ) {
29- throw new \InvalidArgumentException (sprintf ( 'XML string is invalid ' ), null , $ exception );
31+ throw new \InvalidArgumentException ('XML string is invalid ' , $ exception -> getCode () , $ exception );
3032 }
3133 }
32- return $ asDomDocument ? null : $ string ;
34+ return $ asDomDocument ? $ dom : $ formated ;
3335 }
3436}
You can’t perform that action at this time.
0 commit comments