示例#1
0
文件: wsf_utils.php 项目: ztobs/wsf
/**
 * Function to write 'sig model' for a given wsdl   
 * $wsdl_location location of the WSDL
 * returns none
 */
function wsf_wsdl2sig($wsdl_location)
{
    require_once 'dynamic_invocation/wsf_wsdl_consts.php';
    require_once 'dynamic_invocation/wsf_wsdl_util.php';
    global $written_classes;
    global $operations;
    $code = "";
    $wsdl_dom = new DomDocument();
    $sig_model_dom = new DOMDocument();
    $xslt_location = "./xslt/";
    $sig_model_dom->preserveWhiteSpace = false;
    $wsdl_dom->preserveWhiteSpace = false;
    if (!$wsdl_location) {
        echo "WSDL is not found";
        return NULL;
    }
    $is_multiple_interfaces = FALSE;
    // load WSDL as DOM
    if (!$wsdl_dom->load($wsdl_location)) {
        echo "WSDL could not be loaded.";
        return NULL;
    }
    $wsdl_dom->preserveWhiteSpace = false;
    // changing code for processing mutiple port types in wsdl 1.1
    $is_multiple_interfaces = wsf_is_mutiple_port_types($wsdl_dom);
    if ($is_multiple_interfaces == FALSE) {
        $wsdl_dom = wsf_get_wsdl_dom($wsdl_dom, $xslt_location);
        if (!$wsdl_dom) {
            echo "Error creating WSDL DOM document";
            return NULL;
        }
        $wsdl_dom = wsf_clear_wsdl_imports($wsdl_dom);
        $sig_model_dom = wsf_get_sig_model_dom($wsdl_dom, $xslt_location);
    } else {
        $wsdl_dom = wsf_clear_wsdl_imports($wsdl_dom);
        $wsdl_dom = wsf_get_wsdl_dom($wsdl_dom, $xslt_location);
        $sig_model_dom = wsf_process_multiple_interfaces($wsdl_dom, $sig_model_dom, $xslt_location);
    }
    if (!$sig_model_dom) {
        echo "Error creating intermediate service operations signature model";
        return NULL;
    }
    echo $sig_model_dom->saveXML();
}
示例#2
0
/**
 * Function to write classes. Does the WSDL to PHP conversion using a 'sig model'.  
 * $wsdl_location location of the WSDL
 * returns code segment corresponding to classes as a string
 */
function wsf_wsdl2php($wsdl_location)
{
    require_once 'dynamic_invocation/wsf_wsdl_consts.php';
    require_once 'dynamic_invocation/wsf_wsdl_util.php';
    global $written_classes;
    global $operations;
    global $actions;
    $written_classes[WSF_XSD_ANYTYPE] = TRUE;
    $code = "";
    $wsdl_dom = new DomDocument();
    $sig_model_dom = new DOMDocument();
    $xslt_location = "./xslt/";
    $sig_model_dom->preserveWhiteSpace = false;
    $wsdl_dom->preserveWhiteSpace = false;
    if (!$wsdl_location) {
        echo "WSDL is not found";
        return NULL;
    }
    $is_multiple_interfaces = FALSE;
    // load WSDL as DOM
    if (!$wsdl_dom->load($wsdl_location)) {
        echo "WSDL could not be loaded.";
        return NULL;
    }
    $wsdl_dom->preserveWhiteSpace = false;
    // changing code for processing mutiple port types in wsdl 1.1
    $is_multiple_interfaces = wsf_is_mutiple_port_types($wsdl_dom);
    $is_wsdl_11 = $wsdl_11_dom = NULL;
    if ($is_multiple_interfaces == FALSE) {
        //wsdl1.1 to wsdl2 conversion
        $wsdl_dom = wsf_get_wsdl_dom($wsdl_dom, $wsdl_location, $is_wsdl_11, $wsdl_11_dom);
        if (!$wsdl_dom) {
            echo "Error creating WSDL DOM document";
            return NULL;
        }
        $sig_model_dom = wsf_get_sig_model_dom($wsdl_dom);
    } else {
        //wsdl1.1 to wsdl2 conversion
        $wsdl_dom = wsf_get_wsdl_dom($wsdl_dom, $wsdl_location, $is_wsdl_11, $wsdl_11_dom);
        $sig_model_dom = wsf_process_multiple_interfaces($wsdl_dom, $sig_model_dom);
    }
    if (!$sig_model_dom) {
        echo "Error creating intermediate service operations signature model";
        return NULL;
    }
    // get the list of operations
    $op_nodes = $sig_model_dom->getElementsByTagName(WSF_OPERATION);
    // process each operation
    foreach ($op_nodes as $op_node) {
        // get operation name
        $op_attr = $op_node->attributes;
        if ($op_attr == NULL || $op_attr->getNamedItem(WSF_NAME) == NULL) {
            continue;
        }
        $op_name = $op_attr->getNamedItem(WSF_NAME)->value;
        if (array_key_exists($op_name, $operations) == FALSE || $operations[$op_name] == NULL) {
            // it operation is already found in an earlier parse, should not re-set it
            $operations[$op_name] = array();
            $operations[$op_name][WSF_CLIENT] = "";
            $operations[$op_name][WSF_SERVICE] = "";
        } else {
            continue;
            //no need to record same operation multiple times
        }
        // get the nodes describing operation characteristics
        $op_child_list = $op_node->childNodes;
        //first we have to have a good idea about headers, so processing headers first
        $in_headers = 0;
        $out_headers = 0;
        $in_header_objects = array();
        $in_header_objects[WSF_CLIENT] = "";
        $in_header_objects[WSF_SERVICE] = "";
        $out_header_objects = array();
        $out_header_objects[WSF_CLIENT] = "";
        $out_header_objects[WSF_SERVICE] = "";
        $service_function_doc_comment = "";
        $service_function_doc_comment .= "/**\n";
        $service_function_doc_comment .= " * Service function {$op_name}\n";
        // doc comments for input types
        foreach ($op_child_list as $op_child) {
            // process the signature node
            if ($op_child->nodeName == WSF_SIGNATURE) {
                // get the nodes representing operation parameters and return types within signature
                $param_list = $op_child->childNodes;
                foreach ($param_list as $param_node) {
                    if ($param_node) {
                        // look for params and returns nodes
                        if ($param_node->nodeName == WSF_PARAMS) {
                            if ($param_node->hasAttributes()) {
                                // Wrapper element
                                $params_attr = $param_node->attributes;
                                // get wrapper element name, this is going to be the class name
                                $ele_name = $params_attr->getNamedItem(WSF_WRAPPER_ELEMENT)->value;
                                $service_function_doc_comment .= " * @param object of {$ele_name} \$input \n";
                            } else {
                                // No wrapper element, there won't be any class generated for this
                                $child_array = array();
                                $param_child_list = $param_node->childNodes;
                                foreach ($param_child_list as $param_child) {
                                    $param_attr = $param_child->attributes;
                                    $ele_name = $param_attr->getNamedItem(WSF_NAME)->value;
                                    $content_model = "";
                                    if ($param_attr->getNamedItem(WSF_CONTENT_MODEL)) {
                                        $content_model = $param_attr->getNamedItem(WSF_CONTENT_MODEL)->value;
                                    }
                                    $param_type = $param_attr->getNamedItem(WSF_TYPE)->value;
                                    if ($content_model == WSF_SIMPLE_CONTENT) {
                                        $service_function_doc_comment .= " * @param object of {$ele_name} \$input \n";
                                    } else {
                                        $service_function_doc_comment .= " * @param {$param_type} \$input \n";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        foreach ($op_child_list as $op_child) {
            if ($op_child->nodeName == WSF_W2P_BINDING_DETAILS) {
                $op_binding_childs = $op_child->childNodes;
                foreach ($op_binding_childs as $op_binding_child) {
                    if ($op_binding_child->nodeName == WSF_SOAPHEADER) {
                        if ($op_binding_child->attributes->getNamedItem(WSF_HEADER_FOR_ATTRIBUTE)) {
                            if ($op_binding_child->attributes->getNamedItem(WSF_HEADER_FOR_ATTRIBUTE)->value == WSF_WSDL_OUTPUT) {
                                $direction = WSF_WSDL_OUTPUT;
                            } else {
                                $direction = WSF_WSDL_INPUT;
                            }
                        } else {
                            $direction = WSF_WSDL_INPUT;
                        }
                    }
                    if ($op_binding_child->attributes->getNamedItem(WSF_TYPE)) {
                        $param_node = $op_binding_child->firstChild;
                        if ($param_node && $param_node->attributes->getNamedItem(WSF_TYPE)) {
                            $class_name = $param_node->attributes->getNamedItem(WSF_TYPE)->value;
                            if ($direction == WSF_WSDL_INPUT) {
                                if ($param_node->attributes && $param_node->attributes->getNamedItem(WSF_WSDL_SIMPLE) && $param_node->attributes->getNamedItem(WSF_WSDL_SIMPLE)->value == 'no' || $param_node->attributes->getNamedItem(WSF_CONTENT_MODEL) && $param_node->attributes->getNamedItem(WSF_CONTENT_MODEL)->value == WSF_SIMPLE_CONTENT) {
                                    // for the complex types and simple contnet
                                    $in_header_objects[WSF_CLIENT] .= "    \$header_in{$in_headers} = new {$class_name}();\n    // TODO: fill in the class fields of \$header_in{$in_headers} object which is of type {$class_name} to match your business logic\n\n";
                                    $in_header_objects[WSF_SERVICE] .= "    // NOTE: \$header_in{$in_headers} object is of type {$class_name}\n";
                                    $service_function_doc_comment .= " * @param object of {$class_name} \$header_in{$in_headers} input header\n";
                                } else {
                                    // for the simple types
                                    $in_header_objects[WSF_CLIENT] .= "    // TODO: fill in the \$header_in{$in_headers} which is of type {$class_name} to match your business logic\n\n";
                                    $in_header_objects[WSF_SERVICE] .= "    // NOTE: \$header_in{$in_headers} header is of type {$class_name}\n";
                                    $service_function_doc_comment .= " * @param {$class_name} \$header_in{$in_headers} input header\n";
                                }
                                $in_headers++;
                            } else {
                                if ($param_node->attributes && $param_node->attributes->getNamedItem(WSF_WSDL_SIMPLE) && $param_node->attributes->getNamedItem(WSF_WSDL_SIMPLE)->value == 'no' || $param_node->attributes->getNamedItem(WSF_CONTENT_MODEL) && $param_node->attributes->getNamedItem(WSF_CONTENT_MODEL)->value == WSF_SIMPLE_CONTENT) {
                                    // for the complex types and simple contnet
                                    $out_header_objects[WSF_CLIENT] .= "\n    // TODO: Implement business logic to consume \$header_out{$out_headers} object, which is of type class {$class_name}\n";
                                    $out_header_objects[WSF_SERVICE] .= "    // NOTE: you should assign an object of type {$class_name} to \$header_out{$out_headers}\n";
                                    $service_function_doc_comment .= " * @param reference object of {$class_name} \$header_out{$out_headers} object output header\n";
                                } else {
                                    // for the simple types
                                    $out_header_objects[WSF_CLIENT] .= "\n    // TODO: Implement business logic to consume \$header_out{$out_headers}, which is of type {$class_name}\n";
                                    $out_header_objects[WSF_SERVICE] .= "    // NOTE: you should assign an object of type {$class_name} to \$header_out{$out_headers}\n";
                                    $service_function_doc_comment .= " * @param reference {$class_name} \$header_out{$out_headers} output header\n";
                                }
                                $out_headers++;
                            }
                            if ($param_node->attributes && $param_node->attributes->getNamedItem(WSF_WSDL_SIMPLE) && $param_node->attributes->getNamedItem(WSF_WSDL_SIMPLE)->value == 'no' || $param_node->attributes->getNamedItem(WSF_CONTENT_MODEL) && $param_node->attributes->getNamedItem(WSF_CONTENT_MODEL)->value == WSF_SIMPLE_CONTENT) {
                                $code_for_header = wsf_write_sub_classes($param_node);
                                $code .= $code_for_header;
                            }
                        }
                    }
                }
            }
        }
        // doc comments for the return type
        foreach ($op_child_list as $op_child) {
            // process the signature node
            if ($op_child->nodeName == WSF_SIGNATURE) {
                // get the nodes representing operation parameters and return types within signature
                $param_list = $op_child->childNodes;
                foreach ($param_list as $param_node) {
                    if ($param_node) {
                        // look for params and returns nodes
                        if ($param_node->nodeName == WSF_RETURNS) {
                            if ($param_node->hasAttributes()) {
                                // Wrapper element
                                $params_attr = $param_node->attributes;
                                // get wrapper element name, this is going to be the class name
                                $ele_name = $params_attr->getNamedItem(WSF_WRAPPER_ELEMENT)->value;
                                $service_function_doc_comment .= " * @return object of {$ele_name} \n";
                            } else {
                                // No wrapper element, there won't be any class generated for this
                                $child_array = array();
                                $param_child_list = $param_node->childNodes;
                                foreach ($param_child_list as $param_child) {
                                    $param_attr = $param_child->attributes;
                                    $ele_name = $param_type = "";
                                    if ($param_attr->getNamedItem(WSF_NAME)) {
                                        $ele_name = $param_attr->getNamedItem(WSF_NAME)->value;
                                    }
                                    if ($param_attr->getNamedItem(WSF_TYPE)) {
                                        $param_type = $param_attr->getNamedItem(WSF_TYPE)->value;
                                    }
                                    $content_model = "";
                                    if ($param_attr->getNamedItem(WSF_CONTENT_MODEL)) {
                                        $content_model = $param_attr->getNamedItem(WSF_CONTENT_MODEL)->value;
                                    }
                                    if ($content_model == WSF_SIMPLE_CONTENT) {
                                        $service_function_doc_comment .= " * @return object of {$ele_name} \n";
                                    } else {
                                        $service_function_doc_comment .= " * @return {$param_type} \n";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        $service_function_doc_comment .= " */\n";
        /*
        if($out_headers > 0) {
            $in_header_objects[WSF_CLIENT] .= "    // Declration of variables for the output headers\n"; 
            $in_header_objects[WSF_CLIENT] .= "    // NOTE: don't set any value to these objects, rather the call to proxy will assign values for them\n"; 
            for($i = 0; $i < $out_headers; $i ++) {
                $in_header_objects[WSF_CLIENT] .= "    \$header_out{$i} = NULL;\n";
            }
            $in_header_objects[WSF_CLIENT] .= "\n"; 
            $out_header_objects[WSF_SERVICE] .= "\n";
        }
        */
        if ($in_header_objects[WSF_CLIENT] != "") {
            $in_header_objects[WSF_CLIENT] = substr_replace($in_header_objects[WSF_CLIENT], "", -1);
        }
        if ($in_header_objects[WSF_SERVICE] != "") {
            $in_header_objects[WSF_SERVICE] .= "\n";
        }
        /* function declration variables for headers */
        $header_function_decl = "";
        for ($i = 0; $i < $in_headers; $i++) {
            $header_function_decl .= ", \$header_in" . $i;
        }
        for ($i = 0; $i < $out_headers; $i++) {
            $header_function_decl .= ", &\$header_out" . $i;
        }
        /* function call variables for headers */
        $header_function_call = "";
        for ($i = 0; $i < $in_headers; $i++) {
            $header_function_call .= ", \$header_in" . $i;
        }
        for ($i = 0; $i < $out_headers; $i++) {
            $header_function_call .= ", &\$header_out" . $i;
        }
        //put the doc comment
        //declare the start of service function
        $operations[$op_name][WSF_SERVICE] = $service_function_doc_comment;
        $operations[$op_name][WSF_SERVICE] .= "function " . $op_name . "(\$input{$header_function_decl}) {\n";
        foreach ($op_child_list as $op_child) {
            // process the signature node
            if ($op_child->nodeName == WSF_SIGNATURE) {
                // get the nodes representing operation parameters and return types within signature
                $param_list = $op_child->childNodes;
                foreach ($param_list as $param_node) {
                    if ($param_node) {
                        // look for params and returns nodes
                        if ($param_node->nodeName == WSF_PARAMS || $param_node->nodeName == WSF_RETURNS) {
                            if ($param_node->hasAttributes()) {
                                // Wrapper element
                                $params_attr = $param_node->attributes;
                                // get wrapper element name, this is going to be the class name
                                $ele_name = $params_attr->getNamedItem(WSF_WRAPPER_ELEMENT)->value;
                                // array to hold child elements corresponding to sub classes
                                $child_array = array();
                                // check if the class is already written
                                if (array_key_exists($ele_name, $written_classes) && $written_classes[$ele_name] == TRUE) {
                                    continue;
                                }
                                // write the extension code..
                                $extension_code = wsf_write_extension($param_node, $code);
                                $derives_arr = wsf_write_derives($param_node, $code);
                                // start writing class
                                $code = $code . "class " . $ele_name . $extension_code . " {\n";
                                $written_classes[$ele_name] = TRUE;
                                // prepare the demo code that the user could use for testing client.
                                // shows how to create the input and receive the response
                                if ($param_node->nodeName == WSF_PARAMS) {
                                    $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "    \$input = new {$ele_name}();\n";
                                    if (count($derives_arr) > 0) {
                                        $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "    /**\n     * Here you can replace {$ele_name} with a following class(es)\n";
                                        foreach ($derives_arr as $derive) {
                                            $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "     * {$derive}\n";
                                        }
                                        $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "     */\n";
                                    }
                                    $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "    //TODO: fill in the class fields of \$input to match your business logic\n";
                                    $operations[$op_name][WSF_CLIENT] .= $in_header_objects[WSF_CLIENT];
                                    $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "    // TODO: fill in the business logic\n    // NOTE: \$input is of type {$ele_name}\n";
                                    if (count($derives_arr) > 0) {
                                        $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "    /**\n     * You can expect \$input to be an instance of following class(es) in addition to {$ele_name}\n";
                                        foreach ($derives_arr as $derive) {
                                            $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "     * {$derive}\n";
                                        }
                                        $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "     */\n";
                                    }
                                    $operations[$op_name][WSF_SERVICE] .= $in_header_objects[WSF_SERVICE];
                                }
                                if ($param_node->nodeName == WSF_RETURNS) {
                                    $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "\n    // call the operation\n    \$response = \$proxy->" . $op_node->attributes->getNamedItem('name')->value . "(\$input{$header_function_call});\n    //TODO: Implement business logic to consume \$response, which is of type {$ele_name}\n";
                                    if (count($derives_arr) > 0) {
                                        $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "    /**\n     * You can expect \$response to be an instance of following class(es) in addition to {$ele_name}\n";
                                        foreach ($derives_arr as $derive) {
                                            $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "     * {$derive}\n";
                                        }
                                        $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "     */\n";
                                    }
                                    $operations[$op_name][WSF_CLIENT] .= $out_header_objects[WSF_CLIENT];
                                    $operations[$op_name][WSF_SERVICE] .= $out_header_objects[WSF_SERVICE];
                                    $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "    // NOTE: should return an object of type {$ele_name}\n";
                                    if (count($derives_arr) > 0) {
                                        $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "    /**\n     * Here you can replace {$ele_name} with a following class(es)\n";
                                        foreach ($derives_arr as $derive) {
                                            $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "     * {$derive}\n";
                                        }
                                        $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "     */\n";
                                    }
                                }
                                $child_array = array();
                                $derived_classes_code = "";
                                $code .= wsf_write_content_model($param_node, $child_array, $derived_classes_code);
                                $code = $code . "\n}\n\n";
                                // done writing the current class, now go and write the sub classes
                                foreach ($child_array as $child) {
                                    $code = $code . wsf_write_sub_classes($child);
                                }
                                $code .= $derived_classes_code;
                            } else {
                                // TODO: No wrapper element, there won't be any class generated for this
                                $child_array = array();
                                $param_child_list = $param_node->childNodes;
                                foreach ($param_child_list as $param_child) {
                                    $param_attr = $param_child->attributes;
                                    $ele_name = $param_attr->getNamedItem(WSF_NAME)->value;
                                    $param_type = $param_attr->getNamedItem(WSF_TYPE)->value;
                                    $content_model = "";
                                    if ($param_attr->getNamedItem(WSF_CONTENT_MODEL)) {
                                        $content_model = $param_attr->getNamedItem(WSF_CONTENT_MODEL)->value;
                                    }
                                    //resolving lists
                                    $is_list = FALSE;
                                    if ($param_attr->getNamedItem(WSF_LIST)) {
                                        $is_list = $param_attr->getNamedItem(WSF_LIST)->value;
                                    }
                                    $type_prefix = "";
                                    if ($is_list) {
                                        $type_prefix = "array of ";
                                    }
                                    //resolving unions
                                    $is_union = FALSE;
                                    if ($param_attr->getNamedItem(WSF_UNION)) {
                                        $is_union = $param_attr->getNamedItem(WSF_UNION)->value;
                                    }
                                    if ($is_union) {
                                        $union_type_array = array();
                                        $union_childs = $param_child->childNodes;
                                        foreach ($union_childs as $union_child) {
                                            if ($union_child->nodeName == "union") {
                                                $union_type = $union_child->attributes->getNamedItem(WSF_TYPE)->value;
                                                $union_type_array[] = $union_type;
                                            }
                                        }
                                        $param_type = implode("/", $union_type_array);
                                    }
                                    if ($content_model == WSF_SIMPLE_CONTENT) {
                                        // start writing class
                                        if (!array_key_exists($ele_name, $written_classes) || !$written_classes[$ele_name]) {
                                            $written_classes[$ele_name] = TRUE;
                                            $code = $code . "class " . $ele_name . " {\n";
                                            $derived_classes_code = "";
                                            $code .= wsf_write_content_model($param_child, $child_array, $derived_classes_code);
                                            $code = $code . "\n}\n\n";
                                            $code .= $derived_classes_code;
                                        }
                                        if ($param_node->nodeName == WSF_PARAMS) {
                                            $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "    \$input = new {$ele_name}();\n    //TODO: fill in the class fields of \$input to match your business logic\n";
                                            $operations[$op_name][WSF_CLIENT] .= $in_header_objects[WSF_CLIENT];
                                            $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "    // TODO: fill in the business logic\n    // NOTE: \$input is of type {$ele_name}\n";
                                            $operations[$op_name][WSF_SERVICE] .= $in_header_objects[WSF_SERVICE];
                                        }
                                        if ($param_node->nodeName == WSF_RETURNS) {
                                            $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "\n    // call the operation\n    \$response = \$proxy->" . $op_node->attributes->getNamedItem('name')->value . "(\$input{$header_function_call});\n    //TODO: Implement business logic to consume \$response, which is of type {$ele_name}\n";
                                            $operations[$op_name][WSF_CLIENT] .= $out_header_objects[WSF_CLIENT];
                                            $operations[$op_name][WSF_SERVICE] .= $out_header_objects[WSF_SERVICE];
                                            $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "    // NOTE: should return an object of type {$ele_name}\n";
                                        }
                                    } else {
                                        // prepare the demo code that the user could use for testing client.
                                        // shows how to create the input and receive the response
                                        if ($param_node->nodeName == WSF_PARAMS) {
                                            $simple_type_comment = wsf_comment_on_simple_type_wrapper($param_child, "\$input", $param_type);
                                            $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "    //TODO: fill \$input with (data type: {$type_prefix}{$param_type}) data to match your business logic\n";
                                            if ($param_child->getAttribute("simple") == "yes") {
                                                $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . $simple_type_comment . "\n";
                                            }
                                            $operations[$op_name][WSF_CLIENT] .= $in_header_objects[WSF_CLIENT];
                                            $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "    // TODO: fill in the business logic\n    // NOTE: \$input is of type {$type_prefix}{$param_type}\n";
                                            if ($param_child->getAttribute("simple") == "yes") {
                                                $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . $simple_type_comment . "\n";
                                            }
                                            $operations[$op_name][WSF_SERVICE] .= $in_header_objects[WSF_SERVICE];
                                        }
                                        if ($param_node->nodeName == WSF_RETURNS) {
                                            $simple_type_comment = wsf_comment_on_simple_type_wrapper($param_child, "output ", $param_type);
                                            $operations[$op_name][WSF_CLIENT] = $operations[$op_name][WSF_CLIENT] . "\n    // call the operation\n    \$response = \$proxy->" . $op_node->attributes->getNamedItem('name')->value . "(\$input{$header_function_call});\n    //TODO: Implement business logic to consume \$response, which is of type {$type_prefix}{$param_type}\n";
                                            $operations[$op_name][WSF_CLIENT] .= $out_header_objects[WSF_CLIENT];
                                            $operations[$op_name][WSF_SERVICE] .= $out_header_objects[WSF_SERVICE];
                                            $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "    // NOTE: should return an object of (type: {$type_prefix}{$param_type})\n";
                                            $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . $simple_type_comment . "\n";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($op_child->nodeName == WSF_W2P_BINDING_DETAILS) {
                    /* action is default to wsa waction */
                    $action = $op_child->getAttribute('wsawaction');
                    if ($action == NULL) {
                        $action = $op_child->getAttribute('soapaction');
                    }
                    if ($action != NULL) {
                        /* we feeding the actions to the global variable */
                        if ($actions == NULL) {
                            $actions = array();
                        }
                        $actions[$action] = $op_name;
                    }
                }
            }
        }
        $operations[$op_name][WSF_SERVICE] = $operations[$op_name][WSF_SERVICE] . "\n}\n\n";
    }
    return $code;
}
示例#3
0
文件: wsf_wsdl.php 项目: ztobs/wsf
/**
 * This function is called from call_user_function in C level.
 * It will provide the sig model information and the policies
 * and return the array of response payload + attachments.
 * @param array $user_parameters the details of WSDL endpoint, service address
 * and class map
 * @param array $function_parameters the arguments passed with the functions..
 * @param string $wsdl_dom_string the original wsdl as a strng
 * @param boolean $is_wsdl_11 whether this is wsdl1.1. or not
 * @param string $sig_model_string the sig model as a string
 * @return array $return_value array of details to be passed to C level
 */
function wsf_process_wsdl($wsdata)
{
    require_once 'dynamic_invocation/wsf_wsdl_consts.php';
    require_once 'dynamic_invocation/wsf_wsdl_util.php';
    require_once 'dynamic_invocation/wsf_wsdl_client.php';
    ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, "wsf_process_wsdl called");
    $user_parameters = $wsdata->WSDL_UserParameters;
    $function_parameters = $wsdata->WSDL_FunctionParameters;
    $wsdl_dom_string = $wsdata->WSDL_SigModelDom;
    $is_wsdl_11 = $wsdata->WSDL_IsWSDL11;
    $sig_model_string = $wsdata->WSDL_SigModelString;
    $is_multiple_interfaces = $wsdata->WSDL_IsMultipleInterfaces;
    $return_value = array();
    $policy_array = array();
    $binding_array = array();
    $is_doc_lit = FALSE;
    $is_rpc_enc = FALSE;
    $use_mtom = TRUE;
    //default to on
    /* retrieving the user parameters */
    $service = NULL;
    $port = NULL;
    if (array_key_exists(WSF_SERVICE_NAME, $user_parameters)) {
        $service = $user_parameters[WSF_SERVICE_NAME];
    }
    if (array_key_exists(WSF_PORT_NAME, $user_parameters)) {
        $port = $user_parameters[WSF_PORT_NAME];
    }
    if (array_key_exists(WSF_USE_MTOM, $user_parameters)) {
        $use_mtom = $user_parameters[WSF_USE_MTOM];
    }
    /* class map is an optional parameter */
    if (isset($user_parameters[WSF_CLASSMAP])) {
        $class_map = $user_parameters[WSF_CLASSMAP];
    } else {
        $class_map = NULL;
    }
    /* wsf endpoint is an optional parameter */
    if (array_key_exists(WSF_ENDPOINT, $user_parameters) && isset($user_parameters[WSF_ENDPOINT])) {
        $endpoint_address = $user_parameters[WSF_ENDPOINT];
    } else {
        $endpoint_address = NULL;
    }
    /* extracting the information on function parameters */
    $operation_name = $function_parameters[WSF_INVOKE_FUNCTION];
    $arg_count = $function_parameters[WSF_ARG_COUNT];
    $arguments = $function_parameters[WSF_ARG_ARRAY];
    // we load the wsdl dom and the sig model dom from the stored strings
    $wsdl_dom = new DomDocument();
    $sig_model_dom = new DOMDocument();
    $sig_model_dom->preserveWhiteSpace = FALSE;
    $wsdl_dom->preserveWhiteSpace = FALSE;
    $sig_model_dom->loadXML($sig_model_string);
    if (!$sig_model_dom) {
        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "Error retrieving the intermediate sig model");
        return "Error retrieving the intermediate model";
    }
    $wsdl_dom->loadXML($wsdl_dom_string);
    if (!$wsdl_dom) {
        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "Error retrieving the wsdl string to process the request message");
        return "Error retrieving the wsdl string to process the request message";
    }
    $is_multiple_interfaces = wsf_is_mutiple_port_types($wsdl_dom);
    if ($is_wsdl_11) {
        $wsdl_11_dom = $wsdl_dom;
    }
    /* endpoint_address is used for just to parse back to the c code: */
    if (!$endpoint_address) {
        $endpoint_address = wsf_get_endpoint_address($sig_model_dom);
    } else {
        $multiple_ep = TRUE;
        $multiple_ep = wsf_is_multiple_endpoints($sig_model_dom);
        if (!$multiple_ep) {
            $endpoint_address = wsf_get_endpoint_address($sig_model_dom);
        }
    }
    /* for retrieve binding we have to go to the old WSDL */
    if ($is_wsdl_11 && $wsdl_11_dom != NULL) {
        $binding_node = wsf_get_binding($wsdl_11_dom, $service, $port, TRUE);
        if (!$binding_node) {
            ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "binding node not found");
            return NULL;
        }
        $policy_array = wsf_get_all_policies($wsdl_11_dom, $binding_node, $operation_name, $is_wsdl_11);
        $is_rpc_enc = wsf_is_rpc_enc_wsdl($binding_node, $operation_name);
        /* rpc literal not supported */
    } else {
        $binding_node = wsf_get_binding($wsdl_dom, $service, $port, FALSE);
        if (!$binding_node) {
            ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "binding node not found");
            return NULL;
        }
        $policy_array = wsf_get_all_policies($wsdl_dom, $binding_node, $operation_name, FALSE);
    }
    $operation = wsf_find_operation($sig_model_dom, $operation_name, $service, $endpoint_address, $port, $is_multiple_interfaces);
    if (!$operation) {
        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "operation node not found");
        return;
    }
    $binding_array = wsf_get_binding_details($operation);
    //extracting out the sig_method from the operation sig node
    if ($operation) {
        foreach ($operation->childNodes as $style) {
            if ($style->tagName == WSF_SIGNATURE) {
                $sig_method = $style;
                if ($style->attributes->getNamedItem(WSF_METHOD)->value == WSF_INFERENCE) {
                    $is_doc_lit = TRUE;
                } else {
                    if ($style->attributes->getNamedItem(WSF_METHOD)->value == WSF_RPC) {
                        $is_doc_lit = FALSE;
                    }
                }
            }
        }
    }
    $attachment_map = array();
    $return_info = NULL;
    if ($sig_method && !$is_rpc_enc) {
        $return_info = wsf_create_payload($sig_method, $is_doc_lit, $operation_name, $arg_count, $arguments, $class_map, $use_mtom, $attachment_map);
    } else {
        $return_info = wsf_create_payload($sig_method, FALSE, $operation_name, $arg_count, $arguments, $class_map, $use_mtom, $attachment_map);
    }
    $payload = $return_info[WSF_REQUEST_PAYLOAD];
    $headers = $return_info[WSF_INPUT_HEADERS];
    if (is_array($attachment_map) && count($attachment_map) == 0) {
        $attachment_map = NULL;
    }
    $response_sig_model_string = $sig_model_dom->saveXML($operation);
    $return_value = array(WSF_RESPONSE_SIG_MODEL => $response_sig_model_string, WSF_WSDL_DOM => $wsdl_dom_string, WSF_ENDPOINT_URI => $endpoint_address, WSF_BINDING_DETAILS => $binding_array, WSF_REQUEST_PAYLOAD => $payload, WSF_INPUT_HEADERS => $headers, WSF_POLICY_NODE => $policy_array, WSF_ATTACHMENT_MAP => $attachment_map);
    return $return_value;
}