From: Dmitry Stogov Date: Thu, 24 Aug 2006 06:18:30 +0000 (+0000) Subject: Added SoapServer::setObject() method (it is a simplified version of SoapServer::setCl... X-Git-Tag: RELEASE_1_2_2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92f1b46fbba7873c1256d64eac2dac5f7ffc7c1b;p=php Added SoapServer::setObject() method (it is a simplified version of SoapServer::setClass() method). --- diff --git a/NEWS b/NEWS index aa758dccdf..5b464025da 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? Sep 2006, PHP 5.2.0 +- Added SoapServer::setObject() method (it is a simplified version of + SoapServer::setClass() method). (Dmitry) - Added support for hexadecimal entity in imagettftext() for the bundled GD. (Pierre) - Fixed bug #38543 (shutdown_executor() may segfault when memory_limit is too diff --git a/ext/soap/php_soap.h b/ext/soap/php_soap.h index d6988cd0f0..39dbe3e5d3 100644 --- a/ext/soap/php_soap.h +++ b/ext/soap/php_soap.h @@ -114,6 +114,8 @@ struct _soapService { int persistance; } soap_class; + zval *soap_object; + HashTable *mapping; int version; int type; @@ -127,6 +129,7 @@ struct _soapService { #define SOAP_CLASS 1 #define SOAP_FUNCTIONS 2 +#define SOAP_OBJECT 3 #define SOAP_FUNCTIONS_ALL 999 #define SOAP_MAP_FUNCTION 1 diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 135d6f49d4..5f1dc96523 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -239,6 +239,7 @@ PHP_FUNCTION(is_soap_fault); /* 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); @@ -302,6 +303,7 @@ static zend_function_entry soap_server_functions[] = { 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) @@ -1257,6 +1259,33 @@ PHP_METHOD(SoapServer, setClass) /* }}} */ +/* {{{ proto void SoapServer::setObject(object) + Sets object which will handle SOAP requests */ +PHP_METHOD(SoapServer, setObject) +{ + soapServicePtr service; + zval *obj; + + SOAP_SERVER_BEGIN_CODE(); + + FETCH_THIS_SERVICE(service); + + 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) Returns list of defined functions */ PHP_METHOD(SoapServer, getFunctions) @@ -1270,7 +1299,9 @@ PHP_METHOD(SoapServer, getFunctions) FETCH_THIS_SERVICE(service); 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); @@ -1289,7 +1320,7 @@ PHP_METHOD(SoapServer, getFunctions) 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_string(return_value, f->common.function_name, 1); } zend_hash_move_forward_ex(ft, &pos); @@ -1563,7 +1594,10 @@ PHP_METHOD(SoapServer, handle) 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) { @@ -1666,7 +1700,6 @@ PHP_METHOD(SoapServer, handle) #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) { @@ -1695,9 +1728,9 @@ PHP_METHOD(SoapServer, handle) 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); @@ -1716,7 +1749,7 @@ PHP_METHOD(SoapServer, handle) php_end_ob_buffer(0, 0 TSRMLS_CC); 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; #ifdef ZEND_ENGINE_2 } else if (EG(exception)) { @@ -1732,7 +1765,7 @@ PHP_METHOD(SoapServer, handle) 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; #endif } @@ -1745,17 +1778,19 @@ PHP_METHOD(SoapServer, handle) 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); } @@ -1771,12 +1806,14 @@ PHP_METHOD(SoapServer, handle) 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; } @@ -4593,5 +4630,8 @@ static void delete_service(void *data) zend_hash_destroy(service->class_map); FREE_HASHTABLE(service->class_map); } + if (service->soap_object) { + zval_ptr_dtor(&service->soap_object); + } efree(service); } diff --git a/ext/soap/tests/server026.phpt b/ext/soap/tests/server026.phpt new file mode 100755 index 0000000000..a473a8540a --- /dev/null +++ b/ext/soap/tests/server026.phpt @@ -0,0 +1,37 @@ +--TEST-- +SOAP Server 26: setObject +--SKIPIF-- + +--FILE-- +"http://testuri.org")); +$server->setObject($foo); + +$HTTP_RAW_POST_DATA = << + + + + + +EOF; + +$server->handle(); +echo "ok\n"; +?> +--EXPECT-- + +Hello World +ok diff --git a/ext/soap/tests/server027.phpt b/ext/soap/tests/server027.phpt new file mode 100755 index 0000000000..9fee4a6087 --- /dev/null +++ b/ext/soap/tests/server027.phpt @@ -0,0 +1,30 @@ +--TEST-- +SOAP Server 27: setObject and getFunctions +--SKIPIF-- + +--FILE-- +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 diff --git a/ext/soap/tests/server028.phpt b/ext/soap/tests/server028.phpt new file mode 100755 index 0000000000..17194b9e36 --- /dev/null +++ b/ext/soap/tests/server028.phpt @@ -0,0 +1,41 @@ +--TEST-- +SOAP Server 28: SoapServer::setObject and __call() +--SKIPIF-- + +--FILE-- +"http://testuri.org")); +$server->setObject($foo); + +$HTTP_RAW_POST_DATA = << + + + + + +EOF; + +$server->handle(); +echo "ok\n"; +?> +--EXPECT-- + +Hello World +ok