1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Stream\Data; |
6
|
|
|
|
7
|
|
|
class XMLConverter implements Converter |
8
|
|
|
{ |
9
|
|
|
public function convert($data, array $params = []): string |
10
|
|
|
{ |
11
|
|
|
return $this->xml_encode($data); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
private function xml_encode($data, \DOMNode $domElement = null, \DOMDocument $DOMDocument = null): string |
15
|
|
|
{ |
16
|
|
|
if ($DOMDocument === null) { |
17
|
|
|
$DOMDocument = new \DOMDocument(); |
18
|
|
|
$DOMDocument->formatOutput = true; |
19
|
|
|
$this->xml_encode(['data' => $data], $DOMDocument, $DOMDocument); |
20
|
|
|
return $DOMDocument->saveXML(); |
21
|
|
|
} |
22
|
|
|
// To cope with embedded objects |
23
|
|
|
if (is_object($data)) { |
24
|
|
|
$data = get_object_vars($data); |
25
|
|
|
} |
26
|
|
|
if (is_array($data)) { |
27
|
|
|
foreach ($data as $index => $mixedElement) { |
28
|
|
|
if (is_int($index)) { |
29
|
|
|
if ($index === 0) { |
30
|
|
|
$node = $domElement; |
31
|
|
|
} else { |
32
|
|
|
$node = $DOMDocument->createElement($domElement->tagName); |
33
|
|
|
$domElement->parentNode->appendChild($node); |
34
|
|
|
} |
35
|
|
|
} else { |
36
|
|
|
$plural = $DOMDocument->createElement($index); |
37
|
|
|
$domElement->appendChild($plural); |
|
|
|
|
38
|
|
|
$node = $plural; |
39
|
|
|
if (!(rtrim($index, 's') === $index)) { |
40
|
|
|
$singular = $DOMDocument->createElement(rtrim($index, 's')); |
41
|
|
|
$plural->appendChild($singular); |
42
|
|
|
$node = $singular; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->xml_encode($mixedElement, $node, $DOMDocument); |
47
|
|
|
} |
48
|
|
|
} else { |
49
|
|
|
$data = is_bool($data) ? ($data ? 'true' : 'false') : $data; |
50
|
|
|
$domElement->appendChild($DOMDocument->createTextNode($data)); |
51
|
|
|
} |
52
|
|
|
return ''; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.