/* {{{ */ static PHP_METHOD(Closure, __construct) { zval *closure; if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) != SUCCESS) { return; } php_inspector_scope_construct(getThis(), (zend_function*) zend_get_closure_method_def(closure)); }
PHP_METHOD(jsonrpc_server, register) { zval *closure=NULL; zval *val; zval *name; zval *callbacks; char *lcname; char *name_str, *tmp; int name_len, tmp_len; zval *classname; zend_class_entry **pce; zend_class_entry *ce; zend_function *fptr; zval *object = getThis(); if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "zO", &name, &closure, zend_ce_closure) == SUCCESS) { fptr = (zend_function*)zend_get_closure_method_def(closure TSRMLS_CC); Z_ADDREF_P(closure); } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &name, &name_str, &name_len) == SUCCESS) { if ((tmp = strstr(name_str, "::")) == NULL) { char *nsname; lcname = zend_str_tolower_dup(name_str, name_len); // Ignore leading "\" nsname = lcname; if (lcname[0] == '\\') { nsname = &lcname[1]; name_len--; } if (zend_hash_find(EG(function_table), nsname, name_len + 1, (void **)&fptr) == FAILURE) { efree(lcname); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function %s() does not exist", name_str); return; } efree(lcname); }else { tmp_len = tmp - name_str; MAKE_STD_ZVAL(classname); ZVAL_STRINGL(classname, name_str, tmp_len, 1); name_len = name_len - (tmp_len + 2); name_str = tmp + 2; //php_printf("classname: %s, method: %s\n", Z_STRVAL_P(classname), name_str); if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s does exist", Z_STRVAL_P(classname)); //zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, // "Class %s does not exist", Z_STRVAL_P(classname)); zval_dtor(classname); return; } ce = *pce; lcname = zend_str_tolower_dup(name_str, name_len); if (zend_hash_find(&ce->function_table, lcname, name_len + 1, (void **) &fptr) == FAILURE) { efree(lcname); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Method %s::%s() does not exist", ce->name, name_str); //zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, // "Method %s::%s() does not exist", ce->name, name_str); return; } efree(lcname); } }else { return ; } callbacks = zend_read_property( php_jsonrpc_server_entry, object, "callbacks", sizeof("callbacks")-1, 0 TSRMLS_CC ); MAKE_STD_ZVAL(val); #if PHP_VERSION_ID < 50399 zend_create_closure(val, fptr TSRMLS_CC); #else zend_create_closure(val, fptr, NULL, NULL TSRMLS_CC); #endif add_assoc_zval(callbacks, Z_STRVAL_P(name), val); zend_update_property(php_jsonrpc_server_entry, object, "callbacks", sizeof("callbacks")-1, callbacks TSRMLS_CC); RETURN_ZVAL(object,1,0); }