void zend_exception_set_previous(zend_object *exception, zend_object *add_previous) /* {{{ */ { zval *previous, *ancestor, *ex; zval pv, zv, rv; zend_class_entry *base_ce; if (exception == add_previous || !add_previous || !exception) { return; } ZVAL_OBJ(&pv, add_previous); if (!instanceof_function(Z_OBJCE(pv), zend_ce_throwable)) { zend_error_noreturn(E_CORE_ERROR, "Previous exception must implement Throwable"); return; } ZVAL_OBJ(&zv, exception); ex = &zv; do { ancestor = zend_read_property_ex(i_get_exception_base(&pv), &pv, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); while (Z_TYPE_P(ancestor) == IS_OBJECT) { if (Z_OBJ_P(ancestor) == Z_OBJ_P(ex)) { OBJ_RELEASE(add_previous); return; } ancestor = zend_read_property_ex(i_get_exception_base(ancestor), ancestor, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); } base_ce = i_get_exception_base(ex); previous = zend_read_property_ex(base_ce, ex, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); if (Z_TYPE_P(previous) == IS_NULL) { zend_update_property_ex(base_ce, ex, ZSTR_KNOWN(ZEND_STR_PREVIOUS), &pv); GC_DELREF(add_previous); return; } ex = previous; } while (Z_OBJ_P(ex) != add_previous); }
static void php_lua_closure_free_obj(zend_object *zobj) /* {{{ */ { lua_closure_object *objval = php_lua_closure_object_from_zend_object(zobj); if ((Z_TYPE(objval->lua) == IS_OBJECT) && instanceof_function(Z_OBJCE(objval->lua), lua_ce)) { luaL_unref((Z_LUAVAL(objval->lua))->L, LUA_REGISTRYINDEX, objval->closure); } zval_dtor(&(objval->lua)); zend_object_std_dtor(zobj); } /* }}} */
/* {{{ proto ErrorException::__construct(string message, int code, int severity [, string filename [, int lineno [, Throwable previous]]]) ErrorException constructor */ ZEND_METHOD(error_exception, __construct) { char *message = NULL, *filename = NULL; zend_long code = 0, severity = E_ERROR, lineno; zval tmp, *object, *previous = NULL; int argc = ZEND_NUM_ARGS(); size_t message_len, filename_len; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|sllslO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, zend_ce_throwable) == FAILURE) { zend_class_entry *ce; if (Z_TYPE(EX(This)) == IS_OBJECT) { ce = Z_OBJCE(EX(This)); } else if (Z_CE(EX(This))) { ce = Z_CE(EX(This)); } else { ce = zend_ce_error_exception; } zend_throw_error(NULL, "Wrong parameters for %s([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Throwable $previous = NULL]]]]]])", ZSTR_VAL(ce->name)); return; } object = getThis(); if (message) { ZVAL_STRING(&tmp, message); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_MESSAGE], &tmp); zval_ptr_dtor(&tmp); } if (code) { ZVAL_LONG(&tmp, code); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_CODE], &tmp); } if (previous) { zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_PREVIOUS], previous); } ZVAL_LONG(&tmp, severity); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_SEVERITY], &tmp); if (argc >= 4) { ZVAL_STRING(&tmp, filename); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_FILE], &tmp); zval_ptr_dtor(&tmp); if (argc < 5) { lineno = 0; /* invalidate lineno */ } ZVAL_LONG(&tmp, lineno); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_LINE], &tmp); } }
/* {{{ zend_user_it_get_new_iterator */ ZEND_API zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *ce, zval *object, int by_ref) { zval iterator; zend_object_iterator *new_iterator; zend_class_entry *ce_it; zend_user_it_new_iterator(ce, object, &iterator); ce_it = (Z_TYPE(iterator) == IS_OBJECT) ? Z_OBJCE(iterator) : NULL; if (!ce_it || !ce_it->get_iterator || (ce_it->get_iterator == zend_user_it_get_new_iterator && Z_OBJ(iterator) == Z_OBJ_P(object))) { if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Objects returned by %s::getIterator() must be traversable or implement interface Iterator", ce ? ce->name->val : Z_OBJCE_P(object)->name->val); } zval_ptr_dtor(&iterator); return NULL; } new_iterator = ce_it->get_iterator(ce_it, &iterator, by_ref); zval_ptr_dtor(&iterator); return new_iterator; }
/* {{{ proto Exception|Error::__construct(string message, int code [, Throwable previous]) Exception constructor */ ZEND_METHOD(exception, __construct) { zend_string *message = NULL; zend_long code = 0; zval tmp, *object, *previous = NULL; zend_class_entry *base_ce; int argc = ZEND_NUM_ARGS(); object = getThis(); base_ce = i_get_exception_base(object); if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) { zend_class_entry *ce; if (Z_TYPE(EX(This)) == IS_OBJECT) { ce = Z_OBJCE(EX(This)); } else if (Z_CE(EX(This))) { ce = Z_CE(EX(This)); } else { ce = base_ce; } zend_throw_error(NULL, "Wrong parameters for %s([string $message [, long $code [, Throwable $previous = NULL]]])", ZSTR_VAL(ce->name)); return; } if (message) { ZVAL_STR(&tmp, message); zend_update_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_MESSAGE), &tmp); } if (code) { ZVAL_LONG(&tmp, code); zend_update_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_CODE), &tmp); } if (previous) { zend_update_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_PREVIOUS), previous); } }
int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr) /* {{{ */ { zend_closure *closure; if (Z_TYPE_P(obj) != IS_OBJECT) { return FAILURE; } closure = (zend_closure *)Z_OBJ_P(obj); *fptr_ptr = &closure->func; if (Z_TYPE(closure->this_ptr) != IS_UNDEF) { if (obj_ptr) { *obj_ptr = Z_OBJ(closure->this_ptr); } *ce_ptr = Z_OBJCE(closure->this_ptr); } else { if (obj_ptr) { *obj_ptr = NULL; } *ce_ptr = closure->func.common.scope; } return SUCCESS; }
static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */ { xsltTransformContextPtr tctxt; zval *args; zval retval; int result, i; int error = 0; zend_fcall_info fci; zval handler; xmlXPathObjectPtr obj; char *str; xsl_object *intern; zend_string *callable = NULL; if (! zend_is_executing()) { xsltGenericError(xsltGenericErrorContext, "xsltExtFunctionTest: Function called from outside of PHP\n"); error = 1; } else { tctxt = xsltXPathGetTransformContext(ctxt); if (tctxt == NULL) { xsltGenericError(xsltGenericErrorContext, "xsltExtFunctionTest: failed to get the transformation context\n"); error = 1; } else { intern = (xsl_object*)tctxt->_private; if (intern == NULL) { xsltGenericError(xsltGenericErrorContext, "xsltExtFunctionTest: failed to get the internal object\n"); error = 1; } else if (intern->registerPhpFunctions == 0) { xsltGenericError(xsltGenericErrorContext, "xsltExtFunctionTest: PHP Object did not register PHP functions\n"); error = 1; } } } if (error == 1) { for (i = nargs - 1; i >= 0; i--) { obj = valuePop(ctxt); xmlXPathFreeObject(obj); } return; } fci.param_count = nargs - 1; if (fci.param_count > 0) { args = safe_emalloc(fci.param_count, sizeof(zval), 0); } /* Reverse order to pop values off ctxt stack */ for (i = nargs - 2; i >= 0; i--) { obj = valuePop(ctxt); switch (obj->type) { case XPATH_STRING: ZVAL_STRING(&args[i], (char *)obj->stringval); break; case XPATH_BOOLEAN: ZVAL_BOOL(&args[i], obj->boolval); break; case XPATH_NUMBER: ZVAL_DOUBLE(&args[i], obj->floatval); break; case XPATH_NODESET: if (type == 1) { str = (char*)xmlXPathCastToString(obj); ZVAL_STRING(&args[i], str); xmlFree(str); } else if (type == 2) { int j; dom_object *domintern = (dom_object *)intern->doc; array_init(&args[i]); if (obj->nodesetval && obj->nodesetval->nodeNr > 0) { for (j = 0; j < obj->nodesetval->nodeNr; j++) { xmlNodePtr node = obj->nodesetval->nodeTab[j]; zval child; /* not sure, if we need this... it's copied from xpath.c */ if (node->type == XML_NAMESPACE_DECL) { xmlNsPtr curns; xmlNodePtr nsparent; nsparent = node->_private; curns = xmlNewNs(NULL, node->name, NULL); if (node->children) { curns->prefix = xmlStrdup((char *)node->children); } if (node->children) { node = xmlNewDocNode(node->doc, NULL, (char *) node->children, node->name); } else { node = xmlNewDocNode(node->doc, NULL, (const xmlChar *) "xmlns", node->name); } node->type = XML_NAMESPACE_DECL; node->parent = nsparent; node->ns = curns; } else { node = xmlDocCopyNodeList(domintern->document->ptr, node); } php_dom_create_object(node, &child, domintern); add_next_index_zval(&args[i], &child); } } } break; default: str = (char *) xmlXPathCastToString(obj); ZVAL_STRING(&args[i], str); xmlFree(str); } xmlXPathFreeObject(obj); } fci.size = sizeof(fci); fci.function_table = EG(function_table); if (fci.param_count > 0) { fci.params = args; } else { fci.params = NULL; } obj = valuePop(ctxt); if (obj->stringval == NULL) { php_error_docref(NULL, E_WARNING, "Handler name must be a string"); xmlXPathFreeObject(obj); valuePush(ctxt, xmlXPathNewString((const xmlChar *) "")); if (fci.param_count > 0) { for (i = 0; i < nargs - 1; i++) { zval_ptr_dtor(&args[i]); } efree(args); } return; } ZVAL_STRING(&handler, (char *) obj->stringval); xmlXPathFreeObject(obj); ZVAL_COPY_VALUE(&fci.function_name, &handler); fci.symbol_table = NULL; fci.object = NULL; fci.retval = &retval; fci.no_separation = 0; /*fci.function_handler_cache = &function_ptr;*/ if (!zend_make_callable(&handler, &callable)) { php_error_docref(NULL, E_WARNING, "Unable to call handler %s()", ZSTR_VAL(callable)); valuePush(ctxt, xmlXPathNewString((const xmlChar *) "")); } else if ( intern->registerPhpFunctions == 2 && zend_hash_exists(intern->registered_phpfunctions, callable) == 0) { php_error_docref(NULL, E_WARNING, "Not allowed to call handler '%s()'", ZSTR_VAL(callable)); /* Push an empty string, so that we at least have an xslt result... */ valuePush(ctxt, xmlXPathNewString((const xmlChar *) "")); } else { result = zend_call_function(&fci, NULL); if (result == FAILURE) { if (Z_TYPE(handler) == IS_STRING) { php_error_docref(NULL, E_WARNING, "Unable to call handler %s()", Z_STRVAL(handler)); valuePush(ctxt, xmlXPathNewString((const xmlChar *) "")); } /* retval is == NULL, when an exception occurred, don't report anything, because PHP itself will handle that */ } else if (Z_ISUNDEF(retval)) { } else { if (Z_TYPE(retval) == IS_OBJECT && instanceof_function(Z_OBJCE(retval), dom_node_class_entry)) { xmlNode *nodep; dom_object *obj; if (intern->node_list == NULL) { ALLOC_HASHTABLE(intern->node_list); zend_hash_init(intern->node_list, 0, NULL, ZVAL_PTR_DTOR, 0); } Z_ADDREF(retval); zend_hash_next_index_insert(intern->node_list, &retval); obj = Z_DOMOBJ_P(&retval); nodep = dom_object_get_node(obj); valuePush(ctxt, xmlXPathNewNodeSet(nodep)); } else if (Z_TYPE(retval) == IS_TRUE || Z_TYPE(retval) == IS_FALSE) { valuePush(ctxt, xmlXPathNewBoolean(Z_LVAL(retval))); } else if (Z_TYPE(retval) == IS_OBJECT) { php_error_docref(NULL, E_WARNING, "A PHP Object cannot be converted to a XPath-string"); valuePush(ctxt, xmlXPathNewString((const xmlChar *) "")); } else { convert_to_string_ex(&retval); valuePush(ctxt, xmlXPathNewString((xmlChar *) Z_STRVAL(retval))); } zval_ptr_dtor(&retval); } } zend_string_release(callable); zval_ptr_dtor(&handler); if (fci.param_count > 0) { for (i = 0; i < nargs - 1; i++) { zval_ptr_dtor(&args[i]); } efree(args); } }
static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */ { zval retval; int result, i; int error = 0; zend_fcall_info fci; xmlXPathObjectPtr obj; char *str; zend_string *callable = NULL; dom_xpath_object *intern; if (! zend_is_executing()) { xmlGenericError(xmlGenericErrorContext, "xmlExtFunctionTest: Function called from outside of PHP\n"); error = 1; } else { intern = (dom_xpath_object *) ctxt->context->userData; if (intern == NULL) { xmlGenericError(xmlGenericErrorContext, "xmlExtFunctionTest: failed to get the internal object\n"); error = 1; } else if (intern->registerPhpFunctions == 0) { xmlGenericError(xmlGenericErrorContext, "xmlExtFunctionTest: PHP Object did not register PHP functions\n"); error = 1; } } if (error == 1) { for (i = nargs - 1; i >= 0; i--) { obj = valuePop(ctxt); xmlXPathFreeObject(obj); } return; } fci.param_count = nargs - 1; if (fci.param_count > 0) { fci.params = safe_emalloc(fci.param_count, sizeof(zval), 0); } /* Reverse order to pop values off ctxt stack */ for (i = nargs - 2; i >= 0; i--) { obj = valuePop(ctxt); switch (obj->type) { case XPATH_STRING: ZVAL_STRING(&fci.params[i], (char *)obj->stringval); break; case XPATH_BOOLEAN: ZVAL_BOOL(&fci.params[i], obj->boolval); break; case XPATH_NUMBER: ZVAL_DOUBLE(&fci.params[i], obj->floatval); break; case XPATH_NODESET: if (type == 1) { str = (char *)xmlXPathCastToString(obj); ZVAL_STRING(&fci.params[i], str); xmlFree(str); } else if (type == 2) { int j; array_init(&fci.params[i]); if (obj->nodesetval && obj->nodesetval->nodeNr > 0) { for (j = 0; j < obj->nodesetval->nodeNr; j++) { xmlNodePtr node = obj->nodesetval->nodeTab[j]; zval child; /* not sure, if we need this... it's copied from xpath.c */ if (node->type == XML_NAMESPACE_DECL) { xmlNsPtr curns; xmlNodePtr nsparent; nsparent = node->_private; curns = xmlNewNs(NULL, node->name, NULL); if (node->children) { curns->prefix = xmlStrdup((xmlChar *) node->children); } if (node->children) { node = xmlNewDocNode(node->doc, NULL, (xmlChar *) node->children, node->name); } else { node = xmlNewDocNode(node->doc, NULL, (xmlChar *) "xmlns", node->name); } node->type = XML_NAMESPACE_DECL; node->parent = nsparent; node->ns = curns; } php_dom_create_object(node, &child, &intern->dom); add_next_index_zval(&fci.params[i], &child); } } } break; default: ZVAL_STRING(&fci.params[i], (char *)xmlXPathCastToString(obj)); } xmlXPathFreeObject(obj); } fci.size = sizeof(fci); fci.function_table = EG(function_table); obj = valuePop(ctxt); if (obj->stringval == NULL) { php_error_docref(NULL, E_WARNING, "Handler name must be a string"); xmlXPathFreeObject(obj); if (fci.param_count > 0) { for (i = 0; i < nargs - 1; i++) { zval_ptr_dtor(&fci.params[i]); } efree(fci.params); } return; } ZVAL_STRING(&fci.function_name, (char *) obj->stringval); xmlXPathFreeObject(obj); fci.symbol_table = NULL; fci.object = NULL; fci.retval = &retval; fci.no_separation = 0; if (!zend_make_callable(&fci.function_name, &callable)) { php_error_docref(NULL, E_WARNING, "Unable to call handler %s()", callable->val); } else if (intern->registerPhpFunctions == 2 && zend_hash_exists(intern->registered_phpfunctions, callable) == 0) { php_error_docref(NULL, E_WARNING, "Not allowed to call handler '%s()'.", callable->val); /* Push an empty string, so that we at least have an xslt result... */ valuePush(ctxt, xmlXPathNewString((xmlChar *)"")); } else { result = zend_call_function(&fci, NULL); if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { if (Z_TYPE(retval) == IS_OBJECT && instanceof_function(Z_OBJCE(retval), dom_node_class_entry)) { xmlNode *nodep; dom_object *obj; if (intern->node_list == NULL) { ALLOC_HASHTABLE(intern->node_list); zend_hash_init(intern->node_list, 0, NULL, ZVAL_PTR_DTOR, 0); } GC_REFCOUNT(&retval)++; zend_hash_next_index_insert(intern->node_list, &retval); obj = Z_DOMOBJ_P(&retval); nodep = dom_object_get_node(obj); valuePush(ctxt, xmlXPathNewNodeSet(nodep)); } else if (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE) { valuePush(ctxt, xmlXPathNewBoolean(Z_TYPE(retval) == IS_TRUE)); } else if (Z_TYPE(retval) == IS_OBJECT) { php_error_docref(NULL, E_WARNING, "A PHP Object cannot be converted to a XPath-string"); valuePush(ctxt, xmlXPathNewString((xmlChar *)"")); } else { zend_string *str = zval_get_string(&retval); valuePush(ctxt, xmlXPathNewString((xmlChar *) str->val)); zend_string_release(str); } zval_ptr_dtor(&retval); } } zend_string_release(callable); zval_dtor(&fci.function_name); if (fci.param_count > 0) { for (i = 0; i < nargs - 1; i++) { zval_ptr_dtor(&fci.params[i]); } efree(fci.params); } }
static int zephir_is_callable_check_class(const char *name, int name_len, zend_fcall_info_cache *fcc, int *strict_class, char **error) /* {{{ */ { int ret = 0; zend_class_entry *pce; char *lcname = zend_str_tolower_dup(name, name_len); *strict_class = 0; if (name_len == sizeof("self") - 1 && !memcmp(lcname, "self", sizeof("self") - 1)) { if (!EG(scope)) { if (error) *error = estrdup("cannot access self:: when no class scope is active"); } else { fcc->called_scope = EG(current_execute_data)->called_scope; if (!fcc->object) { fcc->object = Z_OBJ(EG(current_execute_data)->This); } ret = 1; } } else if (name_len == sizeof("parent") - 1 && !memcmp(lcname, "parent", sizeof("parent") - 1)) { if (!EG(scope)) { if (error) *error = estrdup("cannot access parent:: when no class scope is active"); } else if (!EG(scope)->parent) { if (error) *error = estrdup("cannot access parent:: when current class scope has no parent"); } else { fcc->called_scope = EG(current_execute_data)->called_scope; if (!fcc->object) { fcc->object = Z_OBJ(EG(current_execute_data)->This); } *strict_class = 1; ret = 1; } } else if (name_len == sizeof("static") - 1 && !memcmp(lcname, "static", sizeof("static") - 1)) { if (!EG(current_execute_data)->called_scope) { if (error) *error = estrdup("cannot access static:: when no class scope is active"); } else { fcc->called_scope = EG(current_execute_data)->called_scope; if (!fcc->object) { fcc->object = Z_OBJ(EG(current_execute_data)->This); } *strict_class = 1; ret = 1; } } else { zend_string *class_name; class_name = zend_string_init(name, name_len, 0); if ((pce = zend_lookup_class_ex(class_name, NULL, 1)) != NULL) { zend_class_entry *scope = EG(current_execute_data) ? EG(current_execute_data)->func->common.scope : NULL; fcc->calling_scope = pce; if (scope && !fcc->object && EG(current_execute_data) && Z_OBJ(EG(current_execute_data)->This) && instanceof_function(Z_OBJCE(EG(current_execute_data)->This), scope TSRMLS_CC) && instanceof_function(scope, fcc->calling_scope TSRMLS_CC)) { fcc->object = Z_OBJ(EG(current_execute_data)->This); fcc->called_scope = fcc->object->ce; } else { fcc->called_scope = fcc->object ? fcc->object->ce : fcc->calling_scope; } *strict_class = 1; ret = 1; } else { if (error) zephir_spprintf(error, 0, "class '%.*s' not found", name_len, name); } zend_string_free(class_name); } efree(lcname); return ret; }
void PHPQt5ConnectionWorker::process() { #ifdef PQDEBUG PQDBG_LVL_START(__FUNCTION__); #endif if(this->ctx == nullptr) { PQDBGLPUP("tsrm_get_ls_cache"); this->ctx = tsrm_get_ls_cache(); if(!this->ctx) { PQDBGLPUP("tsrm_new_interpreter_context"); this->ctx = tsrm_new_interpreter_context(); PQDBGLPUP("php_request_startup"); php_request_startup(); /* PQDBGLPUP("get interpreter context from thread"); void *TSRMLS_CACHE; bool php_started; QMetaObject::invokeMethod(this->thread(), "get_ls_cache", Qt::DirectConnection, Q_RETURN_ARG(void*, TSRMLS_CACHE)); if(!TSRMLS_CACHE) { php_error(E_ERROR, "Failed getting interpreter context from thread"); } QMetaObject::invokeMethod(this->thread(), "php_started", Qt::DirectConnection, Q_RETURN_ARG(bool, php_started)); PQDBGLPUP(QString("tsrm_set_interpreter_context %1") .arg(reinterpret_cast<quint64>(TSRMLS_CACHE))); this->ctx = TSRMLS_CACHE; tsrm_set_interpreter_context(TSRMLS_CACHE); if(!php_started) { PQDBGLPUP("php_request_startup"); php_request_startup(); QMetaObject::invokeMethod(this->thread(), "set_php_started", Qt::DirectConnection); } //PQDBGLPUP("php_request_startup"); //php_request_startup(); */ } } argc++; // the first argument for PHP-slots it is a PHP-object sender zval function_name, retval, z_receiver; zval *params = new zval[argc]; ZVAL_STRING(&function_name, slotName.constData()); ZVAL_OBJ(&z_receiver, zo_receiver); ZVAL_OBJ(¶ms[0], zo_sender); for(int i = 1; i < argc; i++) { QVariant arg = args.at(i-1); params[i] = PHPQt5::pq_cast_to_zval(arg, true PQDBG_LVL_CC); } #ifdef PQDEBUG PQDBGLPUP(QString("call function (%1)").arg(reinterpret_cast<quint64>(&z_receiver))); #endif //zend_call_method(&z_receiver, Z_OBJCE(z_receiver), NULL, ZEND_STRL("run"), &retval, 0, NULL, NULL); if(call_user_function(nullptr, &z_receiver, &function_name, &retval, argc, params) == FAILURE) { QString s = QString("PHPQt5 could not call method: %1 of class: %2") .arg(Z_STRVAL(function_name)) .arg(Z_OBJCE(z_receiver)->name->val); php_error(E_ERROR, s.toUtf8().constData()); } #ifdef PQDEBUG PQDBGLPUP("dtor params"); #endif for(int i = 1; i < argc; i++) { // do not remove sender! zval_dtor(¶ms[i]); } #ifdef PQDEBUG PQDBGLPUP("dtor temps"); #endif delete params; params = nullptr; zval_dtor(&retval); zval_dtor(&function_name); /* if(createNewCtx) { #ifdef PQDEBUG PQDBGLPUP("php_request_shutdown"); #endif php_request_shutdown(nullptr); #ifdef PQDEBUG PQDBGLPUP("tsrm_free_interpreter_context"); #endif tsrm_free_interpreter_context(ctx); } */ PQDBG_LVL_DONE(); }
/** {{{ proto LuaClosure::invoke(mxied $args) */ PHP_METHOD(lua_closure, invoke) { lua_closure_object *objval = php_lua_closure_object_from_zend_object(Z_OBJ_P(getThis())); int bp, sp; zval *arguments = NULL; lua_State *L = NULL; zval rv; if (ZEND_NUM_ARGS()) { arguments = emalloc(sizeof(zval*) * ZEND_NUM_ARGS()); if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) { efree(arguments); zend_throw_exception_ex(NULL, 0, "cannot get arguments for calling closure"); return; } } if (Z_TYPE(objval->lua) != IS_OBJECT || !instanceof_function(Z_OBJCE(objval->lua), lua_ce)) { zend_throw_exception_ex(NULL, 0, "corrupted Lua object"); return; } L = (Z_LUAVAL(objval->lua))->L; bp = lua_gettop(L); lua_rawgeti(L, LUA_REGISTRYINDEX, objval->closure); if (LUA_TFUNCTION != lua_type(L, lua_gettop(L))) { lua_pop(L, -1); zend_throw_exception_ex(NULL, 0, "call to lua closure failed"); return; } if (ZEND_NUM_ARGS()) { int i = 0; for(;i<ZEND_NUM_ARGS();i++) { php_lua_send_zval_to_lua(L, &arguments[i]); } } if (lua_pcall(L, ZEND_NUM_ARGS(), LUA_MULTRET, 0) != 0) { if (arguments) { efree(arguments); } lua_pop(L, lua_gettop(L) - bp); zend_throw_exception_ex(NULL, 0, "call to lua function %s failed", lua_tostring(L, -1)); return; } sp = lua_gettop(L) - bp; if (!sp) { RETURN_NULL(); } else if (sp == 1) { php_lua_get_zval_from_lua(L, -1, &(objval->lua), return_value); } else { zval rv; int i = 0; array_init(return_value); for (i = -sp; i < 0; i++) { php_lua_get_zval_from_lua(L, i, &(objval->lua), &rv); add_next_index_zval(return_value, &rv); } } lua_pop(L, sp); if (arguments) { efree(arguments); } }
/** * Resolves the service * * @param array $parameters * @param Phalcon\DIInterface $dependencyInjector * @return object */ PHP_METHOD(Phalcon_DI_Service, resolve){ zval *parameters = NULL, *dependency_injector = NULL, name = {}, shared = {}, shared_instance = {}, definition = {}, builder = {}; int found = 0, ishared = 0; phalcon_fetch_params(0, 0, 2, ¶meters, &dependency_injector); if (!parameters) { parameters = &PHALCON_GLOBAL(z_null); } if (!dependency_injector) { dependency_injector = &PHALCON_GLOBAL(z_null); } phalcon_return_property(&shared, getThis(), SL("_shared")); phalcon_return_property(&shared_instance, getThis(), SL("_sharedInstance")); ishared = zend_is_true(&shared); /* Check if the service is shared */ if (ishared && Z_TYPE(shared_instance) != IS_NULL) { RETURN_CTORW(&shared_instance); } phalcon_return_property(&definition, getThis(), SL("_definition")); if (Z_TYPE(definition) == IS_STRING) { /* String definitions can be class names without implicit parameters */ if (phalcon_class_exists(&definition, 1) != NULL) { found = 1; if (Z_TYPE_P(parameters) == IS_ARRAY) { RETURN_ON_FAILURE(phalcon_create_instance_params(return_value, &definition, parameters)); } else { RETURN_ON_FAILURE(phalcon_create_instance(return_value, &definition)); } } } else if (likely(Z_TYPE(definition) == IS_OBJECT)) { /* Object definitions can be a Closure or an already resolved instance */ found = 1; if (instanceof_function_ex(Z_OBJCE(definition), zend_ce_closure, 0)) { if (likely(Z_TYPE_P(dependency_injector) == IS_OBJECT)) { PHALCON_CALL_CE_STATICW(&definition, zend_ce_closure, "bind", &definition, dependency_injector); } if (Z_TYPE_P(parameters) == IS_ARRAY) { PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &definition, parameters); } else { PHALCON_CALL_USER_FUNCW(return_value, &definition); } } else { PHALCON_CPY_WRT(return_value, &definition); } } else if (Z_TYPE(definition) == IS_ARRAY) { found = 1; /* Array definitions require a 'className' parameter */ object_init_ex(&builder, phalcon_di_service_builder_ce); PHALCON_CALL_METHODW(return_value, &builder, "build", dependency_injector, &definition, parameters); } if (!EG(exception)) { if (found) { if (ishared) { phalcon_update_property_zval(getThis(), SL("_sharedInstance"), return_value); } /* Update the shared instance if the service is shared */ phalcon_update_property_bool(getThis(), SL("_resolved"), 1); } else { phalcon_return_property(&name, getThis(), SL("_name")); PHALCON_THROW_EXCEPTION_FORMATW(phalcon_di_exception_ce, "Service '%s' cannot be resolved", Z_STRVAL(name)); } } }