source: branches/version-2_11-dev/data/module/SOAP/Value.php @ 21299

Revision 21299, 8.7 KB checked in by Seasoft, 15 years ago (diff)

#1521 (PEAR::SOAP 配布と異なる部分がある)

  • 新しいバージョンの配布ファイルを上書きすることで解決

#1522 (PEAR::SOAP をバージョンアップ)

  • 0.11.0 -> 0.12.0
  • Property svn:eol-style set to LF
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
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 [email protected] so we can
12 * mail you a copy immediately.
13 *
14 * @category   Web Services
15 * @package    SOAP
16 * @author     Dietrich Ayala <[email protected]> Original Author
17 * @author     Shane Caraveo <[email protected]>   Port to PEAR and more
18 * @author     Chuck Hagenbuch <[email protected]>   Maintenance
19 * @author     Jan Schneider <[email protected]>       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
25require_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 <[email protected]> Conversion to PEAR and updates
38 * @author  Dietrich Ayala <[email protected]> Original Author
39 */
40class 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        if ($type) {
142            $this->tqn = new QName($type);
143            $this->type = $this->tqn->name;
144            $this->type_namespace = $this->tqn->namespace;
145        }
146        $this->value = $value;
147        $this->attributes = $attributes;
148        $this->options = $options;
149    }
150
151    /**
152     * Serializes this value.
153     *
154     * @param SOAP_Base $serializer  A SOAP_Base instance or subclass to
155     *                               serialize with.
156     *
157     * @return string  XML representation of $this.
158     */
159    function serialize(&$serializer)
160    {
161        return $serializer->_serializeValue($this->value,
162                                            $this->nqn,
163                                            $this->tqn,
164                                            $this->options,
165                                            $this->attributes,
166                                            $this->arrayType);
167    }
168
169}
170
171/**
172 * This class converts values between PHP and SOAP. It is a simple wrapper
173 * around SOAP_Value, adding support for SOAP actor and mustunderstand
174 * parameters.
175 *
176 * Originally based on SOAPx4 by Dietrich Ayala
177 * http://dietrich.ganx4.com/soapx4
178 *
179 * @access  public
180 * @package SOAP
181 * @author  Shane Caraveo <[email protected]> Conversion to PEAR and updates
182 * @author  Dietrich Ayala <[email protected]> Original Author
183 */
184class SOAP_Header extends SOAP_Value
185{
186    /**
187     * Constructor
188     *
189     * @param string $name             Name of the SOAP value {namespace}name.
190     * @param mixed $type              SOAP value {namespace}type. Determined
191     *                                 automatically if not set.
192     * @param mixed $value             Value to set
193     * @param integer $mustunderstand  Zero or one.
194     * @param mixed $attributes        Attributes.
195     */
196    function SOAP_Header($name = '', $type, $value, $mustunderstand = 0,
197                         $attributes = array())
198    {
199        if (!is_array($attributes)) {
200            $actor = $attributes;
201            $attributes = array();
202        }
203
204        parent::SOAP_Value($name, $type, $value, $attributes);
205
206        if (isset($actor)) {
207            $this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'] = $actor;
208        } elseif (!isset($this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'])) {
209            $this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'] = 'http://schemas.xmlsoap.org/soap/actor/next';
210        }
211        $this->attributes[SOAP_BASE::SOAPENVPrefix().':mustUnderstand'] = (int)$mustunderstand;
212    }
213
214}
215
216/**
217 * This class handles MIME attachements per W3C's Note on Soap Attachements at
218 * http://www.w3.org/TR/SOAP-attachments
219 *
220 * @access  public
221 * @package SOAP
222 * @author  Shane Caraveo <[email protected]> Conversion to PEAR and updates
223 */
224class SOAP_Attachment extends SOAP_Value
225{
226    /**
227     * Constructor.
228     *
229     * @param string $name      Name of the SOAP value <value_name>
230     * @param string $type      The attachment's MIME type.
231     * @param string $filename  The attachment's file name. Ignored if $file
232     *                          is provide.
233     * @param string $file      The attachment data.
234     * @param array $attributes Attributes.
235     */
236    function SOAP_Attachment($name = '', $type = 'application/octet-stream',
237                             $filename, $file = null, $attributes = null)
238    {
239        parent::SOAP_Value($name, null, null);
240
241        $filedata = $file === null ? $this->_file2str($filename) : $file;
242        $filename = basename($filename);
243        if (PEAR::isError($filedata)) {
244            $this->options['attachment'] = $filedata;
245            return;
246        }
247
248        $cid = md5(uniqid(time()));
249
250        $this->attributes = $attributes;
251        $this->attributes['href'] = 'cid:' . $cid;
252
253        $this->options['attachment'] = array('body' => $filedata,
254                                             'disposition' => $filename,
255                                             'content_type' => $type,
256                                             'encoding' => 'base64',
257                                             'cid' => $cid);
258    }
259
260    /**
261     * Returns the contents of the given file name as string.
262     *
263     * @access private
264     *
265     * @param string $file_name  The file location.
266     *
267     * @return string  The file data or a PEAR_Error.
268     */
269    function _file2str($file_name)
270    {
271        if (!is_readable($file_name)) {
272            return PEAR::raiseError('File is not readable: ' . $file_name);
273        }
274
275        if (function_exists('file_get_contents')) {
276            return file_get_contents($file_name);
277        }
278
279        if (!$fd = fopen($file_name, 'rb')) {
280            return PEAR::raiseError('Could not open ' . $file_name);
281        }
282        $cont = fread($fd, filesize($file_name));
283        fclose($fd);
284
285        return $cont;
286    }
287
288}
Note: See TracBrowser for help on using the repository browser.