-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEWSType.php
76 lines (70 loc) · 1.82 KB
/
EWSType.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Base class for Exchange Web Service Types
*
* @author James I. Armes <http://www.jamesarmes.net>
* @author Michal Korzeniowski <[email protected]>
*
*/
abstract class EWSType {
/**
* Schema definition for the type object
*
* @var array
*/
protected $schema = array();
/**
* Constructor
*/
public abstract function __construct();
/*
According to specific of organization process of SOAP class in PHP5,
* we must wrap up complex objects in SoapVar class. Otherwise objects
* would not be encoded properly and could not be loaded on remote
* SOAP handler.
*
*/
public function getAsSOAP() {
$this->recursive_unset($this,"schema");
//print_r($this);
foreach($this as $key=>&$value) {
$this->prepareSOAPrecursive($this->$key);
}
return $this;
}
private function prepareSOAPrecursive(&$element) {
if(is_array($element)) {
foreach($element as $key=>&$val) {
$this->prepareSOAPrecursive($val);
}
$element=new SoapVar($element,SOAP_ENC_ARRAY);
$element = $element->enc_value;
}elseif(is_object($element)) {
if($element instanceof SOAPable) {
$element->getAsSOAP();
}
$element=new SoapVar($element,SOAP_ENC_OBJECT);
$element = $element->enc_value;
}
}
/*
* Recursively unset field from array or object
*/
private function recursive_unset(&$object, $unwanted_key) {
if(is_object($object)){
unset($object->$unwanted_key);
foreach ($object as &$value) {
if (is_object($value) || is_array($value)) {
$this->recursive_unset($value, $unwanted_key);
}
}
}elseif(is_array($object)){
unset($object[$unwanted_key]);
foreach ($object as &$value) {
if (is_array($value) || is_object($value)) {
$this->recursive_unset($value, $unwanted_key);
}
}
}
}
} // end class EWSType