コード例 #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
ファイル: wsf_class_writer.php プロジェクト: ztobs/wsf
/**
 * 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.
 * Once this function is called, it will fill in the WSDL information, 
 * such as sig model, and the wsdl string
 * into an array and return that array.
 * @param array $user_parameters the details of WSDL endpoint, service address
 * and class map
 * @param array $function_parameters details of the invoked function
 * @return array $return_value array of details to be passed to C level
 */
function wsf_extract_wsdl_info($wsdata)
{
    require_once 'dynamic_invocation/wsf_wsdl_consts.php';
    require_once 'dynamic_invocation/wsf_wsdl_util.php';
    ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, "calling for the wsdl info");
    $user_parameters = $wsdata->WSDL_UserParameters;
    $is_wsdl_11 = TRUE;
    $wsdl_11_dom = NULL;
    /** https client auth */
    $cacert = NULL;
    $clientcert = NULL;
    $passphrase = NULL;
    $stream_ctx = NULL;
    /** wsf_get_wsdl_function using an stream context object */
    if (!is_null($cacert) && !is_null($clientcert)) {
        $stream_ctx = stream_context_create(array("ssl" => array('cafile' => $cacert, 'local_cert' => $clientcert, 'verify_peer' => false)));
    }
    $return_value = array();
    /* 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];
    }
    $wsdl_location = $user_parameters[WSF_WSDL];
    $wsdl_dom = new DomDocument();
    $sig_model_dom = new DOMDocument();
    $sig_model_dom->preserveWhiteSpace = FALSE;
    $wsdl_dom->preserveWhiteSpace = FALSE;
    if (!$wsdl_location) {
        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "WSDL location uri is not found");
        return "WSDL location uri is not found";
    }
    $is_multiple_interfaces = FALSE;
    // Load WSDL as DOM
    $wsdl_str = wsf_get_wsdl_str_from_url($wsdl_location, $user_parameters);
    if (is_null($wsdl_str)) {
        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "Reading WSDL from {$wsdl_location} failed ");
        return "Reading WSDL from {$wsdl_location} failed.";
    }
    if (!$wsdl_dom->loadXML($wsdl_str)) {
        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "WSDL {$wsdl_location} could not be loaded");
        return "WSDL {$wsdl_location} could not be loaded.";
    }
    $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) {
        // this will return the wsdl2.0 dom and the information
        // about is_wsdl_11 and wsdl_11_dom + bundles the imports, includes
        $wsdl_dom = wsf_get_wsdl_dom($wsdl_dom, $wsdl_location, $is_wsdl_11, $wsdl_11_dom, $stream_ctx);
        if (!$wsdl_dom) {
            ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "Error creating WSDL Dom Document," . "Please check whether the wsdl is an valid XML");
            return "Error creating WSDL Dom Document" . "Please check whether the wsdl is an valid XML";
        }
        $sig_model_dom = wsf_get_sig_model_dom($wsdl_dom);
    } else {
        // this will return the wsdl2.0 dom and the information
        // about is_wsdl_11 and wsdl_11_dom + bundles the imports, includes
        $wsdl_dom = wsf_get_wsdl_dom($wsdl_dom, $wsdl_location, $is_wsdl_11, $wsdl_11_dom, $stream_ctx);
        $sig_model_dom = wsf_process_multiple_interfaces($wsdl_dom);
    }
    if (!$sig_model_dom) {
        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "Error creating intermediate sig model");
        return "Error creating intermediate model";
    }
    $sig_model_string = $sig_model_dom->saveXML();
    if ($is_wsdl_11 == TRUE && $wsdl_11_dom) {
        $wsdl_dom = $wsdl_11_dom;
    }
    $wsdl_dom_string = $wsdl_dom->saveXML();
    $return_value = array(WSF_IS_WSDL_11 => $is_wsdl_11, WSF_SIG_MODEL_STRING => $sig_model_string, WSF_WSDL_DOM => $wsdl_dom_string, WSF_IS_MULTI_INTERFACES => $is_multiple_interfaces);
    return $return_value;
}