<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.soap.wsdl">
    <title>WSDL Accessor</title>

    <note>
        <para>
            <classname>Zend_Soap_Wsdl</classname> class is used by
            <classname>Zend_Soap_Server</classname> component internally to operate with WSDL
            documents. Nevertheless, you could also use functionality provided by this class for
            your own needs. The <classname>Zend_Soap_Wsdl</classname> package contains both a parser
            and a builder of WSDL documents.
        </para>

        <para>
            If you don't plan to do this, you can skip this documentation section.
        </para>
    </note>

    <sect2 id="zend.soap.wsdl.constructor">
        <title>Zend_Soap_Wsdl constructor</title>

        <para>
            <classname>Zend_Soap_Wsdl</classname> constructor takes three parameters:

            <orderedlist>
                <listitem>
                    <simpara>
                        <varname>$name</varname> - name of the Web Service being described.
                    </simpara>
                </listitem>

                <listitem>
                    <simpara>
                        <varname>$uri</varname> - <acronym>URI</acronym> where the WSDL will be
                        available (could also be a reference to the file in the filesystem.)
                    </simpara>
                </listitem>

                <listitem>
                    <simpara>
                        <varname>$strategy</varname> - optional flag used to identify the strategy
                        for complex types (objects) detection. This was a boolean
                        <varname>$extractComplexTypes</varname> before version 1.7 and can still be
                        set as a boolean for backwards compatibility. By default the 1.6 detection
                        behaviour is set. To read more on complex type detection strategies go to
                        the section: <link linkend="zend.soap.wsdl.types.add_complex">Add complex
                            types</link>.
                    </simpara>
                </listitem>
            </orderedlist>
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.addmessage">
        <title>addMessage() method</title>

        <para>
            <methodname>addMessage($name, $parts)</methodname> method adds new message description
            to the WSDL document (/definitions/message element).
        </para>

        <para>
            Each message correspond to methods in terms of <classname>Zend_Soap_Server</classname>
            and <classname>Zend_Soap_Client</classname> functionality.
        </para>

        <para>
           <varname>$name</varname> parameter represents message name.
        </para>

        <para>
           <varname>$parts</varname> parameter is an array of message parts which describe
           <acronym>SOAP</acronym> call parameters. It's an associative array: 'part name' (SOAP
           call parameter name) =&gt; 'part type'.
        </para>

        <para>
            Type mapping management is performed using <methodname>addTypes()</methodname>,
            <methodname>addTypes()</methodname> and <methodname>addComplexType()</methodname>
            methods (see below).
        </para>

        <note>
            <para>
                Messages parts can use either 'element' or 'type' attribute for typing
                (see <ulink url="http://www.w3.org/TR/wsdl#_messages"/>).
            </para>

            <para>
                'element' attribute must refer to a corresponding element of data type definition.
                'type' attribute refers to a corresponding complexType entry.
            </para>

            <para>
                All standard XSD types have both 'element' and 'complexType' definitions
                (see <ulink url="http://schemas.xmlsoap.org/soap/encoding/"/>).
            </para>

            <para>
                All non-standard types, which may be added using
                <methodname>Zend_Soap_Wsdl::addComplexType()</methodname> method, are described
                using 'complexType' node of '/definitions/types/schema/' section of WSDL document.
            </para>

            <para>
                So <methodname>addMessage()</methodname> method always uses 'type' attribute to
                describe types.
            </para>
        </note>
    </sect2>

    <sect2 id="zend.soap.wsdl.add_port_type">
        <title>addPortType() method</title>

        <para>
            <methodname>addPortType($name)</methodname> method adds new port type to the WSDL
            document (/definitions/portType) with the specified port type name.
        </para>

        <para>
            It joins a set of Web Service methods defined in terms of
            <classname>Zend_Soap_Server</classname> implementation.
        </para>

        <para>
            See <ulink url="http://www.w3.org/TR/wsdl#_porttypes"/> for the details.
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.add_port_operation">
        <title>addPortOperation() method</title>

        <para>
            <methodname>addPortOperation($portType, $name, $input = false, $output = false, $fault
                = false)</methodname> method adds new port operation to the specified port type of
            the WSDL document (/definitions/portType/operation).
        </para>

        <para>
            Each port operation corresponds to a class method (if Web Service is based on a class)
            or function (if Web Service is based on a set of methods) in terms of
            <classname>Zend_Soap_Server</classname> implementation.
        </para>

        <para>
            It also adds corresponding port operation messages depending on specified
            <varname>$input</varname>, <varname>$output</varname> and <varname>$fault</varname>
            parameters.

            <note>
                <para>
                    <classname>Zend_Soap_Server</classname> component generates two messages for
                    each port operation while describing service based on
                    <classname>Zend_Soap_Server</classname> class:

                    <itemizedlist>
                        <listitem>
                            <para>
                                input message with name <code>$methodName . 'Request'</code>.
                            </para>
                        </listitem>

                        <listitem>
                            <para>
                                output message with name <code>$methodName . 'Response'</code>.
                            </para>
                        </listitem>
                    </itemizedlist>
                </para>
            </note>
        </para>

        <para>
            See <ulink url="http://www.w3.org/TR/wsdl#_request-response"/> for the details.
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.add_binding">
        <title>addBinding() method</title>

        <para>
            <methodname>addBinding($name, $portType)</methodname> method adds new binding to the
            WSDL document (/definitions/binding).
        </para>

        <para>
            'binding' WSDL document node defines message format and protocol details for operations
            and messages defined by a particular portType (see <ulink
                url="http://www.w3.org/TR/wsdl#_bindings"/>).
        </para>

        <para>
            The method creates binding node and returns it. Then it may be used to fill with actual
            data.
        </para>

        <para>
            <classname>Zend_Soap_Server</classname> implementation uses
            <code>$serviceName . 'Binding'</code> name for 'binding' element of WSDL document.
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.add_binding_operation">
        <title>addBindingOperation() method</title>

        <para>
            <methodname>addBindingOperation($binding, $name, $input = false, $output = false, $fault
                = false)</methodname> method adds an operation to a binding element
            (/definitions/binding/operation) with the specified name.
        </para>

        <para>
            It takes <code>XML_Tree_Node</code> object returned by
            <methodname>addBinding()</methodname> as an input (<varname>$binding</varname>
            parameter) to add 'operation' element with input/output/false entries depending on
            specified parameters
        </para>

        <para>
            <classname>Zend_Soap_Server</classname> implementation adds corresponding binding entry
            for each Web Service method with input and output entries defining 'soap:body' element
            as '&lt;soap:body use="encoded"
                encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/&gt;
        </para>

        <para>
            See <ulink url="http://www.w3.org/TR/wsdl#_bindings"/> for the details.
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.add_soap_binding">
        <title>addSoapBinding() method</title>

        <para>
            <methodname>addSoapBinding($binding, $style = 'document', $transport =
                'http://schemas.xmlsoap.org/soap/http')</methodname> method adds
            <acronym>SOAP</acronym> binding ('soap:binding') entry to the binding element (which is
            already linked to some port type) with the specified style and transport
            (Zend_Soap_Server implementation uses RPC style over <acronym>HTTP</acronym>).
        </para>

        <para>
            '/definitions/binding/soap:binding' element is used to signify that the binding is bound
            to the <acronym>SOAP</acronym> protocol format.
        </para>

        <para>
            See <ulink url="http://www.w3.org/TR/wsdl#_bindings"/> for the details.
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.add_soap_operation">
        <title>addSoapOperation() method</title>

        <para>
            <methodname>addSoapOperation($binding, $soap_action)</methodname> method adds
            <acronym>SOAP</acronym> operation ('soap:operation') entry to the binding element with
            the specified action. 'style' attribute of the 'soap:operation' element is not used
            since programming model (RPC-oriented or document-oriented) may be using
            <methodname>addSoapBinding()</methodname> method
        </para>

        <para>
            'soapAction' attribute of '/definitions/binding/soap:operation' element specifies the
            value of the <acronym>SOAP</acronym>Action header for this operation. This attribute is
            required for <acronym>SOAP</acronym> over <acronym>HTTP</acronym> and
            <emphasis>must not</emphasis> be specified for other transports.
        </para>

        <para>
            <classname>Zend_Soap_Server</classname> implementation uses
            <code>$serviceUri . '#' . $methodName</code> for <acronym>SOAP</acronym> operation
            action name.
        </para>

        <para>
            See <ulink url="http://www.w3.org/TR/wsdl#_soap:operation"/> for the details.
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.add_service">
        <title>addService() method</title>

        <para>
            <methodname>addService($name, $port_name, $binding, $location)</methodname> method adds
            '/definitions/service' element to the WSDL document with the specified Wed Service name,
            port name, binding, and location.
        </para>

        <para>
            WSDL 1.1 allows to have several port types (sets of operations) per service. This
            ability is not used by <classname>Zend_Soap_Server</classname> implementation and not
            supported by <classname>Zend_Soap_Wsdl</classname> class.
        </para>

        <para>
            <classname>Zend_Soap_Server</classname> implementation uses:

            <itemizedlist>
                <listitem>
                    <para>
                        <code>$name . 'Service'</code> as a Web Service name,
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <code>$name . 'Port'</code> as a port type name,
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <code>'tns:' . $name . 'Binding'</code>

                        <footnote>
                            <para>
                                <code>'tns:' namespace</code> is defined as script
                                <acronym>URI</acronym> (<code>'http://' .$_SERVER['HTTP_HOST']
                                    . $_SERVER['SCRIPT_NAME']</code>).
                            </para>
                        </footnote>

                        as binding name,
                    </para>
                </listitem>

                <listitem>
                    <para>
                        script <acronym>URI</acronym>

                        <footnote>
                            <para>
                                <code>'http://' .$_SERVER['HTTP_HOST'] .
                                    $_SERVER['SCRIPT_NAME']</code>
                            </para>
                        </footnote>

                        as a service URI for Web Service definition using classes.
                    </para>
                </listitem>
            </itemizedlist>

            where <varname>$name</varname> is a class name for the Web Service definition mode using
            class and script name for the Web Service definition mode using set of functions.
        </para>

        <para>
            See <ulink url="http://www.w3.org/TR/wsdl#_services"/> for the details.
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.types">
        <title>Type mapping</title>

        <para>
            <classname>Zend_Soap</classname> WSDL accessor implementation uses the following type
            mapping between <acronym>PHP</acronym> and <acronym>SOAP</acronym> types:

            <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>
                                By default <classname>Zend_Soap_Wsdl</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
                                the following way: If <constant>TRUE</constant>,
                                <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname>,
                                if <constant>FALSE</constant>
                                <classname>Zend_Soap_Wsdl_Strategy_AnyType</classname>.
                            </para>
                        </footnote>.
                    </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>

        <sect3 id="zend.soap.wsdl.types.retrieve">
            <title>Retrieving type information</title>

            <para>
                <methodname>getType($type)</methodname> method may be used to get mapping for a
                specified <acronym>PHP</acronym> type:
            </para>

            <programlisting language="php"><![CDATA[
...
$wsdl = new Zend_Soap_Wsdl('My_Web_Service', $myWebServiceUri);

...
$soapIntType = $wsdl->getType('int');

...
class MyClass {
    ...
}
...
$soapMyClassType = $wsdl->getType('MyClass');
]]></programlisting>
        </sect3>

        <sect3 id="zend.soap.wsdl.types.add_complex">
            <title>Adding complex type information</title>

            <para>
                <methodname>addComplexType($type)</methodname> method is used to add complex types
                (PHP classes) to a WSDL document.
            </para>

            <para>
                It's automatically used by <methodname>getType()</methodname> method to add
                corresponding complex types of method parameters or return types.
            </para>

            <para>
                Its detection and building algorithm is based on the currently active detection
                strategy for complex types. You can set the detection strategy either by specifying
                the class name as string or instance of a
                <classname>Zend_Soap_Wsdl_Strategy_Interface</classname> implementation as the third
                parameter of the constructor or using the
                <methodname>setComplexTypeStrategy($strategy)</methodname> function of
                <classname>Zend_Soap_Wsdl</classname>. The following detection strategies currently
                exist:
            </para>

            <itemizedlist>
                <listitem>
                    <para>
                        Class <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname>:
                        Enabled by default (when no third constructor parameter is set). Iterates
                        over the public attributes of a class type and registers them as subtypes of
                        the complex object type.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        Class <classname>Zend_Soap_Wsdl_Strategy_AnyType</classname>: Casts all
                        complex types into the simple XSD type xsd:anyType. Be careful this shortcut
                        for complex type detection can probably only be handled successfully by
                        weakly typed languages such as <acronym>PHP</acronym>.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        Class <classname>Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence</classname>:
                        This strategy allows to specify return parameters of the type:
                        <code>int[]</code> or <code>string[]</code>. As of Zend Framework version
                        1.9 it can handle both simple <acronym>PHP</acronym> types such as int,
                        string, boolean, float aswell as objects and arrays of objects.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        Class <classname>Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex</classname>:
                        This strategy allows to detect very complex arrays of objects. Objects types
                        are detected based on the
                        <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname> and an
                        array is wrapped around that definition.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        Class <classname>Zend_Soap_Wsdl_Strategy_Composite</classname>: This
                        strategy can combine all strategies by connecting <acronym>PHP</acronym>
                        Complex types (Classnames) to the desired strategy via the
                        <methodname>connectTypeToStrategy($type, $strategy)</methodname> method. A
                        complete typemap can be given to the constructor as an array with
                        <varname>$type</varname> -> <varname>$strategy</varname> pairs. The second
                        parameter specifies the default strategy that will be used if an unknown
                        type is requested for adding. This parameter defaults to the
                        <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname> strategy.
                    </para>
                </listitem>
            </itemizedlist>

            <para>
                <methodname>addComplexType()</methodname> method creates
                '/definitions/types/xsd:schema/xsd:complexType' element for
                each described complex type with name of the specified <acronym>PHP</acronym> class.
            </para>

            <para>
                Class property <emphasis>MUST</emphasis> have docblock section with the described
                <acronym>PHP</acronym> type to have property included into WSDL description.
            </para>

            <para>
                <methodname>addComplexType()</methodname> checks if type is already described within
                types section of the WSDL document.
            </para>

            <para>
                It prevents duplications if this method is called two or more times and recursion in
                the types definition section.
            </para>

            <para>
                See <ulink url="http://www.w3.org/TR/wsdl#_types"/> for the details.
            </para>
        </sect3>
    </sect2>

    <sect2 id="zend.soap.wsdl.add_documentation">
        <title>addDocumentation() method</title>

        <para>
            <methodname>addDocumentation($input_node, $documentation)</methodname> method adds human
            readable documentation using optional 'wsdl:document' element.
        </para>

        <para>
            '/definitions/binding/soap:binding' element is used to signify that the binding is bound
            to the <acronym>SOAP</acronym> protocol format.
        </para>

        <para>
            See <ulink url="http://www.w3.org/TR/wsdl#_documentation"/> for the details.
        </para>
    </sect2>

    <sect2 id="zend.soap.wsdl.retrieve">
        <title>Get finalized WSDL document</title>

        <para>
            <methodname>toXML()</methodname>, <methodname>toDomDocument()</methodname> and
            <methodname>dump($filename = false)</methodname> methods may be used to get WSDL
            document as an <acronym>XML</acronym>, DOM structure or a file.
        </para>
    </sect2>
</sect1>
