forked from TribeHR/AppDirect-PHP-Wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDirectBase.php
43 lines (38 loc) · 1.05 KB
/
AppDirectBase.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
<?php
//Base class for AppDirect Data Objects.
class AppDirectBase {
public function __construct(SimpleXMLElement $xml = null)
{
if ($xml) {
//Load object dynamically and convert SimpleXMLElements into strings
foreach($xml as $key => $element)
{
if(count($element) > 0)
$this->$key = new AppDirectBase($element);
else
$this->$key = (string)$element;
}
}
}
public function getXMLObject(&$xml = null) {
if ($xml === null) {
$xml = simplexml_load_string(sprintf("<?xml version='1.0' encoding='utf-8'?><%s></%s>", $this->getName(), $this->getName()));
}
foreach (get_object_vars($this) as $key=>$val) {
if ($key != 'connector') {
if (is_object($val) && method_exists($val, "getXMLObject")) {
$node = $xml->addChild($key);
$val->getXMLObject($node);
} elseif ($val !== null) {
$xml->addChild($key,htmlentities($val, ENT_QUOTES));
}
}
}
return $xml;
}
public function getXML() {
$xml = $this->getXMLObject();
return $xml->asXML();
}
}
?>