Completed
Branch 0.2.3 (4e241d)
by Anton
15:52 queued 09:37
created

XML::string()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace {
4
5
	abstract class XML {
6
7
		# Create XML object
8
9
		public static function create(string $data) {
10
11
			$data = ('<?xml version="1.0" encoding="UTF-8" ?>' . $data);
12
13
			return @simplexml_load_string($data);
14
		}
15
16
		# Convert XML object to string
17
18
		public static function string(SimpleXMLElement $xml) {
19
20
			if (false === ($xml = dom_import_simplexml($xml))) return '';
21
22
			$dom = $xml->ownerDocument; $dom->formatOutput = true;
23
24
			# ------------------------
25
26
			return $dom->saveXML();
27
		}
28
29
		# Output XML data
30
31
		public static function output(SimpleXMLElement $xml) {
32
33
			Headers::nocache(); Headers::content(MIME_TYPE_XML);
34
35
			echo self::string($xml);
36
		}
37
	}
38
}
39