XmlService::write()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 3
dl 0
loc 10
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * MÓDULO DE EMISIÓN ELECTRÓNICA F72X
5
 * UBL 2.1
6
 * Version 1.0
7
 * 
8
 * Copyright 2019, Jaime Cruz
9
 */
10
11
namespace F72X\Tools;
12
13
use Sabre\Xml\Service;
14
15
class XmlService extends Service {
16
17
    private $xmlVersion;
18
    private $xmlEncoding;
19
    private $xmlStandalone;
20
    private $xmlIndentString = '    ';
21
22
    public function __construct($xmlVersion = '1.0', $encoding = null, $standalone = null) {
23
        $this->xmlVersion = $xmlVersion;
24
        $this->xmlEncoding = $encoding;
25
        $this->xmlStandalone = $standalone;
26
    }
27
28
    public function write($rootElementName, $value, $contextUri = null) {
29
        $me = $this;
30
        $w = $this->getWriter();
31
        $w->openMemory();
32
        $w->contextUri = $contextUri;
33
        $w->setIndent(true);
34
        $w->setIndentString($me->xmlIndentString);
35
        $w->startDocument($me->xmlVersion, $me->xmlEncoding, $me->xmlStandalone);
36
        $w->writeElement($rootElementName, $value);
37
        return $w->outputMemory();
38
    }
39
40
}
41