dmitry Thu Aug 24 06:18:45 2006 UTC Modified files: /php-src/ext/soap php_soap.h soap.c /php-src/ext/soap/tests server026.phpt server027.phpt server028.phpt Log: Added SoapServer::setObject() method (it is a simplified version of SoapServer::setClass() method).
http://cvs.php.net/viewvc.cgi/php-src/ext/soap/php_soap.h?r1=1.47&r2=1.48&diff_format=u Index: php-src/ext/soap/php_soap.h diff -u php-src/ext/soap/php_soap.h:1.47 php-src/ext/soap/php_soap.h:1.48 --- php-src/ext/soap/php_soap.h:1.47 Tue Aug 1 16:10:25 2006 +++ php-src/ext/soap/php_soap.h Thu Aug 24 06:18:45 2006 @@ -17,7 +17,7 @@ | Dmitry Stogov <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: php_soap.h,v 1.47 2006/08/01 16:10:25 dmitry Exp $ */ +/* $Id: php_soap.h,v 1.48 2006/08/24 06:18:45 dmitry Exp $ */ #ifndef PHP_SOAP_H #define PHP_SOAP_H @@ -119,6 +119,8 @@ int persistance; } soap_class; + zval *soap_object; + int type; char *actor; struct _soapHeader **soap_headers_ptr; @@ -179,6 +181,7 @@ #define SOAP_CLASS 1 #define SOAP_FUNCTIONS 2 +#define SOAP_OBJECT 3 #define SOAP_FUNCTIONS_ALL 999 #define SOAP_MAP_FUNCTION 1 http://cvs.php.net/viewvc.cgi/php-src/ext/soap/soap.c?r1=1.204&r2=1.205&diff_format=u Index: php-src/ext/soap/soap.c diff -u php-src/ext/soap/soap.c:1.204 php-src/ext/soap/soap.c:1.205 --- php-src/ext/soap/soap.c:1.204 Tue Aug 8 16:59:11 2006 +++ php-src/ext/soap/soap.c Thu Aug 24 06:18:45 2006 @@ -17,7 +17,7 @@ | Dmitry Stogov <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: soap.c,v 1.204 2006/08/08 16:59:11 tony2001 Exp $ */ +/* $Id: soap.c,v 1.205 2006/08/24 06:18:45 dmitry Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -165,6 +165,7 @@ /* Server Functions */ PHP_METHOD(SoapServer, SoapServer); PHP_METHOD(SoapServer, setClass); +PHP_METHOD(SoapServer, setObject); PHP_METHOD(SoapServer, addFunction); PHP_METHOD(SoapServer, getFunctions); PHP_METHOD(SoapServer, handle); @@ -225,6 +226,7 @@ SOAP_CTOR(SoapServer, SoapServer, NULL, 0) PHP_ME(SoapServer, setPersistence, NULL, 0) PHP_ME(SoapServer, setClass, NULL, 0) + PHP_ME(SoapServer, setObject, NULL, 0) PHP_ME(SoapServer, addFunction, NULL, 0) PHP_ME(SoapServer, getFunctions, NULL, 0) PHP_ME(SoapServer, handle, NULL, 0) @@ -576,6 +578,9 @@ zend_hash_destroy(service->class_map); FREE_HASHTABLE(service->class_map); } + if (service->soap_object) { + zval_ptr_dtor(&service->soap_object); + } zend_object_std_dtor(object TSRMLS_CC); efree(object); } @@ -1525,6 +1530,32 @@ /* }}} */ +/* {{{ proto void SoapServer::setObject(object) + Sets object which will handle SOAP requests */ +PHP_METHOD(SoapServer, setObject) +{ + soap_server_object *service; + zval *obj; + + SOAP_SERVER_BEGIN_CODE(); + service = (soap_server_object*)zend_object_store_get_object(this_ptr TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameters"); + } + + service->type = SOAP_OBJECT; + + MAKE_STD_ZVAL(service->soap_object); + *service->soap_object = *obj; + zval_copy_ctor(service->soap_object); + INIT_PZVAL(service->soap_object); + + SOAP_SERVER_END_CODE(); +} +/* }}} */ + + /* {{{ proto array SoapServer::getFunctions(void) U Returns list of defined functions */ PHP_METHOD(SoapServer, getFunctions) @@ -1538,7 +1569,9 @@ service = (soap_server_object*)zend_object_store_get_object(this_ptr TSRMLS_CC); array_init(return_value); - if (service->type == SOAP_CLASS) { + if (service->type == SOAP_OBJECT) { + ft = &(Z_OBJCE_P(service->soap_object)->function_table); + } else if (service->type == SOAP_CLASS) { ft = &service->soap_class.ce->function_table; } else if (service->soap_functions.functions_all == TRUE) { ft = EG(function_table); @@ -1557,7 +1590,7 @@ HashPosition pos; zend_hash_internal_pointer_reset_ex(ft, &pos); while (zend_hash_get_current_data_ex(ft, (void **)&f, &pos) != FAILURE) { - if ((service->type != SOAP_CLASS) || (f->common.fn_flags & ZEND_ACC_PUBLIC)) { + if ((service->type != SOAP_OBJECT && service->type != SOAP_CLASS) || (f->common.fn_flags & ZEND_ACC_PUBLIC)) { add_next_index_text(return_value, f->common.function_name, 1); } zend_hash_move_forward_ex(ft, &pos); @@ -1844,7 +1877,10 @@ service->soap_headers_ptr = &soap_headers; soap_obj = NULL; - if (service->type == SOAP_CLASS) { + if (service->type == SOAP_OBJECT) { + soap_obj = service->soap_object; + function_table = &((Z_OBJCE_P(soap_obj))->function_table); + } else if (service->type == SOAP_CLASS) { #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION) /* If persistent then set soap_obj from from the previous created session (if available) */ if (service->soap_class.persistance == SOAP_PERSISTENCE_SESSION) { @@ -1943,7 +1979,6 @@ #endif } -/* function_table = &(soap_obj->value.obj.ce->function_table);*/ function_table = &((Z_OBJCE_P(soap_obj))->function_table); } else { if (service->soap_functions.functions_all == TRUE) { @@ -1972,9 +2007,9 @@ fn_name = estrndup(Z_STRVAL(h->function_name),Z_STRLEN(h->function_name)); if (zend_hash_exists(function_table, php_strtolower(fn_name, Z_STRLEN(h->function_name)), Z_STRLEN(h->function_name) + 1) || - (service->type == SOAP_CLASS && + ((service->type == SOAP_CLASS || service->type == SOAP_OBJECT) && zend_hash_exists(function_table, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)))) { - if (service->type == SOAP_CLASS) { + if (service->type == SOAP_CLASS || service->type == SOAP_OBJECT) { call_status = call_user_function(NULL, &soap_obj, &h->function_name, &h->retval, h->num_params, h->parameters TSRMLS_CC); } else { call_status = call_user_function(EG(function_table), NULL, &h->function_name, &h->retval, h->num_params, h->parameters TSRMLS_CC); @@ -1993,7 +2028,7 @@ php_output_discard(TSRMLS_C); soap_server_fault_ex(function, &h->retval, h TSRMLS_CC); efree(fn_name); - if (soap_obj) {zval_ptr_dtor(&soap_obj);} + if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(&soap_obj);} goto fail; } else if (EG(exception)) { php_output_discard(TSRMLS_C); @@ -2008,7 +2043,7 @@ soap_server_fault_ex(function, EG(exception), h TSRMLS_CC); } efree(fn_name); - if (soap_obj) {zval_ptr_dtor(&soap_obj);} + if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(&soap_obj);} goto fail; } } else if (h->mustUnderstand) { @@ -2020,17 +2055,19 @@ fn_name = estrndup(Z_STRVAL(function_name),Z_STRLEN(function_name)); if (zend_hash_exists(function_table, php_strtolower(fn_name, Z_STRLEN(function_name)), Z_STRLEN(function_name) + 1) || - (service->type == SOAP_CLASS && + ((service->type == SOAP_CLASS || service->type == SOAP_OBJECT) && zend_hash_exists(function_table, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)))) { - if (service->type == SOAP_CLASS) { + if (service->type == SOAP_CLASS || service->type == SOAP_OBJECT) { call_status = call_user_function(NULL, &soap_obj, &function_name, &retval, num_params, params TSRMLS_CC); + if (service->type == SOAP_CLASS) { #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION) - if (service->soap_class.persistance != SOAP_PERSISTENCE_SESSION) { - zval_ptr_dtor(&soap_obj); - } + if (service->soap_class.persistance != SOAP_PERSISTENCE_SESSION) { + zval_ptr_dtor(&soap_obj); + } #else - zval_ptr_dtor(&soap_obj); + zval_ptr_dtor(&soap_obj); #endif + } } else { call_status = call_user_function(EG(function_table), NULL, &function_name, &retval, num_params, params TSRMLS_CC); } @@ -2045,12 +2082,14 @@ instanceof_function(Z_OBJCE_P(EG(exception)), soap_fault_class_entry TSRMLS_CC)) { soap_server_fault_ex(function, EG(exception), NULL TSRMLS_CC); } + if (service->type == SOAP_CLASS) { #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION) - if (soap_obj && service->soap_class.persistance != SOAP_PERSISTENCE_SESSION) { + if (soap_obj && service->soap_class.persistance != SOAP_PERSISTENCE_SESSION) { #else - if (soap_obj) { + if (soap_obj) { #endif - zval_ptr_dtor(&soap_obj); + zval_ptr_dtor(&soap_obj); + } } goto fail; } http://cvs.php.net/viewvc.cgi/php-src/ext/soap/tests/server026.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/soap/tests/server026.phpt diff -u /dev/null php-src/ext/soap/tests/server026.phpt:1.2 --- /dev/null Thu Aug 24 06:18:45 2006 +++ php-src/ext/soap/tests/server026.phpt Thu Aug 24 06:18:45 2006 @@ -0,0 +1,37 @@ +--TEST-- +SOAP Server 26: setObject +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +class Foo { + function test() { + return "Hello World"; + } +} + +$foo = new Foo(); +$server = new soapserver(null,array('uri'=>"http://testuri.org")); +$server->setObject($foo); + +$HTTP_RAW_POST_DATA = <<<EOF +<?xml version="1.0" encoding="ISO-8859-1"?> +<SOAP-ENV:Envelope + SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:si="http://soapinterop.org/xsd"> + <SOAP-ENV:Body> + <ns1:test xmlns:ns1="http://testuri.org" /> + </SOAP-ENV:Body> +</SOAP-ENV:Envelope> +EOF; + +$server->handle(); +echo "ok\n"; +?> +--EXPECT-- +<?xml version="1.0" encoding="UTF-8"?> +<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testuri.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:testResponse><return xsi:type="xsd:string">Hello World</return></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> +ok http://cvs.php.net/viewvc.cgi/php-src/ext/soap/tests/server027.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/soap/tests/server027.phpt diff -u /dev/null php-src/ext/soap/tests/server027.phpt:1.2 --- /dev/null Thu Aug 24 06:18:45 2006 +++ php-src/ext/soap/tests/server027.phpt Thu Aug 24 06:18:45 2006 @@ -0,0 +1,38 @@ +--TEST-- +SOAP Server 27: setObject and getFunctions +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +class Foo { + + function Foo() { + } + + function test() { + return $this->str; + } +} + +$foo = new Foo(); +$server = new SoapServer(null,array('uri'=>"http://testuri.org")); +$server->setObject($foo); +var_dump($server->getfunctions()); +echo "ok\n"; +?> +--EXPECT-- +array(2) { + [0]=> + string(3) "Foo" + [1]=> + string(4) "test" +} +ok +--UEXPECT-- +array(2) { + [0]=> + unicode(3) "Foo" + [1]=> + unicode(4) "test" +} +ok http://cvs.php.net/viewvc.cgi/php-src/ext/soap/tests/server028.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/soap/tests/server028.phpt diff -u /dev/null php-src/ext/soap/tests/server028.phpt:1.2 --- /dev/null Thu Aug 24 06:18:45 2006 +++ php-src/ext/soap/tests/server028.phpt Thu Aug 24 06:18:45 2006 @@ -0,0 +1,41 @@ +--TEST-- +SOAP Server 28: SoapServer::setObject and __call() +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +class Foo { + function __call($name, $args) { + if ($name == "test") { + return "Hello World"; + } else { + return SoapFault("Server","Function $name doesn't exist"); + } + } +} + +$foo = new Foo(); +$server = new SoapServer(null,array('uri'=>"http://testuri.org")); +$server->setObject($foo); + +$HTTP_RAW_POST_DATA = <<<EOF +<?xml version="1.0" encoding="ISO-8859-1"?> +<SOAP-ENV:Envelope + SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:si="http://soapinterop.org/xsd"> + <SOAP-ENV:Body> + <ns1:test xmlns:ns1="http://testuri.org" /> + </SOAP-ENV:Body> +</SOAP-ENV:Envelope> +EOF; + +$server->handle(); +echo "ok\n"; +?> +--EXPECT-- +<?xml version="1.0" encoding="UTF-8"?> +<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testuri.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:testResponse><return xsi:type="xsd:string">Hello World</return></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> +ok
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php