-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.phpwsdlhash.php
180 lines (169 loc) · 4.63 KB
/
class.phpwsdlhash.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/*
PhpWsdl - Generate WSDL from PHP
Copyright (C) 2011 Andreas Müller-Saala, wan24.de
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, see <http://www.gnu.org/licenses/>.
*/
if(basename($_SERVER['SCRIPT_FILENAME'])==basename(__FILE__))
exit;
// This is my solution to swap hash arrays between client/server. The receiver
// has to rebuild the hash object in the way his programming language supports
// hash arrays. It's just an example solution. To use the types defined here,
// you have to include this file in your source using "require". This file has
// also to be in the list of files that are parsed by PhpWsdl.
//
// A sample unserialized PHP hash array (use the "Serialize" method on this):
//
// Array(
// 'a' => 'Value of a',
// 'b' => 'Value of b'
// )
//
// The resulting serialized array (return this):
//
// Array(
// PhpWsdlHash(
// 'key' => 'a',
// 'value' => 'Value of a'
// ),
// PhpWsdlHash(
// 'key' => 'b',
// 'value' => 'Value of b'
// )
// )
//
// The received serialized array (use the "Deserialize" method on this):
//
// Array(
// object(
// 'key' => 'a',
// 'value' => 'Value of a'
// ),
// object(
// 'key' => 'b',
// 'value' => 'Value of b'
// )
// )
//
// The value type must be unique within an hash array. You can return prepared
// types like StringHashArray, or you define your own ones. To serialize an
// hash array to the target type, use the PhpWsdlHashArrayBuilder class:
//
// return PhpWsdlHashArrayBuilder::Serialize($yourHashVariable);
//
// To deserialize an received object:
//
// $yourHashVariable=PhpWsdlHashArrayBuilder::Deserialize($receivedHashVariable);
//
// Tip: I prefer converting hashes into an INI formatted string. The string
// type is primitive, but it can contain complex information. In nearly every
// programming language you can work with the INI format with predefined
// classes - or it's very easy to write your own.
/**
* Key/Value pair types for string value type
*
* @pw_element string $key Key
* @pw_element string $value Value
* @pw_complex StringHash String hash array type
*/
/**
* @pw_complex arrayOfStringHash[] StringHash Array of string hash array types
*/
/**
* Key/Value pair types for int value type
*
* @pw_element string $key Key
* @pw_element int $value Value
* @pw_complex IntHash Int hash array type
*/
/**
* @pw_complex arrayOfIntHashArray[] IntHashArray Array of int hash array types
*/
/**
* Key/Value pair types for boolean value type
*
* @pw_element string $key Key
* @pw_element boolean $value Value
* @pw_complex BooleanHash Boolean hash array type
*/
/**
* @pw_complex arrayOfBooleanHashArray[] BooleanHashArray Array of boolean hash array types
*/
/**
* This class contains static methods to (de)serialize hash arrays
*
* @author Andreas Müller-Saala, wan24.de
*/
class PhpWsdlHashArrayBuilder{
/**
* Serialize an hash array
*
* @param array $hash The PHP hash array
* @return PhpWsdlHash[] The serialized array
*/
public static function Serialize($hash){
if(is_null($hash))
return null;
$res=Array();
$keys=array_keys($hash);
$i=-1;
$len=sizeof($keys);
while(++$i<$len)
$res[]=new PhpWsdlHash($keys[$i],$hash[$keys[$i]]);
return $res;
}
/**
* Deserialize an hash array
*
* @param array $arr The serialized array
* @return array The deserialized PHP hash array
*/
public static function Deserialize($arr){
if(is_null($arr))
return null;
$res=Array();
$i=-1;
$len=sizeof($arr);
while(++$i<$len)
$res[$arr[$i]->Key]=$arr[$i]->Value;
return $res;
}
}
/**
* This class simply holds a key/value pair
*
* @author Andreas Müller-Saala, wan24.de
*/
class PhpWsdlHash{
/**
* The key
*
* @var string
*/
public $Key;
/**
* The value
*
* @var mixed
*/
public $Value;
/**
* Constructor
*
* @ignore
* @param string $key The key
* @param mixed $value The value
*/
public function PhpWsdlHash($key,$value){
$this->Key=$key;
$this->Value=$value;
}
}