Example #1
0
/**
 * Returns a new Phalcon\Mvc\Model\Transaction or an already created once
 * This method registers a shutdown function to rollback active connections
 *
 * @param boolean $autoBegin
 * @return Phalcon\Mvc\Model\TransactionInterface
 */
PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, get){

	zval *auto_begin = NULL, *initialized, *rollback_pendent = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &auto_begin);
	
	if (!auto_begin) {
		PHALCON_INIT_VAR(auto_begin);
		ZVAL_BOOL(auto_begin, 1);
	}
	
	PHALCON_OBS_VAR(initialized);
	phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC);
	if (zend_is_true(initialized)) {
	
		PHALCON_OBS_VAR(rollback_pendent);
		phalcon_read_property_this(&rollback_pendent, this_ptr, SL("_rollbackPendent"), PH_NOISY_CC);
		if (zend_is_true(rollback_pendent)) {
			PHALCON_INIT_NVAR(rollback_pendent);
			array_init_size(rollback_pendent, 2);
			phalcon_array_append(&rollback_pendent, this_ptr, PH_SEPARATE);
			add_next_index_stringl(rollback_pendent, SL("rollbackPendent"), 1);
			phalcon_call_func_p1_noret("register_shutdown_function", rollback_pendent);
		}
	
		phalcon_update_property_bool(this_ptr, SL("_initialized"), 1 TSRMLS_CC);
	}
	
	phalcon_call_method(return_value, this_ptr, "getorcreatetransaction");
	RETURN_MM();
}
Example #2
0
/**
 * Rewinds resultset to its beginning
 *
 */
PHP_METHOD(Phalcon_Mvc_Model_Resultset, rewind){

	zval *type, *result = NULL, *active_row, *zero, *rows = NULL;

	PHALCON_MM_GROW();

	PHALCON_OBS_VAR(type);
	phalcon_read_property_this(&type, this_ptr, SL("_type"), PH_NOISY_CC);
	if (zend_is_true(type)) {
	
		/** 
		 * Here, the resultset act as a result that is fetched one by one
		 */
		PHALCON_OBS_VAR(result);
		phalcon_read_property_this(&result, this_ptr, SL("_result"), PH_NOISY_CC);
		if (PHALCON_IS_NOT_FALSE(result)) {
	
			PHALCON_OBS_VAR(active_row);
			phalcon_read_property_this(&active_row, this_ptr, SL("_activeRow"), PH_NOISY_CC);
			if (Z_TYPE_P(active_row) != IS_NULL) {
				PHALCON_INIT_VAR(zero);
				ZVAL_LONG(zero, 0);
				phalcon_call_method_p1_noret(result, "dataseek", zero);
			}
		}
	} else {
		/** 
		 * Here, the resultset act as an array
		 */
		PHALCON_OBS_VAR(rows);
		phalcon_read_property_this(&rows, this_ptr, SL("_rows"), PH_NOISY_CC);
		if (Z_TYPE_P(rows) == IS_NULL) {
	
			PHALCON_OBS_NVAR(result);
			phalcon_read_property_this(&result, this_ptr, SL("_result"), PH_NOISY_CC);
			if (Z_TYPE_P(result) == IS_OBJECT) {
				PHALCON_INIT_NVAR(rows);
				phalcon_call_method(rows, result, "fetchall");
				phalcon_update_property_this(this_ptr, SL("_rows"), rows TSRMLS_CC);
			}
		}
	
		if (Z_TYPE_P(rows) == IS_ARRAY) { 
			Z_SET_ISREF_P(rows);
			phalcon_call_func_p1_noret("reset", rows);
			Z_UNSET_ISREF_P(rows);
		}
	}
	
	phalcon_update_property_long(this_ptr, SL("_pointer"), 0 TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Example #3
0
/**
 * Listen for uncaught exceptions
 *
 * @return Phalcon\Debug
 */
PHP_METHOD(Phalcon_Debug, listenExceptions){

	zval *handler;

	PHALCON_MM_GROW();

	PHALCON_INIT_VAR(handler);
	array_init_size(handler, 2);
	phalcon_array_append(&handler, this_ptr, PH_SEPARATE);
	add_next_index_stringl(handler, SL("onUncaughtException"), 1);
	phalcon_call_func_p1_noret("set_exception_handler", handler);
	RETURN_THIS();
}