source: tmp/version-2_5-test/data/module/SOAP/Value.php @ 18609

Revision 18609, 7.3 KB checked in by kajiwara, 14 years ago (diff)

正式版にナイトリービルド版をマージしてみるテスト

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 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
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 <shane@php.net> Conversion to PEAR and updates
38 * @author  Dietrich Ayala <dietrich@ganx4.com> Original Author
39 */
40class SOAP_Value
41{
42    /**
43     * @var string
44     */
45    var $value = null;
46
47    /**
48     * @var string
49     */
50    var $name = '';
51
52    /**
53     * @var string
54     */
55    var $type = '';
56
57    /**
58     * Namespace
59     *
60     * @var string
61     */
62    var $namespace = '';
63    var $type_namespace = '';
64
65    var $attributes = array();
66
67    /**
68     * @var string
69     */
70    var $arrayType = '';
71
72    var $options = array();
73
74    var $nqn;
75    var $tqn;
76
77    /**
78     * Constructor.
79     *
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.
85     */
86    function SOAP_Value($name = '', $type = false, $value = null,
87                        $attributes = array())
88    {
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;
99    }
100
101    /**
102     * Serializes this value.
103     *
104     * @param SOAP_Base $serializer  A SOAP_Base instance or subclass to
105     *                               serialize with.
106     *
107     * @return string  XML representation of $this.
108     */
109    function serialize(&$serializer)
110    {
111        return $serializer->_serializeValue($this->value,
112                                            $this->name,
113                                            $this->type,
114                                            $this->namespace,
115                                            $this->type_namespace,
116                                            $this->options,
117                                            $this->attributes,
118                                            $this->arrayType);
119    }
120
121}
122
123/**
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
126 * parameters.
127 *
128 * Originally based on SOAPx4 by Dietrich Ayala
129 * http://dietrich.ganx4.com/soapx4
130 *
131 * @access  public
132 * @package SOAP
133 * @author  Shane Caraveo <shane@php.net> Conversion to PEAR and updates
134 * @author  Dietrich Ayala <dietrich@ganx4.com> Original Author
135 */
136class SOAP_Header extends SOAP_Value
137{
138    /**
139     * Constructor
140     *
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.
147     */
148    function SOAP_Header($name = '', $type, $value, $mustunderstand = 0,
149                         $attributes = array())
150    {
151        if (!is_array($attributes)) {
152            $actor = $attributes;
153            $attributes = array();
154        }
155
156        parent::SOAP_Value($name, $type, $value, $attributes);
157
158        if (isset($actor)) {
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';
162        }
163        $this->attributes['SOAP-ENV:mustUnderstand'] = (int)$mustunderstand;
164    }
165
166}
167
168/**
169 * This class handles MIME attachements per W3C's Note on Soap Attachements at
170 * http://www.w3.org/TR/SOAP-attachments
171 *
172 * @access  public
173 * @package SOAP
174 * @author  Shane Caraveo <shane@php.net> Conversion to PEAR and updates
175 */
176class SOAP_Attachment extends SOAP_Value
177{
178    /**
179     * Constructor.
180     *
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
184     *                          is provide.
185     * @param string $file      The attachment data.
186     */
187    function SOAP_Attachment($name = '', $type = 'application/octet-stream',
188                             $filename, $file = null)
189    {
190        parent::SOAP_Value($name, null, null);
191
192        $filedata = ($file === null) ? $this->_file2str($filename) : $file;
193        $filename = basename($filename);
194        if (PEAR::isError($filedata)) {
195            $this->options['attachment'] = $filedata;
196            return;
197        }
198
199        $cid = md5(uniqid(time()));
200
201        $this->attributes['href'] = 'cid:' . $cid;
202
203        $this->options['attachment'] = array('body' => $filedata,
204                                             'disposition' => $filename,
205                                             'content_type' => $type,
206                                             'encoding' => 'base64',
207                                             'cid' => $cid);
208    }
209
210    /**
211     * Returns the contents of the given file name as string.
212     *
213     * @access private
214     *
215     * @param string $file_name  The file location.
216     *
217     * @return string  The file data or a PEAR_Error.
218     */
219    function _file2str($file_name)
220    {
221        if (!is_readable($file_name)) {
222            return PEAR::raiseError('File is not readable: ' . $file_name);
223        }
224
225        if (function_exists('file_get_contents')) {
226            return file_get_contents($file_name);
227        }
228
229        if (!$fd = fopen($file_name, 'rb')) {
230            return PEAR::raiseError('Could not open ' . $file_name);
231        }
232        $cont = fread($fd, filesize($file_name));
233        fclose($fd);
234
235        return $cont;
236    }
237
238}
Note: See TracBrowser for help on using the repository browser.