Пример #1
0
zval * yee_exception_to_array_recursive(zval *self, zval *exception) {
	zend_object *object        = (zend_object *)zend_object_store_get_object(self TSRMLS_CC);
	zend_object *except_object = (zend_object *)zend_object_store_get_object(exception TSRMLS_CC);
	zval *array;
	zval *name = NULL, *message = NULL, *code = NULL, *previous = NULL, *previous2 = NULL;
	
	MAKE_STD_ZVAL(array);
	array_init_size(array, 5);
	
	if (instanceof_function(except_object->ce, yee_ce_Exception)) {
		zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getname"), &name, 0, NULL, NULL);
	}else {
		MAKE_STD_ZVAL(name);
		ZVAL_STRING(name, "Exception", 1);
	}
	
	zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getmessage"), &message, 0, NULL, NULL);
	zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getcode"), &code, 0, NULL, NULL);
	zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getprevious"), &previous, 0, NULL, NULL);
	
	add_assoc_string_ex(array, ZEND_STRS("type"), (char *)except_object->ce->name, 1);
	add_assoc_zval_ex(array, ZEND_STRS("name"), name);
	add_assoc_zval_ex(array, ZEND_STRS("message"), message);
	add_assoc_zval_ex(array, ZEND_STRS("code"), code);
	
	if (previous && previous->type == IS_OBJECT) {
		previous2 = yee_exception_to_array_recursive(self, previous);
		add_assoc_zval_ex(array, ZEND_STRS("previous"), previous2);
	}
	zval_dtor(previous);
	efree(previous);
	
	return array;
}
Пример #2
0
/** {{{ public ZeRecorder::fetch()
 */
PHP_METHOD(ze_recorder, fetch) {
	zval *   self        = NULL;
	zval *   stmt        = NULL;
	long     style       = 0;
	zval *   style_z     = NULL;
	zval *   success     = NULL;
	zval *   row         = NULL;

	/* PDO::FETCH_ASSOC */
	style   =   2;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l"
							 , &style
							 ) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	/* call execute */
	/* call fetch */

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);

	do {
		if (!stmt || Z_TYPE_P(stmt) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.fetch.stmt.not_object");
			break;
		}

		zend_call_method(&stmt, Z_OBJCE_P(stmt), NULL, ZEND_STRL("execute"), &success, 0, NULL, NULL TSRMLS_CC);

		if (!success || EG(exception)) {
			zval_dtor(success);
			FREE_ZVAL(success);
			break;
		}

		convert_to_boolean(success);

		if (Z_BVAL_P(success) == 1) {
			ALLOC_INIT_ZVAL(style_z);
			ZVAL_LONG(style_z, style);
			zend_call_method(&stmt, NULL, NULL, ZEND_STRL("fetch"), &row, 1, style_z, NULL TSRMLS_CC);
			zval_dtor(style_z);
			FREE_ZVAL(style_z);
		}

		zval_dtor(success);
		FREE_ZVAL(success);

	} while (0);

	if (row) {
		RETURN_ZVAL(row, 1, 1);
	} else {
		RETURN_FALSE;
	}
}
Пример #3
0
static void timecop_call_constructor_ex(zval *obj, zend_class_entry *ce, zval *params, int param_count, int call_original) {
	zval *arg1 = NULL, *arg2 = NULL;
	const char *func_name;
	size_t func_name_len;

	if (param_count > 2) {
		zend_error(E_ERROR, "INTERNAL ERROR: too many parameters for constructor.");
		return;
	}

	if (param_count == 1) {
		arg1 = &params[0];
	} else if (param_count == 2) {
		arg1 = &params[0];
		arg2 = &params[1];
	}

	if (call_original) {
		func_name = ORIG_FUNC_NAME("__construct");
		func_name_len = ORIG_FUNC_NAME_SIZEOF("__construct")-1;
	} else {
		func_name = "__construct";
		func_name_len = sizeof("__construct")-1;
	}

	zend_call_method(obj, ce, NULL, func_name, func_name_len, NULL, param_count, arg1, arg2);
}
Пример #4
0
static void signal_cb(uv_signal_t* handle, int signum)
{
    int status;
    zval zprocess, zhandler;
    pid_t pid = wait(&status);
    skyray_process_t *process = skyray_process_get_by_pid(pid);

    if (!process) {
        return;
    }

    process->status = SKYRAY_PROCESS_TERMINATED;
    process->exit_code = status;

    skyray_process_watcher_t *watcher = process->watcher;

    ZVAL_OBJ(&zprocess, &process->std);

    ZVAL_OBJ(&zhandler, watcher->handler);

    zend_call_method(&zhandler, NULL, NULL, ZEND_STRL("onExited"), NULL, 1, &zprocess, NULL);
    skyray_process_delete_by_pid(pid);

    skyray_process_watcher_stop(watcher);
}
Пример #5
0
/** {{{ public ZeRecorder::affected()
 */
PHP_METHOD(ze_recorder, affected) {
	zval *   self        = NULL;
	zval *   stmt        = NULL;
	zval *   row_count      = NULL;

	/* call row_count */

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);

	do {
		if (!stmt || Z_TYPE_P(stmt) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.affected.stmt.not_object");
			break;
		}


		zend_call_method(&stmt, NULL, NULL, ZEND_STRL("rowCount"), &row_count, 0, NULL, NULL TSRMLS_CC);

	} while (0);

	if (row_count) {
		 convert_to_long(row_count);
		 RETURN_ZVAL(row_count, 1, 1);
	} else {
		RETURN_FALSE;
	}
}
Пример #6
0
void yee_behavior_attach(zval *self, zval *owner) {
	zend_class_entry *ce = Z_OBJCE_P(self);
	zval *events = NULL, **handler_ptr;
	char *event;
	int event_size;
	
	zend_update_property(ce, self, ZEND_STRL("owner"), owner);
	
	zend_call_method(&self, ce, NULL, ZEND_STRL("events"), &events, 0, NULL, NULL);
	
	if (events && Z_TYPE_P(events) == IS_ARRAY) {
		HashTable *ht = Z_ARRVAL_P(events);
		zend_hash_internal_pointer_reset(ht);
		while(zend_hash_has_more_elements(ht) == SUCCESS) {
			zend_hash_get_current_key_ex(ht, &event, &event_size, NULL, 0, NULL);
			zend_hash_get_current_data(ht, (void **)&handler_ptr);
			
			zval *zv_event, *zv_handler;
			
			MAKE_STD_ZVAL(zv_event);
			ZVAL_STRINGL(zv_event, event, event_size - 1, 0);
			
			if (Z_TYPE_PP(handler_ptr) == IS_STRING) {
				MAKE_STD_ZVAL(zv_handler);
				array_init(zv_handler);
				add_next_index_zval(zv_handler, self);
				add_next_index_zval(zv_handler, *handler_ptr);

				zval_addref_p(self);
			}else {
				zv_handler = *handler_ptr;
			}
			
			zend_call_method(&owner, Z_OBJCE_P(owner), NULL, ZEND_STRL("on"), NULL, 2, zv_event, zv_handler);
			
			efree(zv_event);
			if (zv_handler != *handler_ptr) {
				zval_ptr_dtor(&zv_handler);
			}
			zend_hash_move_forward(ht);
		}
		
	}
	zval_ptr_dtor(&events);
}
Пример #7
0
/** {{{ public ZeRecorder::exec()
 */
PHP_METHOD(ze_recorder, exec) {
	zval *   self        = NULL;
	zval *   stmt        = NULL;
	zval *   success     = NULL;
	zval *   row_count    = NULL;

	/* call execute */
	/* call rowCount */

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);

	do {
		if (!stmt || Z_TYPE_P(stmt) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.exec.stmt.not_object");
			break;
		}

		zend_call_method(&stmt, Z_OBJCE_P(stmt), NULL, ZEND_STRL("execute"), &success, 0, NULL, NULL TSRMLS_CC);

		if (!success || EG(exception)) {
			break;
		}

		convert_to_boolean(success);

		if (Z_BVAL_P(success) == 1) {
			zend_call_method(&stmt, NULL, NULL, ZEND_STRL("rowCount"), &row_count, 0, NULL, NULL TSRMLS_CC);
		}

		zval_dtor(success);
		FREE_ZVAL(success);

	} while (0);

	if (row_count) {
		 convert_to_long(row_count);
		 RETURN_ZVAL(row_count, 1, 1);
	} else {
		RETURN_FALSE;
	}

}
Пример #8
0
// Create a PHP object given a typename and call the ctor, optionally passing up to 2 arguments
void createObject(char* obj_typename, zval* return_value, int nargs = 0, zval* arg1 = NULL, zval* arg2 = NULL) {
    TSRMLS_FETCH();
    size_t obj_typename_len = strlen(obj_typename);
    zend_class_entry* ce = zend_fetch_class(obj_typename, obj_typename_len, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);
    if (! ce) {
        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s does not exist", obj_typename);
        RETURN_NULL();
    }

    object_and_properties_init(return_value, ce, NULL);
    zend_function* constructor = zend_std_get_constructor(return_value TSRMLS_CC);
    zval* ctor_rv = NULL;
    zend_call_method(&return_value, ce, &constructor, NULL, 0, &ctor_rv, nargs, arg1, arg2 TSRMLS_CC);
    zval_ptr_dtor(&ctor_rv);
}
Пример #9
0
// Create a PHP object given a typename and call the ctor, optionally passing up to 2 arguments
static
void createObject(const char* obj_typename, zval* return_value, int nargs = 0, zval* arg1 = nullptr, zval* arg2 = nullptr) {
  /* is there a better way to do that on the stack ? */
  zend_string *obj_name = zend_string_init(obj_typename, strlen(obj_typename), 0);
  zend_class_entry* ce = zend_fetch_class(obj_name, ZEND_FETCH_CLASS_DEFAULT);
  zend_string_release(obj_name);

  if (! ce) {
    php_error_docref(nullptr, E_ERROR, "Class %s does not exist", obj_typename);
    RETURN_NULL();
  }

  object_and_properties_init(return_value, ce, nullptr);
  zend_function* constructor = zend_std_get_constructor(Z_OBJ_P(return_value));
  zval ctor_rv;
  zend_call_method(return_value, ce, &constructor, NULL, 0, &ctor_rv, nargs, arg1, arg2);
  zval_dtor(&ctor_rv);
}
Пример #10
0
/** {{{ public ZeRecorder::lastId()
 */
PHP_METHOD(ze_recorder, lastId) {
	zval *   self        = NULL;
	zval *   conn        = NULL;
	char *   name        = NULL;
	int      name_len    = 0;
	zval *   name_z      = NULL;
	zval *   lastid      = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s"
							 , &name, &name_len
							 ) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	/* call lastInsertId */

	self = getThis();

	conn = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_PDO_DBH), 0 TSRMLS_CC);

	do {
		if (!conn || Z_TYPE_P(conn) != IS_OBJECT) {

			ze_error(E_ERROR TSRMLS_CC, "recorder.lastId.conn.not_object");
			break;
		}

		ALLOC_INIT_ZVAL(name_z);
		ZVAL_STRINGL(name_z, name, name_len, 1);
		zend_call_method(&conn, NULL, NULL, ZEND_STRL("lastInsertId"), &lastid, 1, name_z, NULL TSRMLS_CC);
		zval_dtor(name_z);
		FREE_ZVAL(name_z);

	} while (0);


	if (lastid) {
		 convert_to_long(lastid);
		 RETURN_ZVAL(lastid, 1, 1);
	} else {
		RETURN_FALSE;
	}
}
Пример #11
0
char * exception_error(zval *exception, int severity TSRMLS_DC) {
    char * result;
    zend_class_entry *ce_exception = Z_OBJCE_P(exception);
    if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
        zval *str, *file, *line;

        EG(exception) = NULL;
        zend_call_method(&exception, ce_exception, NULL, "__tostring", 10, &str, 0, NULL, NULL TSRMLS_CC);
        if (!EG(exception)) {
            if (Z_TYPE_P(str) != IS_STRING) {
                result = "Exception::__toString() must return a string";
            } else {
                zend_update_property_string(default_exception_ce, exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name : Z_STRVAL_P(str) TSRMLS_CC);
            }
        }
        zval_ptr_dtor(&str);

        if (EG(exception)) {
            /* do the best we can to inform about the inner exception */
            if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
                file = zend_read_property(default_exception_ce, EG(exception), "file", sizeof("file")-1, 1 TSRMLS_CC);
                line = zend_read_property(default_exception_ce, EG(exception), "line", sizeof("line")-1, 1 TSRMLS_CC);
            } else {
                file = NULL;
                line = NULL;
            }
            result = "Uncaught in exception handling during call to __tostring()";
        }

        str = zend_read_property(default_exception_ce, exception, "string", sizeof("string")-1, 1 TSRMLS_CC);
        file = zend_read_property(default_exception_ce, exception, "file", sizeof("file")-1, 1 TSRMLS_CC);
        line = zend_read_property(default_exception_ce, exception, "line", sizeof("line")-1, 1 TSRMLS_CC);

        result = "Uncaught %s\n  thrown";
    } else {
        size_t n = snprintf(NULL, 0, "Uncaught exception '%s'", ce_exception->name);
        result = malloc(n + 1);
        snprintf(result, n + 1, "Uncaught exception '%s'", ce_exception->name);
    }
    return result;
}
zval * activerecord_model_magic_set( zval * model, char * name, int name_len, zval * value )
{
    zval ** alias, * retval = NULL;

    if( zend_hash_find( Z_ARRVAL_P(zend_read_static_property(activerecord_model_ce, "alias_attribute", 15, 0 TSRMLS_CC)), name, name_len, (void**)&alias ) == SUCCESS )
    {
        efree( name );
        emalloc( name, sizeof( Z_STRVAL_PP(alias) ) );
        strncpy( name, Z_STRVAL_PP(alias), Z_STRLEN_PP(alias) );
        name_len = Z_STRLEN_PP(alias);
    }
    else
    {
        char *method_name;
        emalloc( method_name, sizeof(name)+4 );
        strcpy( method_name, "set_" );
        strcat( method_name, name );
        if( activerecord_model_array_search( zend_read_property( activerecord_model_ce, this_ptr, "setters", 7, 0 TSRMLS_CC ), method_name) )
        {
            zend_call_method( &this_ptr, activerecord_model_ce, NULL, method_name, sizeof(method_name), &retval, 0, NULL, NULL TSRMLS_CC );
            efree( name );
            RETURN_ZVAL( retval, 0, 0 );
        }
    }

    if( zend_hash_find( Z_ARRVAL_P(zend_read_property(activerecord_model_ce, model, "attributes", 10, 0 TSRMLS_CC)), name, name_len ) == SUCCESS )
    {
        retval = activerecord_model_assign_attribute( model, name, name_len, value );
    }

    efree( name );
    if( retval == NULL );
    // throw new exception

    RETURN_ZVAL( retval, 0, 0 );
}
Пример #13
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);
}
Пример #14
0
/** {{{ public ZeRecorder::query($sql = null, $args = null, $_ = null)
 */
PHP_METHOD(ze_recorder, query) {
	zval *   self      = NULL;
	zval *   conn      = NULL;
	zval *   stmt      = NULL;
	char *   query     = NULL;
	int      query_len = 0;
	zval *   sql       = NULL;
	zval *   keys      = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s"
				, &query
				, &query_len
				) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	/* call prepare */

	self = getThis();

	conn = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_PDO_DBH), 0 TSRMLS_CC);

	do {
		if (!conn || Z_TYPE_P(conn) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.query.conn.not_object");
			break;
		}

		MAKE_STD_ZVAL(keys);
		array_init(keys);

		sql = to_indexed(keys, query, query_len);

		if (!sql) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.query.sql.is_empty");
			break;
		}

		zend_call_method(&conn, Z_OBJCE_P(conn), NULL, ZEND_STRL("prepare"), &stmt, 1, sql, NULL TSRMLS_CC);

		if (!stmt || EG(exception)) {
			zval_dtor(keys);
			FREE_ZVAL(keys);
			ze_error(E_ERROR TSRMLS_CC, "recorder.query.stmt.not_object");
			break;
		}
		zend_update_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), stmt TSRMLS_CC);
		zend_update_property(ze_recorder_ce, self, ZEND_STRL(ZE_KEYS), keys TSRMLS_CC);

		if (stmt != NULL) {
			zval_ptr_dtor(&stmt);
		}

		if (keys != NULL) {
			zval_ptr_dtor(&keys);
		}

	} while (0);


	if (sql != NULL) {
		zval_dtor(sql);
		FREE_ZVAL(sql);
	}

	RETURN_ZVAL(self, 1, 0);
}
Пример #15
0
 //@todo
PHP_METHOD(ze_recorder, bind) {
	zval *   self                = NULL;
	zval *   stmt                = NULL;
	zval *   fields              = NULL;
	zval *   types               = NULL;
	HashTable * keys_table       = NULL;
	HashPosition keys_pointer    = NULL;
	HashTable * fields_table     = NULL;
	HashTable * types_table      = NULL;
	zval ** val                  = NULL;
	zval *  val_copy             = NULL;
	zval ** type                 = NULL;
	zval *  type_copy            = NULL;
	zval *  keys                 = NULL;
	zval ** key                  = NULL;
	int     pos                  = 0;
	zval *  pos_z                = NULL;
	zval ** params[3];

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z"
							, &fields
							, &types
							) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	if (Z_TYPE_P(fields) == IS_OBJECT && Z_OBJ_HT_P(fields)->get_properties != NULL) {
		fields_table = Z_OBJ_HT_P(fields)->get_properties(fields TSRMLS_CC);

	} else if (Z_TYPE_P(fields) == IS_ARRAY) {
		fields_table   = Z_ARRVAL_P(fields);
	}

	if (!fields_table) {
		/* need array or object for '$fields' . */
		ze_error(E_ERROR TSRMLS_CC, "recorder.bind.fields.type");
		return;
	}

	if (types) {
		if (Z_TYPE_P(fields) == IS_OBJECT && Z_OBJ_HT_P(types)->get_properties != NULL) {
			types_table = Z_OBJ_HT_P(types)->get_properties(types TSRMLS_CC);

		} else if (Z_TYPE_P(fields) == IS_ARRAY) {
			types_table    = Z_ARRVAL_P(types);

		}

		if (!types_table){
			/* need array or object for '$types' . */
			ze_error(E_ERROR TSRMLS_CC, "recorder.bind.types.type");
			return;
		}
	}

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);
	keys = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_KEYS), 0 TSRMLS_CC);

	do {

		if (!stmt || Z_TYPE_P(stmt) != IS_OBJECT) {
			 ze_error(E_ERROR TSRMLS_CC, "recorder.bind.stmt.null");
			 break;
		}

		if (!keys || Z_TYPE_P(keys) != IS_ARRAY) {
			 ze_error(E_ERROR TSRMLS_CC, "recorder.bind.keys.is_array");
			 break;
		}

		keys_table = Z_ARRVAL_P(keys);
		pos = 0;

		for (zend_hash_internal_pointer_reset_ex(keys_table, &keys_pointer);
				zend_hash_get_current_data_ex(keys_table,(void**) &key, &keys_pointer) == SUCCESS;
				zend_hash_move_forward_ex(keys_table, &keys_pointer)) {

			if (zend_hash_find(fields_table, Z_STRVAL_PP(key), Z_STRLEN_PP(key) + 1, (void **) &val) == SUCCESS) {
				pos++;
				ALLOC_INIT_ZVAL(pos_z);
				ZVAL_LONG(pos_z, pos);

				val_copy = *val;
				zval_copy_ctor(val_copy);

				if (types_table
					&& zend_hash_find(types_table, Z_STRVAL_PP(key), Z_STRLEN_PP(key) + 1, (void **) &type)  == SUCCESS) {

					type_copy = *type;
					zval_copy_ctor(type_copy);

					params[0] = &pos_z;
					params[1] = &val_copy;
					params[2] = &type_copy;

					ze_call_method(&stmt, NULL, NULL, ZEND_STRL("bindValue"), NULL, 3, params TSRMLS_CC);

				}else{
					zend_call_method(&stmt, NULL, NULL, ZEND_STRL("bindValue"), NULL, 2, pos_z, val_copy TSRMLS_CC);
				}

				zval_dtor(pos_z);
				FREE_ZVAL(pos_z);
			}
		}
	} while (0);

	RETURN_ZVAL(self, 1, 0);
}
Пример #16
0
/** {{{ public ZeRecorder::getInt()
 */
PHP_METHOD(ze_recorder, getInt) {
	zval *   self        = NULL;
	zval *   stmt        = NULL;
	zval *   success     = NULL;
	zval *   row         = NULL;
	long     style       = 0;
	zval *   style_z     = NULL;
	long     count       = 0;
	zval **  count_z     = NULL;


	/* PDO::FETCH_NUM */
	style   =   3;

	/* call execute */
	/* call fetch */

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);
	do {
		if (!stmt) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.fetch.stmt.null");
			break;
		}

		if (Z_TYPE_P(stmt) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.fetch.stmt.not_object");
			break;
		}

		zend_call_method(&stmt, Z_OBJCE_P(stmt), NULL, ZEND_STRL("execute"), &success, 0, NULL, NULL TSRMLS_CC);

		if (!success || EG(exception)) {
			break;
		}

		convert_to_boolean(success);

		if (Z_BVAL_P(success) == 1) {
			ALLOC_INIT_ZVAL(style_z);
			ZVAL_LONG(style_z, style);
			zend_call_method(&stmt, NULL, NULL, ZEND_STRL("fetch"), &row, 1, style_z, NULL TSRMLS_CC);
			zval_dtor(style_z);
			FREE_ZVAL(style_z);
		}

		zval_dtor(success);
		FREE_ZVAL(success);

		if (!row) {
			break;
		}

		if (Z_TYPE_P(row) == IS_ARRAY
				&& zend_hash_has_more_elements(Z_ARRVAL_P(row)) == SUCCESS
				&& zend_hash_get_current_data(Z_ARRVAL_P(row), (void **) &count_z) == SUCCESS) {

				convert_to_long_ex(count_z);
				count = Z_LVAL_PP(count_z);

				zval_dtor(*count_z);
				FREE_ZVAL(*count_z);
			}

		zval_dtor(row);
		FREE_ZVAL(row);
	} while (0);

	RETURN_LONG(count);
}
Пример #17
0
zval * yee_exception_to_array(zval *self) {
	zend_object *object = zend_object_store_get_object(self);
	zval *ret = NULL;
	zend_call_method(&self, object->ce, NULL, ZEND_STRL("toarrayrecursive"), &ret, 1, self, NULL);
	return ret;
}
Пример #18
0
static void _timecop_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
	zend_bool get_as_float = 0;
	long fixed_sec = 0, fixed_usec = 0;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) {
		return;
	}

	switch (TIMECOP_G(timecop_mode)) {
	case TIMECOP_MODE_FREEZE:
		fixed_sec = TIMECOP_G(freezed_timestamp);
		fixed_usec = 0;
		break;
	case TIMECOP_MODE_TRAVEL:
		{
			zval timeofday, *zv_sec, *zv_usec;
			timecop_call_orig_method_with_0_params(NULL, NULL, NULL, "gettimeofday", &timeofday);
			zv_sec = zend_hash_str_find(Z_ARR(timeofday), "sec", sizeof("sec")-1);
			if (zv_sec) {
				fixed_sec = Z_LVAL_P(zv_sec) + TIMECOP_G(travel_offset);
			}
			zv_usec = zend_hash_str_find(Z_ARR(timeofday), "usec", sizeof("usec")-1);
			if (zv_sec) {
				fixed_usec = Z_LVAL_P(zv_usec);
			}
			zval_ptr_dtor(&timeofday);
		}
		break;
	default:
		{
			const char *func_name;
			size_t func_name_len;
			zval *arg1 = NULL, tmp;
			int param_count = 0;

			if (mode) {
				func_name = ORIG_FUNC_NAME("gettimeofday");
				func_name_len = ORIG_FUNC_NAME_SIZEOF("gettimeofday")-1;
			} else {
				func_name = ORIG_FUNC_NAME("microtime");
				func_name_len = ORIG_FUNC_NAME_SIZEOF("microtime")-1;
			}
			if (get_as_float) {
				ZVAL_TRUE(&tmp);
				arg1 = &tmp;
				param_count = 1;
			}
			zend_call_method(NULL, NULL, NULL, func_name, func_name_len, return_value, param_count, arg1, NULL);
			return;
		}
	}

	if (get_as_float) {
		RETURN_DOUBLE((double)(fixed_sec + fixed_usec / MICRO_IN_SEC));
	}
	if (mode) {
		zval zv_offset, zv_dst, format, timestamp;
		long offset = 0, is_dst = 0;

		ZVAL_LONG(&timestamp, fixed_sec);

		/* offset */
		ZVAL_STRING(&format, "Z");
		timecop_call_orig_method_with_2_params(NULL, NULL, NULL, "date", &zv_offset, &format, &timestamp);
		convert_to_long(&zv_offset);
		offset = Z_LVAL(zv_offset);
		zval_ptr_dtor(&zv_offset);
		zval_ptr_dtor(&format);

		/* is_dst */
		ZVAL_STRING(&format, "I");
		timecop_call_orig_method_with_2_params(NULL, NULL, NULL, "date", &zv_dst, &format, &timestamp);
		convert_to_long(&zv_dst);
		is_dst = Z_LVAL(zv_dst);
		zval_ptr_dtor(&zv_dst);
		zval_ptr_dtor(&format);

		array_init(return_value);
		add_assoc_long(return_value, "sec", fixed_sec);
		add_assoc_long(return_value, "usec", fixed_usec);
		add_assoc_long(return_value, "minuteswest", -offset / SEC_IN_MIN);
		add_assoc_long(return_value, "dsttime", is_dst);
	} else {
		char ret[100];
		snprintf(ret, 100, "%.8F %ld", fixed_usec / MICRO_IN_SEC, fixed_sec);
		RETURN_STRING(ret);
	}
}