Esempio n. 1
0
/**
 * Phalcon_Model_MetaData_Session constructor
 *
 * @param Phalcon_Config|stdClass $options
 */
PHP_METHOD(Phalcon_Model_MetaData_Session, __construct){

	zval *options = NULL, *adapter_options = NULL;
	zval *t0 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &options) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_SEPARATE_PARAM(options);
	
	if (Z_TYPE_P(options) == IS_ARRAY) { 
		PHALCON_SEPARATE_PARAM(options);
		convert_to_array(options);
		PHALCON_CPY_WRT(adapter_options, options);
	} else {
		PHALCON_CPY_WRT(adapter_options, options);
	}
	eval_int = phalcon_isset_property(adapter_options, "suffix", strlen("suffix") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t0);
		phalcon_read_property(&t0, adapter_options, "suffix", sizeof("suffix")-1, PHALCON_NOISY TSRMLS_CC);
		phalcon_update_property_zval(this_ptr, "_suffix", strlen("_suffix"), t0 TSRMLS_CC);
	}
	
	PHALCON_MM_RESTORE();
}
Esempio n. 2
0
/**
 * This method is automatically called in Phalcon_Db_Mysql constructor.
 * Call it when you need to restore a database connection
 *
 * @param stdClass $descriptor
 * @return boolean
 */
PHP_METHOD(Phalcon_Db_Adapter_Mysql, connect){

	zval *descriptor = NULL, *host = NULL, *username = NULL, *password = NULL, *port = NULL;
	zval *socket = NULL, *dbname = NULL, *client_flags = NULL, *persistent = NULL;
	zval *link = NULL, *autocommit = NULL, *success = NULL, *collation = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL;
	zval *t7 = NULL, *t8 = NULL, *t9 = NULL, *t10 = NULL, *t11 = NULL, *t12 = NULL, *t13 = NULL;
	zval *t14 = NULL, *t15 = NULL, *t16 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *p0[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (!descriptor) {
		PHALCON_INIT_VAR(descriptor);
		ZVAL_NULL(descriptor);
	} else {
		PHALCON_SEPARATE_PARAM(descriptor);
	}
	
	if (!zend_is_true(descriptor)) {
		PHALCON_ALLOC_ZVAL_MM(t0);
		phalcon_read_property(&t0, this_ptr, SL("_descriptor"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(descriptor, t0);
	}
	eval_int = phalcon_isset_property(descriptor, SL("host") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t1);
		phalcon_read_property(&t1, descriptor, SL("host"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(host, t1);
	} else {
		PHALCON_INIT_VAR(host);
		ZVAL_NULL(host);
	}
	
	eval_int = phalcon_isset_property(descriptor, SL("username") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t2);
		phalcon_read_property(&t2, descriptor, SL("username"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(username, t2);
	} else {
		PHALCON_INIT_VAR(username);
		ZVAL_NULL(username);
	}
	
	eval_int = phalcon_isset_property(descriptor, SL("password") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t3);
		phalcon_read_property(&t3, descriptor, SL("password"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(password, t3);
	} else {
		PHALCON_INIT_VAR(password);
		ZVAL_NULL(password);
	}
	
	eval_int = phalcon_isset_property(descriptor, SL("port") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t4);
		phalcon_read_property(&t4, descriptor, SL("port"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(port, t4);
	} else {
		PHALCON_INIT_VAR(port);
		ZVAL_NULL(port);
	}
	
	eval_int = phalcon_isset_property(descriptor, SL("socket") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t5);
		phalcon_read_property(&t5, descriptor, SL("socket"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(socket, t5);
	} else {
		PHALCON_INIT_VAR(socket);
		ZVAL_NULL(socket);
	}
	
	eval_int = phalcon_isset_property(descriptor, SL("name") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t6);
		phalcon_read_property(&t6, descriptor, SL("name"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(dbname, t6);
	} else {
		PHALCON_INIT_VAR(dbname);
		ZVAL_STRING(dbname, "", 1);
	}
	
	PHALCON_INIT_VAR(client_flags);
	ZVAL_NULL(client_flags);
	eval_int = phalcon_isset_property(descriptor, SL("compression") TSRMLS_CC);
	if (eval_int) {
		PHALCON_INIT_VAR(t7);
		ZVAL_LONG(t7, 32);
		PHALCON_CPY_WRT(client_flags, t7);
	}
	
	eval_int = phalcon_isset_property(descriptor, SL("ssl") TSRMLS_CC);
	if (eval_int) {
		if (!zend_is_true(client_flags)) {
			PHALCON_INIT_VAR(t8);
			ZVAL_LONG(t8, 2048);
			PHALCON_CPY_WRT(client_flags, t8);
		} else {
			PHALCON_INIT_VAR(t9);
			ZVAL_LONG(t9, 2048);
			PHALCON_ALLOC_ZVAL_MM(r0);
			bitwise_or_function(r0, client_flags, t9 TSRMLS_CC);
			PHALCON_CPY_WRT(client_flags, r0);
		}
	}
	
	eval_int = phalcon_isset_property(descriptor, SL("interactive") TSRMLS_CC);
	if (eval_int) {
		if (!zend_is_true(client_flags)) {
			PHALCON_INIT_VAR(t10);
			ZVAL_LONG(t10, 1024);
			PHALCON_CPY_WRT(client_flags, t10);
		} else {
			PHALCON_INIT_VAR(t11);
			ZVAL_LONG(t11, 1024);
			PHALCON_ALLOC_ZVAL_MM(r1);
			bitwise_or_function(r1, client_flags, t11 TSRMLS_CC);
			PHALCON_CPY_WRT(client_flags, r1);
		}
	}
	
	PHALCON_INIT_VAR(persistent);
	ZVAL_BOOL(persistent, 0);
	eval_int = phalcon_isset_property(descriptor, SL("persistent") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t12);
		phalcon_read_property(&t12, descriptor, SL("persistent"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(persistent, t12);
	}
	
	PHALCON_INIT_VAR(link);
	PHALCON_CALL_FUNC(link, "mysqli_init");
	eval_int = phalcon_isset_property(descriptor, SL("autocommit") TSRMLS_CC);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(t13);
		phalcon_read_property(&t13, descriptor, SL("autocommit"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_INIT_VAR(autocommit);
		PHALCON_CALL_FUNC_PARAMS_1(autocommit, "intval", t13);
		phalcon_update_property_zval(this_ptr, SL("_autoCommit"), autocommit TSRMLS_CC);
		
		PHALCON_INIT_VAR(t14);
		ZVAL_LONG(t14, 3);
		
		PHALCON_ALLOC_ZVAL_MM(r2);
		PHALCON_CONCAT_SV(r2, "SET AUTOCOMMIT = ", autocommit);
		
		PHALCON_ALLOC_ZVAL_MM(r3);
		PHALCON_CALL_FUNC_PARAMS_3(r3, "mysqli_options", link, t14, r2);
		if (!zend_is_true(r3)) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Setting MYSQLI_INIT_COMMAND failed");
			return;
		}
	}
	
	p0[0] = link;
	p0[1] = host;
	p0[2] = username;
	p0[3] = password;
	p0[4] = dbname;
	p0[5] = port;
	p0[6] = socket;
	p0[7] = client_flags;
	
	PHALCON_ALLOC_ZVAL_MM(r4);
	PHALCON_CALL_FUNC_PARAMS(r4, "mysqli_real_connect", 8, p0);
	PHALCON_CPY_WRT(success, r4);
	if (zend_is_true(success)) {
		phalcon_update_property_zval(this_ptr, SL("_idConnection"), link TSRMLS_CC);
		PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon_Db_Adapter_Mysql", "__construct", descriptor);
		eval_int = phalcon_isset_property(descriptor, SL("charset") TSRMLS_CC);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(t15);
			phalcon_read_property(&t15, descriptor, SL("charset"), PHALCON_NOISY TSRMLS_CC);
			PHALCON_CALL_FUNC_PARAMS_2_NORETURN("mysqli_set_charset", link, t15);
		}
		
		eval_int = phalcon_isset_property(descriptor, SL("collation") TSRMLS_CC);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(t16);
			phalcon_read_property(&t16, descriptor, SL("collation"), PHALCON_NOISY TSRMLS_CC);
			PHALCON_CPY_WRT(collation, t16);
			
			PHALCON_ALLOC_ZVAL_MM(r5);
			PHALCON_CONCAT_SV(r5, "SET collation_connection=", collation);
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "query", r5, PHALCON_NO_CHECK);
			
			PHALCON_ALLOC_ZVAL_MM(r6);
			PHALCON_CONCAT_SV(r6, "SET collation_database=", collation);
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "query", r6, PHALCON_NO_CHECK);
		}
	} else {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Connection to MySQL failed");
		return;
	}
	
	PHALCON_MM_RESTORE();
}
Esempio n. 3
0
/**
 * Returns a connection builded with the default descriptor parameters
 *
 * 
 *
 * @param boolean $newConnection
     * @param boolean $renovate
 * @return Phalcon_Db
 */
PHP_METHOD(Phalcon_Db_Pool, getConnection){

	zval *new_connection = NULL, *renovate = NULL, *database = NULL, *connection = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &new_connection, &renovate) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (!new_connection) {
		PHALCON_INIT_VAR(new_connection);
		ZVAL_BOOL(new_connection, 0);
	}
	
	if (!renovate) {
		PHALCON_INIT_VAR(renovate);
		ZVAL_BOOL(renovate, 0);
	}
	
	PHALCON_OBSERVE_VAR(t0);
	phalcon_read_static_property(&t0, SL("Phalcon_Db_Pool"), SL("_defaultDescriptor") TSRMLS_CC);
	PHALCON_CPY_WRT(database, t0);
	if (!zend_is_true(database)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Default database connection parameters was not defined");
		return;
	}
	
	eval_int = phalcon_isset_property(database, SL("adapter") TSRMLS_CC);
	if (!eval_int) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "A valid adapter name is required");
		return;
	}
	
	if (zend_is_true(new_connection)) {
		if (zend_is_true(renovate)) {
			PHALCON_ALLOC_ZVAL_MM(r0);
			PHALCON_ALLOC_ZVAL_MM(t1);
			phalcon_read_property(&t1, database, SL("adapter"), PHALCON_NOISY TSRMLS_CC);
			PHALCON_CALL_STATIC_PARAMS_2(r0, "phalcon_db", "factory", t1, database);
			phalcon_update_static_property(SL("Phalcon_Db_Pool"), SL("_connection"), r0 TSRMLS_CC);
			PHALCON_OBSERVE_VAR(t2);
			phalcon_read_static_property(&t2, SL("Phalcon_Db_Pool"), SL("_connection") TSRMLS_CC);
			PHALCON_CPY_WRT(connection, t2);
		} else {
			PHALCON_ALLOC_ZVAL_MM(r1);
			PHALCON_ALLOC_ZVAL_MM(t3);
			phalcon_read_property(&t3, database, SL("adapter"), PHALCON_NOISY TSRMLS_CC);
			PHALCON_CALL_STATIC_PARAMS_2(r1, "phalcon_db", "factory", t3, database);
			PHALCON_CPY_WRT(connection, r1);
		}
	} else {
		PHALCON_OBSERVE_VAR(t4);
		phalcon_read_static_property(&t4, SL("Phalcon_Db_Pool"), SL("_connection") TSRMLS_CC);
		if (!zend_is_true(t4)) {
			PHALCON_ALLOC_ZVAL_MM(r2);
			PHALCON_ALLOC_ZVAL_MM(t5);
			phalcon_read_property(&t5, database, SL("adapter"), PHALCON_NOISY TSRMLS_CC);
			PHALCON_CALL_STATIC_PARAMS_2(r2, "phalcon_db", "factory", t5, database);
			phalcon_update_static_property(SL("Phalcon_Db_Pool"), SL("_connection"), r2 TSRMLS_CC);
		}
		PHALCON_OBSERVE_VAR(t6);
		phalcon_read_static_property(&t6, SL("Phalcon_Db_Pool"), SL("_connection") TSRMLS_CC);
		PHALCON_CPY_WRT(connection, t6);
	}
	
	
	RETURN_CHECK_CTOR(connection);
}
Esempio n. 4
0
/**
 * Modifies multiple general settings using a Phalcon_Config object or a stdClass filled with parameters
 *
 * @param stdClass $config
 */
PHP_METHOD(Phalcon_Controller_Front, setConfig){

	zval *config = NULL, *phalcon = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL;
	zval *t7 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &config) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	if (Z_TYPE_P(config) == IS_OBJECT) {
		eval_int = phalcon_isset_property(config, SL("database") TSRMLS_CC);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(t0);
			phalcon_read_property(&t0, config, SL("database"), PH_NOISY_CC);
			PHALCON_CALL_STATIC_PARAMS_1_NORETURN("phalcon\\db\\pool", "setdefaultdescriptor", t0);
		}
		eval_int = phalcon_isset_property(config, SL("phalcon") TSRMLS_CC);
		if (eval_int) {
			PHALCON_INIT_VAR(phalcon);
			phalcon_read_property(&phalcon, config, SL("phalcon"), PH_NOISY_CC);
			eval_int = phalcon_isset_property(phalcon, SL("controllersDir") TSRMLS_CC);
			if (eval_int) {
				PHALCON_ALLOC_ZVAL_MM(t1);
				phalcon_read_property(&t1, phalcon, SL("controllersDir"), PH_NOISY_CC);
				phalcon_update_property_zval(this_ptr, SL("_controllersDir"), t1 TSRMLS_CC);
			}
			
			eval_int = phalcon_isset_property(phalcon, SL("modelsDir") TSRMLS_CC);
			if (eval_int) {
				PHALCON_ALLOC_ZVAL_MM(t2);
				phalcon_read_property(&t2, phalcon, SL("modelsDir"), PH_NOISY_CC);
				phalcon_update_property_zval(this_ptr, SL("_modelsDir"), t2 TSRMLS_CC);
			}
			
			eval_int = phalcon_isset_property(phalcon, SL("viewsDir") TSRMLS_CC);
			if (eval_int) {
				PHALCON_ALLOC_ZVAL_MM(t3);
				phalcon_read_property(&t3, phalcon, SL("viewsDir"), PH_NOISY_CC);
				phalcon_update_property_zval(this_ptr, SL("_viewsDir"), t3 TSRMLS_CC);
			}
			
			eval_int = phalcon_isset_property(phalcon, SL("baseUri") TSRMLS_CC);
			if (eval_int) {
				PHALCON_ALLOC_ZVAL_MM(t4);
				phalcon_read_property(&t4, phalcon, SL("baseUri"), PH_NOISY_CC);
				phalcon_update_property_zval(this_ptr, SL("_baseUri"), t4 TSRMLS_CC);
			}
			
			eval_int = phalcon_isset_property(phalcon, SL("basePath") TSRMLS_CC);
			if (eval_int) {
				PHALCON_ALLOC_ZVAL_MM(t5);
				phalcon_read_property(&t5, phalcon, SL("basePath"), PH_NOISY_CC);
				phalcon_update_property_zval(this_ptr, SL("_basePath"), t5 TSRMLS_CC);
			}
		}
		
		eval_int = phalcon_isset_property(config, SL("models") TSRMLS_CC);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(t6);
			phalcon_read_property(&t6, config, SL("models"), PH_NOISY_CC);
			phalcon_update_property_zval(this_ptr, SL("_modelsConfig"), t6 TSRMLS_CC);
		}
		
		eval_int = phalcon_isset_property(config, SL("views") TSRMLS_CC);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(t7);
			phalcon_read_property(&t7, config, SL("views"), PH_NOISY_CC);
			phalcon_update_property_zval(this_ptr, SL("_viewsConfig"), t7 TSRMLS_CC);
		}
	} else {
		PHALCON_THROW_EXCEPTION_STR(phalcon_exception_ce, "Config parameter should be an object");
		return;
	}
	
	PHALCON_MM_RESTORE();
}