Test Failed
Push — master ( 766481...9055ab )
by Stefan
07:01
created

ServerSideCredential::getAll()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 4
nop 0
dl 0
loc 11
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * *****************************************************************************
5
 * Contributions to this work were made on behalf of the GÉANT project, a 
6
 * project that has received funding from the European Union’s Framework 
7
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
8
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
9
 * 691567 (GN4-1) and No. 731122 (GN4-2).
10
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
11
 * of the copyright in all material which was developed by a member of the GÉANT
12
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
13
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
14
 * UK as a branch of GÉANT Vereniging.
15
 * 
16
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
17
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
18
 *
19
 * License: see the web/copyright.inc.php file in the file structure or
20
 *          <base_url>/copyright.php after deploying the software
21
 */
22
23
/**
24
 * This file contains class definitions and procedures for 
25
 * generation of a generic XML description of a 802.1x configurator
26
 *
27
 * @author Maja Górecka-Wolniewicz <[email protected]>
28
 *
29
 * @package ModuleWriting
30
 */
31
32
namespace devices\xml;
33
34
/**
35
 * 
36
 * @param \SimpleXMLElement $key   where to append the new element
37
 * @param \SimpleXMLElement $value the value to append
38
 * @return void
39
 */
40
function SimpleXMLElement_append($key, $value) {
41
    if (trim((string) $value) == '') {
42
        $element = $key->addChild($value->getName());
43
        foreach ($value->attributes() as $attKey => $attValue) {
44
            $element->addAttribute($attKey, $attValue);
45
        }
46
        foreach ($value->children() as $child) {
47
            SimpleXMLElement_append($element, $child);
48
        }
49
    } else {
50
        $key->addChild($value->getName(), trim((string) $value));
51
    }
52
}
53
54
/**
55
 * 
56
 * @param \SimpleXMLElement   $node   the XML node to marshal
57
 * @param EAPIdentityProvider $object the Object
58
 * @return void
59
 */
60
function marshalObject($node, $object) {
61
    $qualClassName = get_class($object);
62
    // remove namespace qualifier
63
    $pos = strrpos($qualClassName, '\\');
64
    $className = substr($qualClassName, $pos + 1);
65
    $name = preg_replace("/_/", "-", $className);
66
    if ($object->getValue()) {
67
        $val = preg_replace('/&/', '&amp;', $object->getValue());
68
        $childNode = $node->addChild($name, $val);
69
    } else {
70
        $childNode = $node->addChild($name);
71
    }
72
    if ($object->areAttributes()) {
73
        $attrs = $object->getAttributes();
74
        foreach ($attrs as $attrt => $attrv) {
75
            $childNode->addAttribute($attrt, $attrv);
76
        }
77
    }
78
    $fields = $object->getAll();
79
    if (empty($fields)) {
80
        return;
81
    }
82
    foreach ($fields as $name => $value) {
83
        if (is_scalar($value)) {
84
            $childNode->addChild($name, strval($value));
85
            continue;
86
        }
87
        if (gettype($value) == 'array') {
88
            foreach ($value as $insideValue) {
89
                if (is_object($insideValue)) {
90
                    marshalObject($childNode, $insideValue);
91
                }
92
            }
93
            continue;
94
        }
95
        if (gettype($value) == 'object') {
96
            marshalObject($childNode, $value);
97
        }
98
    }
99
}
100