File: Zend_Soap_AutoDiscovery.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 (435 lines) | stat: -rwxr-xr-x 17,066 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
432
433
434
435
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.soap.autodiscovery">
    <title>AutoDiscovery</title>

    <sect2 id="zend.soap.autodiscovery.introduction">
        <title>AutoDiscovery Introduction</title>

        <para>
            <acronym>SOAP</acronym> functionality implemented within Zend Framework is intended to
            make all steps required for <acronym>SOAP</acronym> communications more simple.
        </para>

        <para>
            <acronym>SOAP</acronym> is language independent protocol. So it may be used not only for
            <acronym>PHP</acronym>-to-PHP communications.
        </para>

        <para>
            There are three configurations for <acronym>SOAP</acronym> applications where Zend
            Framework may be utilized:

            <orderedlist>
                <listitem>
                    <simpara>
                        SOAP server <acronym>PHP</acronym> application &lt;---&gt;
                        <acronym>SOAP</acronym> client <acronym>PHP</acronym> application
                    </simpara>
                </listitem>

                <listitem>
                    <simpara>
                        SOAP server non-PHP application &lt;---&gt; <acronym>SOAP</acronym>
                        client <acronym>PHP</acronym> application
                    </simpara>
                </listitem>

                <listitem>
                    <simpara>
                        SOAP server <acronym>PHP</acronym> application &lt;---&gt;
                        <acronym>SOAP</acronym> client non-PHP application
                    </simpara>
                </listitem>
            </orderedlist>
        </para>

        <para>
            We always have to know, which functionality is provided by <acronym>SOAP</acronym>
            server to operate with it. <ulink url="http://www.w3.org/TR/wsdl">WSDL</ulink> is used
            to describe network service <acronym>API</acronym> in details.
        </para>

        <para>
            WSDL language is complex enough (see <ulink
                url="http://www.w3.org/TR/wsdl">http://www.w3.org/TR/wsdl</ulink>
            for the details). So it's difficult to prepare correct WSDL description.
        </para>

        <para>
            Another problem is synchronizing changes in network service <acronym>API</acronym> with
            already existing WSDL.
        </para>

        <para>
            Both these problem may be solved by WSDL autogeneration. A prerequisite for this is a
            <acronym>SOAP</acronym> server autodiscovery. It constructs object similar to object
            used in <acronym>SOAP</acronym> server application, extracts necessary information and
            generates correct WSDL using this information.
        </para>

        <para>
            There are two ways for using Zend Framework for <acronym>SOAP</acronym> server
            application:

            <itemizedlist>
                <listitem>
                    <para>Use separated class.</para>
                </listitem>

                <listitem>
                    <para>Use set of functions</para>
                </listitem>
            </itemizedlist>
        </para>

        <para>
            Both methods are supported by Zend Framework Autodiscovery functionality.
        </para>

        <para>
            The<classname>Zend_Soap_AutoDiscover</classname> class also supports datatypes mapping
            from <acronym>PHP</acronym> to <ulink
                url="http://www.w3.org/TR/xmlschema-2/">XSD types</ulink>.
        </para>

        <para>
            Here is an example of common usage of the autodiscovery functionality. The
            <methodname>handle()</methodname> function generates the WSDL file and posts it to the
            browser.
        </para>

        <programlisting language="php"><![CDATA[
class My_SoapServer_Class {
...
}

$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('My_SoapServer_Class');
$autodiscover->handle();
]]></programlisting>

        <para>
            If you need access to the generated WSDL file either to save it to a file or as an
            <acronym>XML</acronym> string you can use the <methodname>dump($filename)</methodname>
            or <methodname>toXml()</methodname> functions the AutoDiscover class provides.
        </para>

        <note id="zend.soap.autodiscovery.introduction.noserver">
            <title>Zend_Soap_Autodiscover is not a Soap Server</title>

            <para>
                It is very important to note, that the class
                <classname>Zend_Soap_AutoDiscover</classname> does not act as a
                <acronym>SOAP</acronym> Server on its own. It only generates the WSDL and serves it
                to anyone accessing the url it is listening on.
            </para>

            <para>
                As the <acronym>SOAP</acronym> Endpoint Uri is uses the default
                <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code>, but this
                can be changed with the <methodname>setUri()</methodname> function or the
                Constructor parameter of <classname>Zend_Soap_AutoDiscover</classname> class. The
                endpoint has to provide a <classname>Zend_Soap_Server</classname> that listens to
                requests.
            </para>

            <programlisting language="php"><![CDATA[
if(isset($_GET['wsdl'])) {
    $autodiscover = new Zend_Soap_AutoDiscover();
    $autodiscover->setClass('HelloWorldService');
    $autodiscover->handle();
} else {
    // pointing to the current file here
    $soap = new Zend_Soap_Server("http://example.com/soap.php?wsdl");
    $soap->setClass('HelloWorldService');
    $soap->handle();
}
]]></programlisting>
        </note>
    </sect2>

    <sect2 id="zend.soap.autodiscovery.class">
        <title>Class autodiscovering</title>

        <para>
            If class is used to provide SOAP server functionality, then the same class should be
            provided to <classname>Zend_Soap_AutoDiscover</classname> for WSDL generation:
        </para>

        <programlisting language="php"><![CDATA[
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('My_SoapServer_Class');
$autodiscover->handle();
]]></programlisting>

        <para>
            The following rules are used while WSDL generation:

            <itemizedlist>
                <listitem>
                    <para>Generated WSDL describes an RPC style Web Service.</para>
                </listitem>

                <listitem>
                    <para>Class name is used as a name of the Web Service being described.</para>
                </listitem>

                <listitem>
                    <para>
                        <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code> is
                        used as an <acronym>URI</acronym> where the WSDL is available by default but
                        can be overwritten via <methodname>setUri()</methodname> method.
                    </para>

                    <para>
                         It's also used as a target namespace for all service related names
                         (including described complex types).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        Class methods are joined into one <ulink
                            url="http://www.w3.org/TR/wsdl#_porttypes">Port Type</ulink>.
                    </para>

                    <para>
                        <code>$className . 'Port'</code> is used as Port Type name.
                    </para>
                </listitem>

                <listitem>
                    <para>Each class method is registered as a corresponding port operation.</para>
                </listitem>

                <listitem>
                    <para>
                        Each method prototype generates corresponding Request/Response messages.
                    </para>

                    <para>
                        Method may have several prototypes if some method parameters are optional.
                    </para>
                </listitem>
            </itemizedlist>
        </para>

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

            <para>
                WSDL autodiscovery utilizes the <acronym>PHP</acronym> docblocks provided by the
                developer to determine the parameter and return types. In fact, for scalar types,
                this is the only way to determine the parameter types, and for return types, this is
                the only way to determine them.
            </para>

            <para>
                That means, providing correct and fully detailed docblocks is not only best
                practice, but is required for discovered class.
            </para>
        </note>
    </sect2>

    <sect2 id="zend.soap.autodiscovery.functions">
        <title>Functions autodiscovering</title>

        <para>
            If set of functions are used to provide SOAP server functionality, then the same set
            should be provided to <classname>Zend_Soap_AutoDiscovery</classname> for WSDL
            generation:
        </para>

        <programlisting language="php"><![CDATA[
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->addFunction('function1');
$autodiscover->addFunction('function2');
$autodiscover->addFunction('function3');
...
$autodiscover->handle();
]]></programlisting>

        <para>
            The following rules are used while WSDL generation:

            <itemizedlist>
                <listitem>
                    <para>Generated WSDL describes an RPC style Web Service.</para>
                </listitem>

                <listitem>
                    <para>
                        Current script name is used as a name of the Web Service being described.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code> is
                        used as an <acronym>URI</acronym> where the WSDL is available.
                    </para>

                    <para>
                         It's also used as a target namespace for all service related names
                         (including described complex types).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        Functions are joined into one <ulink
                            url="http://www.w3.org/TR/wsdl#_porttypes">Port Type</ulink>.
                    </para>

                    <para>
                        <code>$functionName . 'Port'</code> is used as Port Type name.
                    </para>
                </listitem>

                <listitem>
                    <para>Each function is registered as a corresponding port operation.</para>
                </listitem>

                <listitem>
                    <para>
                        Each function prototype generates corresponding Request/Response messages.
                    </para>

                    <para>
                        Function may have several prototypes if some method parameters are optional.
                    </para>
                </listitem>
            </itemizedlist>
        </para>

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

            <para>
                WSDL autodiscovery utilizes the <acronym>PHP</acronym> docblocks provided by the
                developer to determine the parameter and return types. In fact, for scalar types,
                this is the only way to determine the parameter types, and for return types, this is
                the only way to determine them.
            </para>

            <para>
                That means, providing correct and fully detailed docblocks is not only best
                practice, but is required for discovered class.
            </para>
        </note>
    </sect2>

    <sect2 id="zend.soap.autodiscovery.datatypes">
        <title>Autodiscovering Datatypes</title>

        <para>
            Input/output datatypes are converted into network service types using the following
            mapping:

            <itemizedlist>
                <listitem>
                    <para>PHP strings &lt;-&gt; <code>xsd:string</code>.</para>
                </listitem>

                <listitem>
                    <para>PHP integers &lt;-&gt; <code>xsd:int</code>.</para>
                </listitem>

                <listitem>
                    <para>PHP floats and doubles &lt;-&gt; <code>xsd:float</code>.</para>
                </listitem>

                <listitem>
                    <para>PHP booleans &lt;-&gt; <code>xsd:boolean</code>.</para>
                </listitem>

                <listitem>
                    <para>PHP arrays &lt;-&gt; <code>soap-enc:Array</code>.</para>
                </listitem>

                <listitem>
                    <para>PHP object &lt;-&gt; <code>xsd:struct</code>.</para>
                </listitem>

                <listitem>
                    <para>
                        <acronym>PHP</acronym> class &lt;-&gt; based on complex type strategy (See:
                        <link linkend="zend.soap.wsdl.types.add_complex">this section</link>)

                        <footnote>
                            <para>
                                <classname>Zend_Soap_AutoDiscover</classname> will be created with
                                the
                                <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname>
                                class as detection algorithm for complex types. The first parameter
                                of the AutoDiscover constructor takes any complex type strategy
                                implementing
                                <classname>Zend_Soap_Wsdl_Strategy_Interface</classname> or a string
                                with the name of the class. For backwards compatibility with
                                <varname>$extractComplexType</varname> boolean variables are parsed
                                exactly like in <classname>Zend_Soap_Wsdl</classname>. See the
                                <link
                                    linkend="zend.soap.wsdl.types.add_complex"><classname>Zend_Soap_Wsdl</classname>
                                    manual on adding complex</link> types for more information.
                            </para>
                        </footnote>.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        type[] or object[] (ie. int[]) &lt;-&gt; based on complex type strategy
                    </para>
                </listitem>

                <listitem>
                    <para>PHP void &lt;-&gt; empty type.</para>
                </listitem>

                <listitem>
                    <para>
                        If type is not matched to any of these types by some reason, then
                        <code>xsd:anyType</code> is used.
                    </para>
                </listitem>
            </itemizedlist>

            Where <code>xsd:</code> is "http://www.w3.org/2001/XMLSchema" namespace,
            <code>soap-enc:</code> is a "http://schemas.xmlsoap.org/soap/encoding/" namespace,
            <code>tns:</code> is a "target namespace" for a service.
        </para>
    </sect2>

    <sect2 id="zend.soap.autodiscovery.wsdlstyles">
        <title>WSDL Binding Styles</title>

        <para>
            WSDL offers different transport mechanisms and styles. This affects the
            <code>soap:binding</code> and <code>soap:body</code> tags within the Binding
            section of WSDL. Different clients have different requirements as to what options
            really work. Therefore you can set the styles before you call any <code>setClass</code>
            or <code>addFunction</code> method on the AutoDiscover class.
        </para>

        <programlisting language="php"><![CDATA[
$autodiscover = new Zend_Soap_AutoDiscover();
// Default is 'use' => 'encoded' and
// 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'
$autodiscover->setOperationBodyStyle(
                    array('use' => 'literal',
                          'namespace' => 'http://framework.zend.com')
                );

// Default is 'style' => 'rpc' and
// 'transport' => 'http://schemas.xmlsoap.org/soap/http'
$autodiscover->setBindingStyle(
                    array('style' => 'document',
                          'transport' => 'http://framework.zend.com')
                );
...
$autodiscover->addFunction('myfunc1');
$autodiscover->handle();
]]></programlisting>
    </sect2>
</sect1>