1 | <?php |
||
10 | class XmlStringFormatter implements FormatterInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private static $headers = [ |
||
16 | '/^application\/.*xml/', |
||
17 | ]; |
||
18 | |||
19 | /** |
||
20 | * @param string $header |
||
21 | * @return bool |
||
22 | */ |
||
23 | public static function isXmlHeader($header) |
||
33 | |||
34 | /** |
||
35 | * @param string $string |
||
36 | * @return bool |
||
37 | */ |
||
38 | public static function isXmlString($string) |
||
39 | { |
||
40 | $string = trim($string); |
||
41 | |||
42 | if (substr($string, 0, 1) === '<' && substr($string, -1, 1) === '>') { |
||
43 | try { |
||
44 | $dom = new \DOMDocument('1.0'); |
||
45 | $dom->validateOnParse = true; |
||
46 | return $dom->loadXML($string) !== false; |
||
47 | } catch (\Exception $e) { |
||
|
|||
48 | |||
49 | } |
||
50 | } |
||
51 | |||
52 | return false; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param string $xml |
||
57 | * @return string |
||
58 | * @throws FormatterException |
||
59 | */ |
||
60 | public function format($xml) |
||
73 | } |
||
74 |