generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MedidocXMLService.php
56 lines (43 loc) · 1.21 KB
/
MedidocXMLService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Smartprax\Medidoc\XML;
use Sabre\Xml\Writer;
use Smartprax\Medidoc\Methods\AbstractMethod;
use Smartprax\Medidoc\XML\Nodes\Body;
use Smartprax\Medidoc\XML\Nodes\Envelope;
class MedidocXMLService extends Writer
{
public function __construct()
{
$this->openMemory();
$this->setIndent(true);
$this->startDocument('1.0', 'UTF-8');
$this->initNamespacesMap();
}
private function initNamespacesMap()
{
foreach (XML_NS::cases() as $namespace) {
$this->namespaceMap[$namespace->value] = $namespace->name;
}
}
public static function forMethod(AbstractMethod $method) : self
{
$instance = new self();
$instance->writeElement(XML_NS::envelope->node('Envelope'), [
new Envelope($method),
new Body($method),
]);
return $instance;
}
public function prettyPrint() : string
{
$dom = new \DOMDocument('1.0');
$dom->preserveWhiteSpace = true;
$dom->formatOutput = true;
$dom->loadXML($this->outputMemory());
return $dom->saveXML();
}
public function __toString(): string
{
return $this->outputMemory();
}
}