Пример #1
0
bool pq_PHP_emit(const QString &qosignal, QObject *sender, QEvent *event)
{
    int index = PHPQt5::acceptedPHPSlots_indexes.value(sender, -1);

    if(index >= 0) {
        if(PHPQt5::acceptedPHPSlots_list.at(index).contains(qosignal)) {
            TSRMLS_FETCH();

            pq_access_function_entry afe = PHPQt5::acceptedPHPSlots_list.at(index).value(qosignal);
            zend_function *copy_fptr = zend_get_closure_invoke_method(afe.zo TSRMLS_CC);
            zval *zevent = PHPQt5::pq_qevent_to_zobject(event TSRMLS_CC);

            PHPQt5::pq_eventHash.insert(Z_OBJVAL_P(zevent).handle, pq_event_wrapper{zevent, event});
            zval *zobject = PHPQt5::objectFactory()->getZObject(sender);

            zend_call_method_with_2_params(&afe.zo,
                                           Z_OBJCE_P(afe.zo),
                                           &copy_fptr,
                                           "__invoke",
                                           NULL,
                                           zobject,
                                           zevent);

            PHPQt5::pq_eventHash.remove(Z_OBJVAL_P(zevent).handle);
            zval_ptr_dtor(&zevent);

            return true;
        }
    }

    return false;
}
Пример #2
0
ZEND_METHOD(Nc_Sql_MasterSlaveConnection, query)
{
    zval *sql, *flag;
    zval *connection, *r;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql, &flag) == FAILURE || Z_TYPE_P(flag) != IS_LONG)
        return;

    if (Z_LVAL_P(flag) & NC_SQL_CONNECTION_WRITE)
    {
        connection = nc_kernel_injection_property(getThis(), "masterConnection", Nc_Sql_Connection_ce);
    }
    else
    {
        connection = nc_kernel_injection_property(getThis(), "slaveConnection", Nc_Sql_Connection_ce);
    }

    if (!connection)
        return;

    r = zend_call_method_with_2_params(&connection, Z_OBJCE_P(connection), NULL, "query", &r, sql, flag);
    zval_ptr_dtor(&connection);

    if (!r)
    {
        zend_throw_exception(Nc_Sql_Exception_ce, "Cannot invoke query of injection property masterConnection/slaveConnection.", 0 TSRMLS_CC);
        return;
    }

    RETVAL_ZVAL(r, 0, 0);
    efree(r);
}
static PHP_METHOD(php_midgard_reflection_method, __construct)
{
	zval *this = getThis();
	zval *arg1, *arg2;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &arg1, &arg2) == FAILURE)
		return;

	zend_call_method_with_2_params(&this, zend_reflection_function_class, &zend_reflection_function_class->constructor, "__construct", NULL, arg1, arg2);
}
Пример #4
0
PHP_METHOD(swoole_http_server, on)
{
    zval *callback;
    zval *event_name;
    swServer *serv;

    if (SwooleGS->start > 0)
    {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server is running. Unable to set event callback now.");
        RETURN_FALSE;
    }

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &event_name, &callback) == FAILURE)
    {
        return;
    }

    SWOOLE_GET_SERVER(getThis(), serv);

    char *func_name = NULL;
    if (!zend_is_callable(callback, 0, &func_name TSRMLS_CC))
    {
        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Function '%s' is not callable", func_name);
        efree(func_name);
        RETURN_FALSE;
    }
    efree(func_name);

    if (strncasecmp("request", Z_STRVAL_P(event_name), Z_STRLEN_P(event_name)) == 0)
    {
        zval_add_ref(&callback);
        php_sw_http_server_callbacks[0] = callback;
    }
    else if (strncasecmp("message", Z_STRVAL_P(event_name), Z_STRLEN_P(event_name)) == 0)
    {
        zval_add_ref(&callback);
        php_sw_http_server_callbacks[1] = callback;
    }
    else if (strncasecmp("handshake", Z_STRVAL_P(event_name), Z_STRLEN_P(event_name)) == 0)
    {
        zval_add_ref(&callback);
        php_sw_http_server_callbacks[2] = callback;
    }
    else if (strncasecmp("open", Z_STRVAL_P(event_name), Z_STRLEN_P(event_name)) == 0)
    {
        zval_add_ref(&callback);
        php_sw_http_server_callbacks[3] = callback;
    }
    else
    {
        zend_call_method_with_2_params(&getThis(), swoole_server_class_entry_ptr, NULL, "on", &return_value, event_name, callback);
    }
}
static PHP_METHOD(php_midgard_reflection_class, getMethods)
{
	zval *filter = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &filter) == FAILURE)
		return;

	zval *this = getThis();

	zval *class_name = NULL;
	zend_call_method_with_0_params(&this, zend_reflection_class_class, NULL, "getname", &class_name);

	zval *result = NULL;

	if (filter) {
		zend_call_method_with_1_params(&this, zend_reflection_class_class, NULL, "getmethods", &result, filter);
	} else {
		zend_call_method_with_0_params(&this, zend_reflection_class_class, NULL, "getmethods", &result);
	}

	array_init(return_value);

	HashTable *parent_ht = Z_ARRVAL_P(result);
	for(
		zend_hash_internal_pointer_reset(parent_ht);
		zend_hash_has_more_elements(parent_ht) == SUCCESS;
		zend_hash_move_forward(parent_ht)
	) {
		zval **ppzval = NULL;
		zend_hash_get_current_data(parent_ht, (void**)&ppzval);

		zval *method_name = NULL;
		zend_call_method_with_0_params(ppzval, zend_reflection_function_class, NULL, "getname", &method_name);

		zval *new_obj = NULL;
		MAKE_STD_ZVAL(new_obj);
		object_init_ex(new_obj, php_midgard_reflection_method_class);
		zend_call_method_with_2_params(&new_obj,
		                               php_midgard_reflection_method_class,
		                               &php_midgard_reflection_method_class->constructor, "__construct",
		                               NULL, class_name, method_name
		);
		zval_ptr_dtor(&method_name);

		add_next_index_zval(return_value, new_obj);
	}

	zval_ptr_dtor(&result);
	zval_ptr_dtor(&class_name);
}
Пример #6
0
static int spl_ptr_heap_cmp_cb_helper(zval *object, spl_heap_object *heap_object, zval *a, zval *b, zend_long *result) { /* {{{ */
	zval zresult;

	zend_call_method_with_2_params(object, heap_object->std.ce, &heap_object->fptr_cmp, "compare", &zresult, a, b);

	if (EG(exception)) {
		return FAILURE;
	}

	*result = zval_get_long(&zresult);
	zval_ptr_dtor(&zresult);

	return SUCCESS;
}
Пример #7
0
PHP_METHOD(air_async_waiter, serve) {
	AIR_INIT_THIS;
	zval *request = NULL;
	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &request) == FAILURE){
		AIR_NEW_EXCEPTION(1, "invalid serve param");
	}

	zval *service = NULL;
	MAKE_STD_ZVAL(service);
	object_init_ex(service, air_async_service_ce);
	zend_call_method_with_2_params(&service, air_async_service_ce, NULL, "__construct", NULL, self, request);
	zval *services = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_services"), 0 TSRMLS_CC);
	zval *service_id = zend_read_property(Z_OBJCE_P(service), service, ZEND_STRL("_id"), 1 TSRMLS_CC);
	add_index_zval(services, Z_LVAL_P(service_id), service);
	RETURN_ZVAL(service, 1, 0);
}
Пример #8
0
ONPHP_METHOD(Form, getErrors)
{
	zval
		*out,
		*errors = ONPHP_READ_PROPERTY(getThis(), "errors"),
		*violated = ONPHP_READ_PROPERTY(getThis(), "violated");
	
	zend_call_method_with_2_params(
		NULL,
		NULL,
		NULL,
		"array_merge",
		&out,
		errors,
		violated
	);
	
	RETURN_ZVAL(out, 1, 1);
}
Пример #9
0
/* Object constructor */
static PHP_METHOD(midgard_datetime, __construct)
{
	char *time_str = "now";
	int time_str_len;
	zval *self = getThis();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &time_str, &time_str_len) == FAILURE)
		return;

	zval *timezone_object = get_UTC_timezone(TSRMLS_C);

	/* Copy of time-string */
	zval *dt_str;
	MAKE_STD_ZVAL(dt_str);
	ZVAL_STRING(dt_str, time_str, 1);

	/* Call parent constructor - parent::__construct */
	zend_call_method_with_2_params(&self, zend_datetime_class_ptr, &zend_datetime_class_ptr->constructor, "__construct", NULL, dt_str, timezone_object);
	zval_ptr_dtor(&dt_str);
	zval_ptr_dtor(&timezone_object);
}
Пример #10
0
static void spl_fixedarray_object_write_dimension(zval *object, zval *offset, zval *value) /* {{{ */
{
	spl_fixedarray_object *intern;
	zval tmp;

	intern = Z_SPLFIXEDARRAY_P(object);

	if (intern->fptr_offset_set) {
		if (!offset) {
			ZVAL_NULL(&tmp);
			offset = &tmp;
		} else {
			SEPARATE_ARG_IF_REF(offset);
		}
		SEPARATE_ARG_IF_REF(value);
		zend_call_method_with_2_params(object, intern->std.ce, &intern->fptr_offset_set, "offsetSet", NULL, offset, value);
		zval_ptr_dtor(value);
		zval_ptr_dtor(offset);
		return;
	}

	spl_fixedarray_object_write_dimension_helper(intern, offset, value);
}
Пример #11
0
U_CFUNC PHP_FUNCTION(intlcal_to_date_time)
{
	zval retval;
	CALENDAR_METHOD_INIT_VARS;

	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
			&object, Calendar_ce_ptr) == FAILURE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intlcal_to_date_time: bad arguments", 0 TSRMLS_CC);
		RETURN_FALSE;
	}

	CALENDAR_METHOD_FETCH_OBJECT;

	/* There are no exported functions in ext/date to this
	 * in a more native fashion */
	double	date = co->ucal->getTime(CALENDAR_ERROR_CODE(co)) / 1000.;
	int64_t	ts;
	char	ts_str[sizeof("@-9223372036854775808")];
	int		ts_str_len;
	zval	ts_tmp, ts_zval, tmp;

	INTL_METHOD_CHECK_STATUS(co, "Call to ICU method has failed");

	if (date > (double)U_INT64_MAX || date < (double)U_INT64_MIN) {
		intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR,
			"intlcal_to_date_time: The calendar date is out of the "
			"range for a 64-bit integer", 0 TSRMLS_CC);
		RETURN_FALSE;
	}
	
	ZVAL_UNDEF(&retval);
	ts = (int64_t)date;

	ts_str_len = slprintf(ts_str, sizeof(ts_str), "@%I64d", ts);
	ZVAL_STRINGL(&ts_zval, ts_str, ts_str_len);

	/* Now get the time zone */
	const TimeZone& tz = co->ucal->getTimeZone();
	zval *timezone_zval = timezone_convert_to_datetimezone(
		&tz, CALENDAR_ERROR_P(co), "intlcal_to_date_time", &tmp TSRMLS_CC);
	if (timezone_zval == NULL) {
		RETURN_FALSE;
	}

	/* resources allocated from now on */

	/* Finally, instantiate object and call constructor */
	object_init_ex(return_value, php_date_get_date_ce());
	zend_call_method_with_2_params(return_value, NULL, NULL, "__construct", NULL, &ts_zval, timezone_zval);
	if (EG(exception)) {
		intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR,
			"intlcal_to_date_time: DateTime constructor has thrown exception",
			1 TSRMLS_CC);
		zend_object_store_ctor_failed(Z_OBJ_P(return_value) TSRMLS_CC);
		zval_ptr_dtor(return_value);
		zval_ptr_dtor(&ts_zval);

		RETVAL_FALSE;
		goto error;
	}
	zval_ptr_dtor(&ts_zval);

	/* due to bug #40743, we have to set the time zone again */
	zend_call_method_with_1_params(return_value, NULL, NULL, "settimezone",
			&retval, timezone_zval);
	if (Z_ISUNDEF(retval) || Z_TYPE(retval) == IS_FALSE) {
		intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR,
			"intlcal_to_date_time: call to DateTime::setTimeZone has failed",
			1 TSRMLS_CC);
		zval_ptr_dtor(return_value);
		RETVAL_FALSE;
		goto error;
	}

error:
	zval_ptr_dtor(timezone_zval);
	zval_ptr_dtor(&retval);
}
Пример #12
0
PHP_METHOD(Edge_Controller, model)
{
    char *model_name = NULL;
    char *model_dir = NULL;
    int mnlen=0;
    int mdlen=0;
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &model_name, &mnlen, &model_dir, &mdlen) == FAILURE)
    {
        RETURN_FALSE;
    }
    
    char *model_class_name;
    int class_name_len;
    class_name_len = spprintf(&model_class_name, 0, "%s%s", model_name, "Model");

    zval **z_obj;
    if(zend_hash_find(Z_ARRVAL_P(EDGE_G(regs)), model_class_name, class_name_len+1, (void **)&z_obj) == SUCCESS)
    {
        efree(model_class_name);
        RETURN_ZVAL(*z_obj, 1, 0);
    }
    
    zval *config;
    zval *config_data;
    config = zend_read_static_property(edge_core_ce, ZEND_STRL("config"), 1 TSRMLS_DC);
    config_data = zend_read_property(edge_config_ce, config, ZEND_STRL("_data"), 1 TSRMLS_DC);

    zval **models_home_pp;
    if(zend_hash_find(Z_ARRVAL_P(config_data), "_models_home", strlen("_models_home")+1, (void **)&models_home_pp) == FAILURE)
    {
        RETURN_FALSE;
    }
    
    zval *z_model_name;
    MAKE_STD_ZVAL(z_model_name);
    ZVAL_STRING(z_model_name, model_class_name, 1);

    zval *loader;
    zval *ret;
    loader = zend_read_static_property(edge_core_ce, ZEND_STRL("loader"), 1 TSRMLS_DC);
    zend_call_method_with_2_params(&loader, Z_OBJCE_P(loader), NULL, "autoload", &ret, z_model_name, *models_home_pp);
    zval_ptr_dtor(&z_model_name);
    if(!Z_BVAL_P(ret))
    {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "model %s%s load fail", Z_STRVAL_PP(models_home_pp), model_class_name);
        zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "model %s%s load fail", Z_STRVAL_PP(models_home_pp), model_class_name);
        zval_ptr_dtor(&ret);
        efree(model_class_name);
        RETURN_FALSE;
    }
    zval_ptr_dtor(&ret);

    zend_class_entry **model_ce;
    if(zend_lookup_class(model_class_name, class_name_len, &model_ce TSRMLS_CC) == FAILURE)
    {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "model class %s not exist", model_class_name);
        zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "model class %s%s  not exist", model_class_name);
        efree(model_class_name);
        RETURN_FALSE;
    }

    zval *model_obj;
    MAKE_STD_ZVAL(model_obj);
    object_init_ex(model_obj, *model_ce);

    zval **cfptr;
    if(zend_hash_find(&((*model_ce)->function_table), "__construct", strlen("__construct")+1, (void **)&cfptr) == SUCCESS)
    {
        zval *cretval;
        zend_call_method(&model_obj, *model_ce, NULL, "__construct", strlen("__construct"), &cretval, 0, NULL, NULL TSRMLS_CC);
        zval_ptr_dtor(&cretval);
    }

    zend_hash_update(Z_ARRVAL_P(EDGE_G(regs)), model_class_name, class_name_len+1, (void **)&model_obj, sizeof(zval *), NULL);

    efree(model_class_name);
    RETURN_ZVAL(model_obj, 1, 0);
}