3
* This file contains the code for converting values between SOAP and PHP.
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.
14
* @category Web Services
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
25
require_once 'SOAP/Base.php';
30
* This class converts values between PHP and SOAP.
32
* Originally based on SOAPx4 by Dietrich Ayala
33
* http://dietrich.ganx4.com/soapx4
37
* @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
38
* @author Dietrich Ayala <dietrich@ganx4.com> Original Author
63
var $type_namespace = '';
65
var $attributes = array();
72
var $options = array();
80
* @param string $name Name of the SOAP value {namespace}name.
81
* @param mixed $type SOAP value {namespace}type. Determined
82
* automatically if not set.
83
* @param mixed $value Value to set.
84
* @param array $attributes Attributes.
86
function SOAP_Value($name = '', $type = false, $value = null,
87
$attributes = array())
89
// Detect type if not passed.
90
$this->nqn = new QName($name);
91
$this->name = $this->nqn->name;
92
$this->namespace = $this->nqn->namespace;
93
$this->tqn = new QName($type);
94
$this->type = $this->tqn->name;
95
$this->type_prefix = $this->tqn->ns;
96
$this->type_namespace = $this->tqn->namespace;
97
$this->value = $value;
98
$this->attributes = $attributes;
102
* Serializes this value.
104
* @param SOAP_Base $serializer A SOAP_Base instance or subclass to
107
* @return string XML representation of $this.
109
function serialize(&$serializer)
111
return $serializer->_serializeValue($this->value,
115
$this->type_namespace,
124
* This class converts values between PHP and SOAP. It is a simple wrapper
125
* around SOAP_Value, adding support for SOAP actor and mustunderstand
128
* Originally based on SOAPx4 by Dietrich Ayala
129
* http://dietrich.ganx4.com/soapx4
133
* @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
134
* @author Dietrich Ayala <dietrich@ganx4.com> Original Author
136
class SOAP_Header extends SOAP_Value
141
* @param string $name Name of the SOAP value {namespace}name.
142
* @param mixed $type SOAP value {namespace}type. Determined
143
* automatically if not set.
144
* @param mixed $value Value to set
145
* @param integer $mustunderstand Zero or one.
146
* @param mixed $attributes Attributes.
148
function SOAP_Header($name = '', $type, $value, $mustunderstand = 0,
149
$attributes = array())
151
if (!is_array($attributes)) {
152
$actor = $attributes;
153
$attributes = array();
156
parent::SOAP_Value($name, $type, $value, $attributes);
159
$this->attributes['SOAP-ENV:actor'] = $actor;
160
} elseif (!isset($this->attributes['SOAP-ENV:actor'])) {
161
$this->attributes['SOAP-ENV:actor'] = 'http://schemas.xmlsoap.org/soap/actor/next';
163
$this->attributes['SOAP-ENV:mustUnderstand'] = (int)$mustunderstand;
169
* This class handles MIME attachements per W3C's Note on Soap Attachements at
170
* http://www.w3.org/TR/SOAP-attachments
174
* @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
176
class SOAP_Attachment extends SOAP_Value
181
* @param string $name Name of the SOAP value <value_name>
182
* @param string $type The attachment's MIME type.
183
* @param string $filename The attachment's file name. Ignored if $file
185
* @param string $file The attachment data.
187
function SOAP_Attachment($name = '', $type = 'application/octet-stream',
188
$filename, $file = null)
190
parent::SOAP_Value($name, null, null);
192
$filedata = ($file === null) ? $this->_file2str($filename) : $file;
193
$filename = basename($filename);
194
if (PEAR::isError($filedata)) {
195
$this->options['attachment'] = $filedata;
199
$cid = md5(uniqid(time()));
201
$this->attributes['href'] = 'cid:' . $cid;
203
$this->options['attachment'] = array('body' => $filedata,
204
'disposition' => $filename,
205
'content_type' => $type,
206
'encoding' => 'base64',
211
* Returns the contents of the given file name as string.
215
* @param string $file_name The file location.
217
* @return string The file data or a PEAR_Error.
219
function _file2str($file_name)
221
if (!is_readable($file_name)) {
222
return PEAR::raiseError('File is not readable: ' . $file_name);
225
if (function_exists('file_get_contents')) {
226
return file_get_contents($file_name);
229
if (!$fd = fopen($file_name, 'rb')) {
230
return PEAR::raiseError('Could not open ' . $file_name);
232
$cont = fread($fd, filesize($file_name));