1 | <?php |
---|
2 | /** |
---|
3 | * This file contains the code for converting values between SOAP and PHP. |
---|
4 | * |
---|
5 | * PHP versions 4 and 5 |
---|
6 | * |
---|
7 | * LICENSE: This source file is subject to version 2.02 of the PHP license, |
---|
8 | * that is bundled with this package in the file LICENSE, and is available at |
---|
9 | * through the world-wide-web at http://www.php.net/license/2_02.txt. If you |
---|
10 | * did not receive a copy of the PHP license and are unable to obtain it |
---|
11 | * through the world-wide-web, please send a note to license@php.net so we can |
---|
12 | * mail you a copy immediately. |
---|
13 | * |
---|
14 | * @category Web Services |
---|
15 | * @package SOAP |
---|
16 | * @author Dietrich Ayala <dietrich@ganx4.com> Original Author |
---|
17 | * @author Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
---|
18 | * @author Chuck Hagenbuch <chuck@horde.org> Maintenance |
---|
19 | * @author Jan Schneider <jan@horde.org> Maintenance |
---|
20 | * @copyright 2003-2007 The PHP Group |
---|
21 | * @license http://www.php.net/license/2_02.txt PHP License 2.02 |
---|
22 | * @link http://pear.php.net/package/SOAP |
---|
23 | */ |
---|
24 | |
---|
25 | require_once 'SOAP/Base.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * SOAP::Value |
---|
29 | * |
---|
30 | * This class converts values between PHP and SOAP. |
---|
31 | * |
---|
32 | * Originally based on SOAPx4 by Dietrich Ayala |
---|
33 | * http://dietrich.ganx4.com/soapx4 |
---|
34 | * |
---|
35 | * @access public |
---|
36 | * @package SOAP |
---|
37 | * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates |
---|
38 | * @author Dietrich Ayala <dietrich@ganx4.com> Original Author |
---|
39 | */ |
---|
40 | class SOAP_Value |
---|
41 | { |
---|
42 | /** |
---|
43 | * The actual value. |
---|
44 | * |
---|
45 | * @var mixed |
---|
46 | */ |
---|
47 | var $value = null; |
---|
48 | |
---|
49 | /** |
---|
50 | * QName instance representing the value name. |
---|
51 | * |
---|
52 | * @var QName |
---|
53 | */ |
---|
54 | var $nqn; |
---|
55 | |
---|
56 | /** |
---|
57 | * The value name, without namespace information. |
---|
58 | * |
---|
59 | * @var string |
---|
60 | */ |
---|
61 | var $name = ''; |
---|
62 | |
---|
63 | /** |
---|
64 | * The namespace of the value name. |
---|
65 | * |
---|
66 | * @var string |
---|
67 | */ |
---|
68 | var $namespace = ''; |
---|
69 | |
---|
70 | /** |
---|
71 | * QName instance representing the value type. |
---|
72 | * |
---|
73 | * @var QName |
---|
74 | */ |
---|
75 | var $tqn; |
---|
76 | |
---|
77 | /** |
---|
78 | * The value type, without namespace information. |
---|
79 | * |
---|
80 | * @var string |
---|
81 | */ |
---|
82 | var $type = ''; |
---|
83 | |
---|
84 | /** |
---|
85 | * The namespace of the value type. |
---|
86 | * |
---|
87 | * @var string |
---|
88 | */ |
---|
89 | var $type_namespace = ''; |
---|
90 | |
---|
91 | /** |
---|
92 | * The type of the array elements, if this value is an array. |
---|
93 | * |
---|
94 | * @var string |
---|
95 | */ |
---|
96 | var $arrayType = ''; |
---|
97 | |
---|
98 | /** |
---|
99 | * A hash of additional attributes. |
---|
100 | * |
---|
101 | * @see SOAP_Value() |
---|
102 | * @var array |
---|
103 | */ |
---|
104 | var $attributes = array(); |
---|
105 | |
---|
106 | /** |
---|
107 | * List of encoding and serialization options. |
---|
108 | * |
---|
109 | * @see SOAP_Value() |
---|
110 | * @var array |
---|
111 | */ |
---|
112 | var $options = array(); |
---|
113 | |
---|
114 | /** |
---|
115 | * Constructor. |
---|
116 | * |
---|
117 | * @param string $name Name of the SOAP value {namespace}name. |
---|
118 | * @param mixed $type SOAP value {namespace}type. Determined |
---|
119 | * automatically if not set. |
---|
120 | * @param mixed $value Value to set. |
---|
121 | * @param array $attributes A has of additional XML attributes to be |
---|
122 | * added to the serialized value. |
---|
123 | * @param array $options A list of encoding and serialization options: |
---|
124 | * - 'attachment': array with information about |
---|
125 | * the attachment |
---|
126 | * - 'soap_encoding': defines encoding for SOAP |
---|
127 | * message part of a MIME encoded SOAP request |
---|
128 | * (default: base64) |
---|
129 | * - 'keep_arrays_flat': use the tag name |
---|
130 | * multiple times for each element when |
---|
131 | * passing in an array in literal mode |
---|
132 | * - 'no_type_prefix': supress adding of the |
---|
133 | * namespace prefix |
---|
134 | */ |
---|
135 | function SOAP_Value($name = '', $type = false, $value = null, |
---|
136 | $attributes = array(), $options = array()) |
---|
137 | { |
---|
138 | $this->nqn = new QName($name); |
---|
139 | $this->name = $this->nqn->name; |
---|
140 | $this->namespace = $this->nqn->namespace; |
---|
141 | $this->tqn = new QName($type); |
---|
142 | $this->type = $this->tqn->name; |
---|
143 | $this->type_namespace = $this->tqn->namespace; |
---|
144 | $this->value = $value; |
---|
145 | $this->attributes = $attributes; |
---|
146 | $this->options = $options; |
---|
147 | } |
---|
148 | |
---|
149 | /** |
---|
150 | * Serializes this value. |
---|
151 | * |
---|
152 | * @param SOAP_Base $serializer A SOAP_Base instance or subclass to |
---|
153 | * serialize with. |
---|
154 | * |
---|
155 | * @return string XML representation of $this. |
---|
156 | */ |
---|
157 | function serialize(&$serializer) |
---|
158 | { |
---|
159 | return $serializer->_serializeValue($this->value, |
---|
160 | $this->nqn, |
---|
161 | $this->tqn, |
---|
162 | $this->options, |
---|
163 | $this->attributes, |
---|
164 | $this->arrayType); |
---|
165 | } |
---|
166 | |
---|
167 | } |
---|
168 | |
---|
169 | /** |
---|
170 | * This class converts values between PHP and SOAP. It is a simple wrapper |
---|
171 | * around SOAP_Value, adding support for SOAP actor and mustunderstand |
---|
172 | * parameters. |
---|
173 | * |
---|
174 | * Originally based on SOAPx4 by Dietrich Ayala |
---|
175 | * http://dietrich.ganx4.com/soapx4 |
---|
176 | * |
---|
177 | * @access public |
---|
178 | * @package SOAP |
---|
179 | * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates |
---|
180 | * @author Dietrich Ayala <dietrich@ganx4.com> Original Author |
---|
181 | */ |
---|
182 | class SOAP_Header extends SOAP_Value |
---|
183 | { |
---|
184 | /** |
---|
185 | * Constructor |
---|
186 | * |
---|
187 | * @param string $name Name of the SOAP value {namespace}name. |
---|
188 | * @param mixed $type SOAP value {namespace}type. Determined |
---|
189 | * automatically if not set. |
---|
190 | * @param mixed $value Value to set |
---|
191 | * @param integer $mustunderstand Zero or one. |
---|
192 | * @param mixed $attributes Attributes. |
---|
193 | */ |
---|
194 | function SOAP_Header($name = '', $type, $value, $mustunderstand = 0, |
---|
195 | $attributes = array()) |
---|
196 | { |
---|
197 | if (!is_array($attributes)) { |
---|
198 | $actor = $attributes; |
---|
199 | $attributes = array(); |
---|
200 | } |
---|
201 | |
---|
202 | parent::SOAP_Value($name, $type, $value, $attributes); |
---|
203 | |
---|
204 | if (isset($actor)) { |
---|
205 | $this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'] = $actor; |
---|
206 | } elseif (!isset($this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'])) { |
---|
207 | $this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'] = 'http://schemas.xmlsoap.org/soap/actor/next'; |
---|
208 | } |
---|
209 | $this->attributes[SOAP_BASE::SOAPENVPrefix().':mustUnderstand'] = (int)$mustunderstand; |
---|
210 | } |
---|
211 | |
---|
212 | } |
---|
213 | |
---|
214 | /** |
---|
215 | * This class handles MIME attachements per W3C's Note on Soap Attachements at |
---|
216 | * http://www.w3.org/TR/SOAP-attachments |
---|
217 | * |
---|
218 | * @access public |
---|
219 | * @package SOAP |
---|
220 | * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates |
---|
221 | */ |
---|
222 | class SOAP_Attachment extends SOAP_Value |
---|
223 | { |
---|
224 | /** |
---|
225 | * Constructor. |
---|
226 | * |
---|
227 | * @param string $name Name of the SOAP value <value_name> |
---|
228 | * @param string $type The attachment's MIME type. |
---|
229 | * @param string $filename The attachment's file name. Ignored if $file |
---|
230 | * is provide. |
---|
231 | * @param string $file The attachment data. |
---|
232 | * @param array $attributes Attributes. |
---|
233 | */ |
---|
234 | function SOAP_Attachment($name = '', $type = 'application/octet-stream', |
---|
235 | $filename, $file = null, $attributes = null) |
---|
236 | { |
---|
237 | parent::SOAP_Value($name, null, null); |
---|
238 | |
---|
239 | $filedata = $file === null ? $this->_file2str($filename) : $file; |
---|
240 | $filename = basename($filename); |
---|
241 | if (PEAR::isError($filedata)) { |
---|
242 | $this->options['attachment'] = $filedata; |
---|
243 | return; |
---|
244 | } |
---|
245 | |
---|
246 | $cid = md5(uniqid(time())); |
---|
247 | |
---|
248 | $this->attributes = $attributes; |
---|
249 | $this->attributes['href'] = 'cid:' . $cid; |
---|
250 | |
---|
251 | $this->options['attachment'] = array('body' => $filedata, |
---|
252 | 'disposition' => $filename, |
---|
253 | 'content_type' => $type, |
---|
254 | 'encoding' => 'base64', |
---|
255 | 'cid' => $cid); |
---|
256 | } |
---|
257 | |
---|
258 | /** |
---|
259 | * Returns the contents of the given file name as string. |
---|
260 | * |
---|
261 | * @access private |
---|
262 | * |
---|
263 | * @param string $file_name The file location. |
---|
264 | * |
---|
265 | * @return string The file data or a PEAR_Error. |
---|
266 | */ |
---|
267 | function _file2str($file_name) |
---|
268 | { |
---|
269 | if (!is_readable($file_name)) { |
---|
270 | return PEAR::raiseError('File is not readable: ' . $file_name); |
---|
271 | } |
---|
272 | |
---|
273 | if (function_exists('file_get_contents')) { |
---|
274 | return file_get_contents($file_name); |
---|
275 | } |
---|
276 | |
---|
277 | if (!$fd = fopen($file_name, 'rb')) { |
---|
278 | return PEAR::raiseError('Could not open ' . $file_name); |
---|
279 | } |
---|
280 | $cont = fread($fd, filesize($file_name)); |
---|
281 | fclose($fd); |
---|
282 | |
---|
283 | return $cont; |
---|
284 | } |
---|
285 | |
---|
286 | } |
---|