File: Zend_Soap_Server.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (431 lines) | stat: -rw-r--r-- 14,931 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.soap.server">
    <title>Zend_Soap_Server</title>

    <para>
        <classname>Zend_Soap_Server</classname> class is intended to simplify Web Services server
        part development for <acronym>PHP</acronym> programmers.
    </para>

    <para>
        It may be used in WSDL or non-WSDL mode, and using classes or functions to define Web
        Service <acronym>API</acronym>.
    </para>

    <para>
        When <classname>Zend_Soap_Server</classname> component works in the WSDL mode, it uses
        already prepared WSDL document to define server object behavior and transport layer options.
    </para>

    <para>
        WSDL document may be auto-generated with functionality provided by <link
            linkend="zend.soap.autodiscovery.introduction">Zend_Soap_AutoDiscovery component</link>
        or should be constructed manually using <link
            linkend="zend.soap.wsdl"><classname>Zend_Soap_Wsdl</classname> class</link> or any other
        <acronym>XML</acronym> generating tool.
    </para>

    <para>
        If the non-WSDL mode is used, then all protocol options have to be set using options
        mechanism.
    </para>

    <sect2 id="zend.soap.server.constructor">
        <title>Zend_Soap_Server constructor</title>

        <para>
            <classname>Zend_Soap_Server</classname> constructor should be used a bit differently for
            WSDL and non-WSDL modes.
        </para>

        <sect3 id="zend.soap.server.constructor.wsdl_mode">
            <title>Zend_Soap_Server constructor for the WSDL mode</title>

            <para>
                <classname>Zend_Soap_Server</classname> constructor takes two optional parameters
                when it works in WSDL mode:

                <orderedlist>
                    <listitem>
                        <para>
                            <varname>$wsdl</varname>, which is an <acronym>URI</acronym> of a WSDL
                            file

                            <footnote>
                                <para>
                                    May be set later using <methodname>setWsdl($wsdl)</methodname>
                                    method.
                                </para>
                            </footnote>.
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            <varname>$options</varname> - options to create <acronym>SOAP</acronym>
                            server object

                            <footnote>
                                <para>
                                    Options may be set later using
                                    <methodname>setOptions($options)</methodname> method.
                                </para>
                            </footnote>.
                        </para>

                        <para>
                            The following options are recognized in the WSDL mode:

                            <itemizedlist>
                                <listitem>
                                    <para>
                                        'soap_version' ('soapVersion') - soap version to use
                                        (SOAP_1_1 or <acronym>SOAP</acronym>_1_2).
                                    </para>
                                </listitem>

                                <listitem>
                                    <para>
                                        'actor' - the actor <acronym>URI</acronym> for the server.
                                    </para>
                                </listitem>

                                <listitem>
                                    <para>
                                        'classmap' ('classMap') which can be used to map some WSDL
                                        types to <acronym>PHP</acronym> classes.
                                    </para>

                                    <para>
                                        The option must be an array with WSDL types as keys and
                                        names of <acronym>PHP</acronym> classes as values.
                                    </para>
                                </listitem>

                                <listitem>
                                    <para>
                                        'encoding' - internal character encoding (UTF-8 is always
                                        used as an external encoding).
                                    </para>
                                </listitem>

                                <listitem>
                                    <para>
                                        'wsdl' which is equivalent to
                                        <methodname>setWsdl($wsdlValue)</methodname> call.
                                    </para>
                                </listitem>
                            </itemizedlist>
                        </para>
                    </listitem>
                </orderedlist>
            </para>
        </sect3>

        <sect3 id="zend.soap.server.wsdl_mode">
            <title>Zend_Soap_Server constructor for the non-WSDL mode</title>

            <para>
                The first constructor parameter <emphasis>must</emphasis> be set to
                <constant>NULL</constant> if you plan to use <classname>Zend_Soap_Server</classname>
                functionality in non-WSDL mode.
            </para>

            <para>
                You also have to set 'uri' option in this case (see below).
            </para>

            <para>
                The second constructor parameter (<varname>$options</varname>) is an array with
                options to create <acronym>SOAP</acronym> server object

                <footnote>
                    <para>
                        Options may be set later using <methodname>setOptions($options)</methodname>
                        method.
                    </para>
                </footnote>.
            </para>

            <para>
                The following options are recognized in the non-WSDL mode:

                <itemizedlist>
                    <listitem>
                        <para>
                            'soap_version' ('soapVersion') - soap version to use (SOAP_1_1 or
                            <acronym>SOAP</acronym>_1_2).
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            'actor' - the actor <acronym>URI</acronym> for the server.
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            'classmap' ('classMap') which can be used to map some WSDL types to
                            <acronym>PHP</acronym> classes.
                        </para>

                        <para>
                            The option must be an array with WSDL types as keys and names of
                            <acronym>PHP</acronym> classes as values.
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            'encoding' - internal character encoding (UTF-8 is always used as an
                            external encoding).
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            'uri' (required) - <acronym>URI</acronym> namespace for
                            <acronym>SOAP</acronym> server.
                        </para>
                    </listitem>
                </itemizedlist>
            </para>
        </sect3>
    </sect2>

    <sect2 id="zend.soap.server.api_define_methods">
        <title>Methods to define Web Service API</title>

        <para>
            There are two ways to define Web Service <acronym>API</acronym> when your want to give
            access to your <acronym>PHP</acronym> code through <acronym>SOAP</acronym>.
        </para>

        <para>
            The first one is to attach some class to the <classname>Zend_Soap_Server</classname>
            object which has to completely describe Web Service <acronym>API</acronym>:
        </para>

        <programlisting language="php"><![CDATA[
...
class MyClass {
    /**
     * This method takes ...
     *
     * @param integer $inputParam
     * @return string
     */
    public function method1($inputParam) {
        ...
    }

    /**
     * This method takes ...
     *
     * @param integer $inputParam1
     * @param string  $inputParam2
     * @return float
     */
    public function method2($inputParam1, $inputParam2) {
        ...
    }

    ...
}
...
$server = new Zend_Soap_Server(null, $options);
// Bind Class to Soap Server
$server->setClass('MyClass');
// Bind already initialized object to Soap Server
$server->setObject(new MyClass());
...
$server->handle();
]]></programlisting>

        <note>
            <title>Important!</title>

            <para>
                You should completely describe each method using method docblock if you plan to
                use autodiscover functionality to prepare corresponding Web Service WSDL.
            </para>
        </note>

        <para>
            The second method of defining Web Service <acronym>API</acronym> is using set of
            functions and <methodname>addFunction()</methodname> or
            <methodname>loadFunctions()</methodname> methods:
        </para>

        <programlisting language="php"><![CDATA[
...
/**
 * This function ...
 *
 * @param integer $inputParam
 * @return string
 */
function function1($inputParam) {
    ...
}

/**
 * This function ...
 *
 * @param integer $inputParam1
 * @param string  $inputParam2
 * @return float
 */
function function2($inputParam1, $inputParam2) {
    ...
}
...
$server = new Zend_Soap_Server(null, $options);
$server->addFunction('function1');
$server->addFunction('function2');
...
$server->handle();
]]></programlisting>
    </sect2>

    <sect2 id="zend.soap.server.request_response">
        <title>Request and response objects handling</title>

        <note>
            <title>Advanced</title>

            <para>
                This section describes advanced request/response processing options and may be
                skipped.
            </para>
        </note>

        <para>
            <classname>Zend_Soap_Server</classname> component performs request/response processing
            automatically, but allows to catch it and do some pre- and post-processing.
        </para>

        <sect3 id="zend.soap.server.request_response.request">
            <title>Request processing</title>

            <para>
                <methodname>Zend_Soap_Server::handle()</methodname> method takes request from the
                standard input stream ('php://input'). It may be overridden either by supplying
                optional parameter to the <methodname>handle()</methodname> method or by setting
                request using <methodname>setRequest()</methodname> method:
            </para>

            <programlisting language="php"><![CDATA[
...
$server = new Zend_Soap_Server(...);
...
// Set request using optional $request parameter
$server->handle($request);
...
// Set request using setRequest() method
$server->setRequest();
$server->handle();
]]></programlisting>

            <para>
                Request object may be represented using any of the following:

                <itemizedlist>
                    <listitem>
                        <para>
                            DOMDocument (casted to <acronym>XML</acronym>)
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            DOMNode (owner document is grabbed and casted to <acronym>XML</acronym>)
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            SimpleXMLElement (casted to <acronym>XML</acronym>)
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            stdClass (__toString() is called and verified to be valid
                            <acronym>XML</acronym>)
                        </para>
                    </listitem>

                    <listitem>
                        <para>
                            string (verified to be valid <acronym>XML</acronym>)
                        </para>
                    </listitem>
                </itemizedlist>
            </para>

            <para>
                Last processed request may be retrieved using
                <methodname>getLastRequest()</methodname> method as an <acronym>XML</acronym>
                string:
            </para>

            <programlisting language="php"><![CDATA[
...
$server = new Zend_Soap_Server(...);
...
$server->handle();
$request = $server->getLastRequest();
]]></programlisting>
        </sect3>

        <sect3 id="zend.soap.server.request_response.response">
            <title>Response pre-processing</title>

            <para>
                <methodname>Zend_Soap_Server::handle()</methodname> method automatically emits
                generated response to the output stream. It may be blocked using
                <methodname>setReturnResponse()</methodname> with <constant>TRUE</constant> or
                <constant>FALSE</constant> as a parameter

                <footnote>
                    <para>
                        Current state of the Return Response flag may be requested with
                        <methodname>setReturnResponse()</methodname> method.
                    </para>
                </footnote>.

                Generated response is returned by <methodname>handle()</methodname> method in this
                case.
            </para>

            <programlisting language="php"><![CDATA[
...
$server = new Zend_Soap_Server(...);
...
// Get a response as a return value of handle() method
// instead of emitting it to the standard output
$server->setReturnResponse(true);
...
$response = $server->handle();
...
]]></programlisting>

            <para>
                Last response may be also retrieved by <methodname>getLastResponse()</methodname>
                method for some post-processing:
            </para>

            <programlisting language="php"><![CDATA[
...
$server = new Zend_Soap_Server(...);
...
$server->handle();
$response = $server->getLastResponse();
...
]]></programlisting>
        </sect3>
    </sect2>
</sect1>