Esempio n. 1
0
/**
* Extract the sig node looking at the user object type
* @param array $sig_model as a DomNode
* @param DomNode $parent_node - The parent node to add the content 
* @param DomNode $root_node - The top most of parent
* @param mixed $user_obj - class object to pass
* @param $prefix_i - next available prefix index 
* @param $namespace_map - Just make sure the unique namespace is used.
   Newly added (passed by reference)
*/
function wsf_infer_sig_node_from_user_obj($sig_node, $parent_node, $root_node, $user_obj, $classmap, &$prefix_i, array &$namespace_map)
{
    ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, "Calling infer sig mode from user obj");
    // first loop the through sig child whther there is is inheriting-types in there
    $inheriting_type_sigs = array();
    $inheriting_type_namespaces = array();
    $sig_child_nodes = $sig_node->childNodes;
    foreach ($sig_child_nodes as $sig_child_node) {
        if ($sig_child_node->localName == WSF_INHERITING_TYPE) {
            $sig_child_attris = $sig_child_node->attributes;
            $type_name = $type_ns = "";
            if ($sig_child_attris->getNamedItem(WSF_XSI_TYPE)) {
                $type_name = $sig_child_attris->getNamedItem(WSF_XSI_TYPE)->value;
            }
            if ($sig_child_attris->getNamedItem(WSF_XSI_TYPE_NS)) {
                $type_ns = $sig_child_attris->getNamedItem(WSF_XSI_TYPE_NS)->value;
            }
            ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, "type name {$type_name} ; {$type_ns} ");
            $inheriting_type_sigs[$type_name] = $sig_child_node;
            $inheriting_type_namespaces[$type_name] = $type_ns;
        }
    }
    ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, print_r($inheriting_type_namespaces, TRUE));
    // if not inheriting types just let the sig_node to be the sig node
    if (count($inheriting_type_sigs) == 0) {
        return $sig_node;
    }
    $reflex_obj = new ReflectionObject($user_obj);
    if (!$reflex_obj) {
        return $sig_node;
    }
    $class_name = $reflex_obj->getName();
    // find the type name
    $type_name = $class_name;
    // if the classmap is present we need to check the type name from the map
    if ($classmap && is_array($classmap)) {
        foreach ($classmap as $type_name_key => $class_name_value) {
            if ($class_name_value == $class_name) {
                $type_name = $type_name_key;
                break;
            }
        }
    }
    // so we found the type, check with the collected inherited_types
    $the_sig_node = NULL;
    $the_type_name = NULL;
    $the_type_namespace = NULL;
    if (array_key_exists($type_name, $inheriting_type_sigs)) {
        $the_type_name = $type_name;
        $the_type_namespace = $inheriting_type_namespaces[$type_name];
        $the_sig_node = $inheriting_type_sigs[$type_name];
    } else {
        // not in inherited map, so should be the same sig,
        return $sig_node;
    }
    //now retrieve the namespace or declare it if it is not present
    $the_type_ns_prefix = NULL;
    if (array_key_exists($the_type_namespace, $namespace_map)) {
        $the_type_ns_prefix = $namespace_map[$the_type_namespace];
    } else {
        $the_type_ns_prefix = "ns" . $prefix_i;
        $prefix_i++;
        $root_node->setAttribute("xmlns:" . $the_type_ns_prefix, $the_type_namespace);
        $namespace_map[$the_type_namespace] = $the_type_ns_prefix;
    }
    $xsi_namespace_prefix = NULL;
    if (array_key_exists(WSF_XSI_NAMESPACE, $namespace_map)) {
        $xsi_namespace_prefix = $namespace_map[WSF_XSI_NAMESPACE];
    } else {
        $xsi_namespace_prefix = "xsi";
        $root_node->setAttribute("xmlns:" . $xsi_namespace_prefix, WSF_XSI_NAMESPACE);
        $namespace_map[WSF_XSI_NAMESPACE] = $xsi_namespace_prefix;
    }
    $attribute_name = $xsi_namespace_prefix . ":" . "type";
    $attribute_value = $the_type_ns_prefix . ":" . $the_type_name;
    $parent_node->setAttribute($attribute_name, $attribute_value);
    ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, wsf_test_serialize_node($the_sig_node));
    return $the_sig_node;
}
Esempio n. 2
0
/**
 * Easy serializing function
 * @param xml DOMDocuemnt the xml to serialize
 * @return string of serialized xml
 */
function wsf_test_serialize_node($xml)
{
    $nodeText = "";
    if ($xml->nodeType == XML_TEXT_NODE) {
        //for text node
        $nodeText = $xml->nodeValue;
    } else {
        if ($xml->nodeType == XML_ELEMENT_NODE) {
            $nodeName = $xml->nodeName;
            $nodeText = "<" . $nodeName;
            // add attributes
            foreach ($xml->attributes as $attri) {
                $nodeText .= " " . $attri->name . "=" . "\"" . $attri->value . "\" ";
            }
            $nodeText .= ">";
            // add childs
            foreach ($xml->childNodes as $child) {
                $childText = wsf_test_serialize_node($child);
                $nodeText .= $childText;
            }
            $nodeText .= "</" . $nodeName . ">";
        }
    }
    return $nodeText;
}
Esempio n. 3
0
/**
 * infer attributes
 * @param $parent_node parent node containing the attributes
 * @param $sig_node sig node containing the attribute signature
 * @return $parset_tree the parsed tree of attributes
 */
function wsf_infer_attributes(DomNode $parent_node, DomNode $sig_node)
{
    $parse_tree = array();
    if ($sig_node->hasChildNodes()) {
        foreach ($sig_node->childNodes as $sig_param_node) {
            if ($sig_param_node->nodeName == WSF_PARAM) {
                $is_simple = FALSE;
                $is_attribute = FALSE;
                $param_name = NULL;
                $param_type = NULL;
                if ($sig_param_node->attributes->getNamedItem(WSF_NAME)) {
                    $param_name = $sig_param_node->attributes->getNamedItem(WSF_NAME)->value;
                }
                if ($sig_param_node->attributes->getNamedItem(WSF_TYPE)) {
                    $param_type = $sig_param_node->attributes->getNamedItem(WSF_TYPE)->value;
                }
                if ($sig_param_node->attributes->getNamedItem(WSF_WSDL_SIMPLE) && $sig_param_node->attributes->getNamedItem(WSF_WSDL_SIMPLE)->value == "yes") {
                    $is_simple = TRUE;
                }
                if ($sig_param_node->attributes->getNamedItem(WSF_ATTRIBUTE) && $sig_param_node->attributes->getNamedItem(WSF_ATTRIBUTE)->value == "yes") {
                    $is_attribute = TRUE;
                }
                if ($is_attribute) {
                    ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, $param_name . ":" . wsf_test_serialize_node($parent_node));
                    if ($parent_node && $parent_node->attributes->getNamedItem($param_name)) {
                        $original_value = $parent_node->attributes->getNamedItem($param_name)->value;
                        $is_list = FALSE;
                        if ($sig_param_node->attributes->getNamedItem(WSF_LIST) && $sig_param_node->attributes->getNamedItem(WSF_LIST)->value == "yes") {
                            $is_list = TRUE;
                        }
                        $converted_value = wsf_wsdl_deserialize_string_value($param_type, $original_value, $sig_param_node, NULL);
                        $parse_tree[$param_name] = $converted_value;
                    }
                }
            } else {
                if ($sig_param_node->nodeName == WSF_INHERITED_CONTENT) {
                    $parse_tree = array_merge($parse_tree, wsf_infer_attributes($parent_node, $sig_param_node));
                }
            }
        }
    }
    return $parse_tree;
}