[PHP-SOAP-DEV] Proposed overriding ser/deser
Status: Alpha
Brought to you by:
rodif_bl
From: brad l. <rod...@ya...> - 2002-05-05 15:29:52
|
I have been doing some thining on how to do this... And i think it would be pretty cool if i could incorperate domxml. Standard function handing: $soap_server->map("namespace:type", "to_xml", "to_zval"); function to_xml_before($zval) { return $modified_zval; } function to_xml($zval) { $xmldom_node = new DomElement($zval->name); $xmldom_node->set_content($zval->value); return $xmldom_node; } function to_xml_after($xmldom_node) { $xmldom_node->first_child()->unlink_node(); return $xmldom_node; } ------------- function to_zval_before($xmldom_node) { return $xmldom_node->first_child()->unlink_node(); } function to_zval($xmldom_node) { $zval->data = $xmldom_node->first_child()->get_content(); return $zval; } function to_zval_after($zval) { $zval->connection = db_connect($zval->db, $zval->username, $zval->passwd); - or - unset($zval->unwanted_field); - or - $obj = new OtherObject($zval->value); return $obj; } Class manipulation. $soap_server->map("namespace:type", "class", MAP_CLASS_INSTANCE (default) | MAP_CLASS_CONVERT); MAP_CLASS_INSTANCE: class myType { function to_xml_before() { unset($this->unwanted); } function to_xml() { $xmldom_node = new DomElement($this->name); $xmldom_node->set_content($this->value); return $xmldom_node; } function to_xml_after($xmldom_node) { $xmldom_node->first_child()->unlink_node(); return $xmldom; } function to_zval_before($dom_node) { $xmldom_node->first_child()->unlink_node(); return $xmldom; } function to_zval($xmldom_node) { $this->data = $xmldom_node->get_contents(); } function to_zval_after() { unlink($this->data); } } MAP_CLASS_CONVERT: class myType { function to_xml_before($zval) { return $modified_zval; } function to_xml($zval) { $xmldom_node = new DomElement($zval->name); $xmldom_node->set_content($zval->value); return $xmldom_node; } function to_xml_after($xmldom_node) { $xmldom_node->first_child()->unlink_node(); return $xmldom_node; } function to_zval_before($xmldom_node) { return $xmldom_node->first_child()->unlink_node(); } function to_zval($xmldom_node) { $zval->data = $xmldom_node->first_child()->get_content(); return $zval; } function to_zval_after($zval) { $zval->connection = db_connect($zval->db, $zval->username, $zval->passwd); - or - unset($zval->unwanted_field); - or - $obj = new OtherObject($zval->value); return $obj; } } Basically the difference between MAP_CLASS_INSTANCE and MAP_CLASS_CONVERT is the instance treats the class as the type thats being converted and the class_convert treats the class as just a "conversion" class. $soap_server->autoMap(true/false); This will tell the server to "automap" types. Meaning if while serializing/deseralizing "someType" and there is an existing php class called "someType" then it ill try and call the corrisponding functions. I was looking into the domxml extension. The extension will need some changes for my needs and some other issues that dont currently work right now. like: $xml = new DomElement("asdf"); doesn't really give you a new DomElement(); you have to do: $xml = new DomElement("asfd"); $real_xml = $xml->domelement("asdf"); it looks like the constructors aren't working. I know how to fix them its just a matter of getting in the changes. the extension could still handle the to_xml_before() and to_zval_after() with out domxml changes or if domxml isn't even compiled in. - Brad __________________________________________________ Do You Yahoo!? Yahoo! Health - your guide to health and wellness http://health.yahoo.com |