Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
//
3
// +----------------------------------------------------------------------+
4
// | PHP Version 4                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2003 The PHP Group                                |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.02 of the PHP license,      |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available at through the world-wide-web at                           |
11
// | http://www.php.net/license/2_02.txt.                                 |
12
// | If you did not receive a copy of the PHP license and are unable to   |
13
// | obtain it through the world-wide-web, please send a note to          |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
16
// | Authors: Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more   |
17
// | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author         |
18
// +----------------------------------------------------------------------+
19
//
20
// $Id: Value.php 696 2011-09-08 09:08:23Z tiefland $
21
//
22
require_once 'PayPal/SOAP/Base.php';
23
 
24
/**
25
 * SOAP::Value
26
 *
27
 * This class converts values between PHP and SOAP.
28
 *
29
 * Originally based on SOAPx4 by Dietrich Ayala
30
 * http://dietrich.ganx4.com/soapx4
31
 *
32
 * @access public
33
 * @package SOAP::Client
34
 * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
35
 * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
36
 */
37
class SOAP_Value
38
{
39
    /**
40
     *
41
     *
42
     * @var  string
43
     */
44
    var $value = null;
45
 
46
    /**
47
     *
48
     * @var  string
49
     */
50
    var $name = '';
51
 
52
    /**
53
     *
54
     * @var  string
55
     */
56
    var $type = '';
57
 
58
    /**
59
     * Namespace
60
     *
61
     * @var  string
62
     */
63
    var $namespace = '';
64
    var $type_namespace = '';
65
 
66
    var $attributes = array();
67
 
68
    /**
69
     *
70
     * @var string
71
     */
72
    var $arrayType = '';
73
 
74
    var $options = array();
75
 
76
    var $nqn;
77
    var $tqn;
78
 
79
    /**
80
     * Constructor.
81
     *
82
     * @param string $name        name of the soap-value {namespace}name
83
     * @param mixed  $type        soap value {namespace}type, if not set an automatic
84
     * @param mixed  $value       value to set
85
     * @param array  $attributes  (optional) Attributes.
86
     */
87
    function SOAP_Value($name = '', $type = false, $value = null, $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
     * Serialize.
103
     *
104
     * @param SOAP_Base &$serializer  A SOAP_Base instance or subclass to serialize with.
105
     *
106
     * @return string  XML representation of $this.
107
     */
108
    function serialize(&$serializer)
109
    {
110
        return $serializer->_serializeValue($this->value, $this->name, $this->type, $this->namespace, $this->type_namespace, $this->options, $this->attributes, $this->arrayType);
111
    }
112
 
113
}
114
 
115
/**
116
 * SOAP::Header
117
 *
118
 * This class converts values between PHP and SOAP. It is a simple
119
 * wrapper around SOAP_Value, adding support for SOAP actor and
120
 * mustunderstand parameters.
121
 *
122
 * Originally based on SOAPx4 by Dietrich Ayala
123
 * http://dietrich.ganx4.com/soapx4
124
 *
125
 * @access public
126
 * @package SOAP::Header
127
 * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
128
 * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
129
 */
130
class SOAP_Header extends SOAP_Value
131
{
132
    /**
133
     * Constructor
134
     *
135
     * @param string  $name            name of the soap-value {namespace}name
136
     * @param mixed   $type            soap value {namespace}type, if not set an automatic
137
     * @param mixed   $value           value to set
138
     * @param integer $mustunderstand  Zero or one.
139
     * @param mixed   $attributes      (optional) Attributes.
140
     */
141
    function SOAP_Header($name = '', $type, $value,
142
                         $mustunderstand = 0,
143
                         $attributes = array())
144
    {
145
        if (!is_array($attributes)) {
146
            $actor = $attributes;
147
            $attributes = array();
148
        }
149
 
150
        parent::SOAP_Value($name, $type, $value, $attributes);
151
 
152
        if (isset($actor)) {
153
            $this->attributes['SOAP-ENV:actor'] = $actor;
154
        } elseif (!isset($this->attributes['SOAP-ENV:actor'])) {
155
            $this->attributes['SOAP-ENV:actor'] = 'http://schemas.xmlsoap.org/soap/actor/next';
156
        }
157
        $this->attributes['SOAP-ENV:mustUnderstand'] = (int)$mustunderstand;
158
    }
159
 
160
}
161
 
162
/**
163
 * SOAP::Attachment
164
 * this class converts values between PHP and SOAP
165
 * it handles Mime attachements per W3C Note on Soap Attachements at
166
 * http://www.w3.org/TR/SOAP-attachments
167
 *
168
 *
169
 * @access public
170
 * @package SOAP::Attachment
171
 * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
172
 */
173
class SOAP_Attachment extends SOAP_Value
174
{
175
    /**
176
     * Constructor
177
     *
178
     * @param    string  name of the soap-value <value_name>
179
     * @param    mixed   soap header value
180
     * @param    string namespace
181
     */
182
    function SOAP_Attachment($name = '', $type = 'application/octet-stream',
183
                             $filename, $file = null)
184
    {
185
        global $SOAP_options;
186
        if (!isset($SOAP_options['Mime'])) {
187
            return PEAR::raiseError('Mail_mime is not installed, unable to support SOAP Attachements');
188
        }
189
        parent::SOAP_Value($name, null, null);
190
 
191
        $filedata = ($file === null) ? $this->_file2str($filename) : $file;
192
        $filename = basename($filename);
193
        if (PEAR::isError($filedata)) {
194
            return $filedata;
195
        }
196
 
197
        $cid = md5(uniqid(time()));
198
 
199
        $this->attributes['href'] = 'cid:'.$cid;
200
 
201
        $this->options['attachment'] = array(
202
                                'body'     => $filedata,
203
                                'disposition'     => $filename,
204
                                'content_type'   => $type,
205
                                'encoding' => 'base64',
206
                                'cid' => $cid
207
                               );
208
    }
209
 
210
    /**
211
     * Returns the contents of the given file name as string
212
     * @param string $file_name
213
     * @return string
214
     * @acces private
215
     */
216
    function &_file2str($file_name)
217
    {
218
        if (!is_readable($file_name)) {
219
            return PEAR::raiseError('File is not readable ' . $file_name);
220
        }
221
        if (!$fd = fopen($file_name, 'rb')) {
222
            return PEAR::raiseError('Could not open ' . $file_name);
223
        }
224
        $cont = fread($fd, filesize($file_name));
225
        fclose($fd);
226
        return $cont;
227
    }
228
 
229
}