示例#1
0
/**
 * Bind params to SQL select
 *
 * @param string $sqlSelect
 * @param array $params
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, bindParams){

	zval *sql_select = NULL, *params = NULL, *select = NULL, *pdo = NULL, *bind_value = NULL;
	zval *index = NULL, *value = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql_select, &params) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_ALLOC_ZVAL_MM(r0);
	phalcon_fast_count(r0, params TSRMLS_CC);
	if (zend_is_true(r0)) {
		PHALCON_CPY_WRT(select, sql_select);
		
		PHALCON_INIT_VAR(pdo);
		phalcon_read_property(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC);
		if (!phalcon_valid_foreach(params TSRMLS_CC)) {
			return;
		}
		
		ah0 = Z_ARRVAL_P(params);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_7f5d_2:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_7f5d_2;
			}
			
			PHALCON_INIT_VAR(index);
			PHALCON_GET_FOREACH_KEY(index, ah0, hp0);
			PHALCON_INIT_VAR(bind_value);
			ZVAL_ZVAL(bind_value, *hd, 1, 0);
			PHALCON_INIT_VAR(r1);
			PHALCON_CALL_FUNC_PARAMS_1(r1, "is_numeric", bind_value);
			if (zend_is_true(r1)) {
				PHALCON_CPY_WRT(value, bind_value);
			} else {
				PHALCON_INIT_VAR(value);
				PHALCON_CALL_METHOD_PARAMS_1(value, pdo, "quote", bind_value, PH_NO_CHECK);
			}
			if (Z_TYPE_P(index) == IS_LONG) {
				PHALCON_INIT_VAR(r2);
				PHALCON_CONCAT_SV(r2, "?", index);
				PHALCON_INIT_VAR(r3);
				phalcon_fast_str_replace(r3, r2, value, select TSRMLS_CC);
				PHALCON_CPY_WRT(select, r3);
			} else {
				if (Z_TYPE_P(index) == IS_STRING) {
					PHALCON_INIT_VAR(r4);
					PHALCON_CONCAT_SVS(r4, ":", index, ":");
					PHALCON_INIT_VAR(r5);
					phalcon_fast_str_replace(r5, r4, value, select TSRMLS_CC);
					PHALCON_CPY_WRT(select, r5);
				} else {
					PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind parameter");
					return;
				}
			}
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_7f5d_2;
		fee_7f5d_2:
		if(0){}
		
		
		RETURN_CCTOR(select);
	}
	
	RETURN_CCTOR(sql_select);
}
示例#2
0
/**
 * Returns a slice of the resultset to show in the pagination
 *
 * @return \stdClass
 */
PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){

	zval show = {}, config = {}, items = {}, page_number = {}, rowcount = {}, page = {}, last_show_page = {}, start = {}, possible_pages = {}, total_pages = {};
	zval page_items = {}, maximum_pages = {}, next = {}, additional_page = {}, before = {}, remainder = {}, pages_total = {};
	long int i, i_show;

	phalcon_return_property(&show, getThis(), SL("_limitRows"));
	phalcon_return_property(&config, getThis(), SL("_config"));
	phalcon_return_property(&page_number, getThis(), SL("_page"));

	i_show = phalcon_get_intval(&show);

	phalcon_array_fetch_str(&items, &config, SL("data"), PH_NOISY);

	if (Z_TYPE(page_number) == IS_NULL || PHALCON_LT(&show, &PHALCON_GLOBAL(z_zero))) {
		PHALCON_CPY_WRT_CTOR(&page_number, &PHALCON_GLOBAL(z_one));
	}

	phalcon_fast_count(&rowcount, &items);

	object_init(&page);

	phalcon_sub_function(&last_show_page, &page_number, &PHALCON_GLOBAL(z_one));

	mul_function(&start, &show, &last_show_page);
	phalcon_div_function(&possible_pages, &rowcount, &show);

	if (unlikely(Z_TYPE(possible_pages)) != IS_DOUBLE) {
		convert_to_double(&possible_pages);
	}

	ZVAL_LONG(&total_pages, (long int)ceil(Z_DVAL(possible_pages)));
	if (Z_TYPE(items) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_paginator_exception_ce, "Invalid data for paginator");
		return;
	}

	array_init(&page_items);
	if (PHALCON_GT(&rowcount, &PHALCON_GLOBAL(z_zero))) {
		/** 
		 * Seek to the desired position
		 */
		if (PHALCON_LT(&start, &rowcount)) {
			PHALCON_CALL_METHODW(NULL, &items, "seek", &start);
		} else {
			PHALCON_CALL_METHODW(NULL, &items, "rewind");
			PHALCON_CPY_WRT_CTOR(&page_number, &PHALCON_GLOBAL(z_one));
			PHALCON_CPY_WRT_CTOR(&start, &PHALCON_GLOBAL(z_zero));
		}

		/** 
		 * The record must be iterable
		 */
		for (i=1; ; ++i) {
			zval valid = {}, current = {};
			PHALCON_CALL_METHODW(&valid, &items, "valid");
			if (!PHALCON_IS_NOT_FALSE(&valid)) {
				break;
			}

			PHALCON_CALL_METHODW(&current, &items, "current");
			phalcon_array_append(&page_items, &current, PH_COPY);

			if (i >= i_show) {
				break;
			}
		}
	}

	phalcon_update_property_zval(&page, SL("items"), &page_items);

	phalcon_add_function(&maximum_pages, &start, &show);
	if (PHALCON_LT(&maximum_pages, &rowcount)) {
		phalcon_add_function(&next, &page_number, &PHALCON_GLOBAL(z_one));
	} else if (PHALCON_IS_EQUAL(&maximum_pages, &rowcount)) {
			PHALCON_CPY_WRT_CTOR(&next, &rowcount);
	} else {
		phalcon_div_function(&possible_pages, &rowcount, &show);

		phalcon_add_function(&additional_page, &possible_pages, &PHALCON_GLOBAL(z_one));

		ZVAL_LONG(&next, phalcon_get_intval(&additional_page));
	}

	if (PHALCON_GT(&next, &total_pages)) {
		PHALCON_CPY_WRT_CTOR(&next, &total_pages);
	}

	phalcon_update_property_zval(&page, SL("next"), &next);
	if (PHALCON_GT(&page_number, &PHALCON_GLOBAL(z_one))) {
		phalcon_sub_function(&before, &page_number, &PHALCON_GLOBAL(z_one));
	} else {
		PHALCON_CPY_WRT_CTOR(&before, &PHALCON_GLOBAL(z_one));
	}

	phalcon_update_property_zval(&page, SL("first"), &PHALCON_GLOBAL(z_one));
	phalcon_update_property_zval(&page, SL("before"), &before);
	phalcon_update_property_zval(&page, SL("current"), &page_number);

	mod_function(&remainder, &rowcount, &show);

	phalcon_div_function(&possible_pages, &rowcount, &show);
	if (!PHALCON_IS_LONG(&remainder, 0)) {
		phalcon_add_function(&next, &possible_pages, &PHALCON_GLOBAL(z_one));

		ZVAL_LONG(&pages_total, phalcon_get_intval(&next));
	} else {
		PHALCON_CPY_WRT_CTOR(&pages_total, &possible_pages);
	}

	phalcon_update_property_zval(&page, SL("last"), &pages_total);
	phalcon_update_property_zval(&page, SL("total_pages"), &pages_total);
	phalcon_update_property_zval(&page, SL("total_items"), &rowcount);

	RETURN_CTORW(&page);
}
示例#3
0
/**
 * Sends SQL statements to the database server returning the success state.
 * Use this method only when the SQL statement sent to the server don't return any row
 *
 * //Inserting data
 * $success = $connection->execute("INSERT INTO robots VALUES (1, 'Astro Boy')");
 * $success = $connection->execute("INSERT INTO robots VALUES (?, ?)", array(1, 'Astro Boy'));
 *
 * @param  string $sqlStatement
 * @param  array $placeholders
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){

	zval *sql_statement = NULL, *placeholders = NULL, *events_manager = NULL;
	zval *pdo = NULL, *n = NULL, *statement = NULL, *value = NULL, *success = NULL, *affected_rows = NULL;
	zval *error_info = NULL;
	zval *c0 = NULL, *c1 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL;
	zval *i0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

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

	if (!placeholders) {
		PHALCON_INIT_VAR(placeholders);
		array_init(placeholders);
	}
	
	PHALCON_INIT_VAR(events_manager);
	phalcon_read_property(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC);
	if (zend_is_true(events_manager)) {
		phalcon_update_property_zval(this_ptr, SL("_sqlStatement"), sql_statement TSRMLS_CC);
		
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, "db:beforeQuery", 1);
		
		PHALCON_ALLOC_ZVAL_MM(r0);
		PHALCON_CALL_METHOD_PARAMS_2(r0, events_manager, "fire", c0, this_ptr, PH_NO_CHECK);
		if (Z_TYPE_P(r0) == IS_BOOL && !Z_BVAL_P(r0)) {
			PHALCON_MM_RESTORE();
			RETURN_FALSE;
		}
	}
	
	PHALCON_INIT_VAR(pdo);
	phalcon_read_property(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC);
	
	PHALCON_ALLOC_ZVAL_MM(r1);
	phalcon_fast_count(r1, placeholders TSRMLS_CC);
	if (zend_is_true(r1)) {
		PHALCON_INIT_VAR(n);
		ZVAL_LONG(n, 1);
		
		PHALCON_INIT_VAR(statement);
		PHALCON_CALL_METHOD_PARAMS_1(statement, pdo, "prepare", sql_statement, PH_NO_CHECK);
		if (!phalcon_valid_foreach(placeholders TSRMLS_CC)) {
			return;
		}
		
		ah0 = Z_ARRVAL_P(placeholders);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_7f5d_1:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_7f5d_1;
			}
			
			PHALCON_INIT_VAR(value);
			ZVAL_ZVAL(value, *hd, 1, 0);
			PHALCON_CALL_METHOD_PARAMS_2_NORETURN(statement, "bindparam", n, value, PH_NO_CHECK);
			PHALCON_SEPARATE(n);
			increment_function(n);
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_7f5d_1;
		fee_7f5d_1:
		if(0){}
		
		PHALCON_INIT_VAR(success);
		PHALCON_CALL_METHOD(success, statement, "execute", PH_NO_CHECK);
		
		PHALCON_INIT_VAR(affected_rows);
		PHALCON_CALL_METHOD(affected_rows, statement, "rowcount", PH_NO_CHECK);
	} else {
		PHALCON_INIT_VAR(success);
		ZVAL_BOOL(success, 1);
		
		PHALCON_INIT_VAR(affected_rows);
		PHALCON_CALL_METHOD_PARAMS_1(affected_rows, pdo, "exec", sql_statement, PH_NO_CHECK);
	}
	
	if (zend_is_true(success)) {
		if (Z_TYPE_P(affected_rows) == IS_LONG) {
			phalcon_update_property_zval(this_ptr, SL("_affectedRows"), affected_rows TSRMLS_CC);
			if (zend_is_true(events_manager)) {
				PHALCON_INIT_VAR(c1);
				ZVAL_STRING(c1, "db:afterQuery", 1);
				PHALCON_ALLOC_ZVAL_MM(r2);
				PHALCON_CALL_METHOD_PARAMS_2(r2, events_manager, "fire", c1, this_ptr, PH_NO_CHECK);
				if (Z_TYPE_P(r2) == IS_BOOL && !Z_BVAL_P(r2)) {
					PHALCON_MM_RESTORE();
					RETURN_FALSE;
				}
			}
			
			PHALCON_MM_RESTORE();
			RETURN_TRUE;
		}
	}
	
	PHALCON_INIT_VAR(error_info);
	PHALCON_CALL_METHOD(error_info, pdo, "errorinfo", PH_NO_CHECK);
	
	PHALCON_ALLOC_ZVAL_MM(i0);
	object_init_ex(i0, phalcon_db_exception_ce);
	
	PHALCON_ALLOC_ZVAL_MM(r3);
	phalcon_array_fetch_long(&r3, error_info, 2, PH_NOISY_CC);
	
	PHALCON_ALLOC_ZVAL_MM(r4);
	PHALCON_CONCAT_VSV(r4, r3, " when executing ", sql_statement);
	
	PHALCON_ALLOC_ZVAL_MM(r5);
	phalcon_array_fetch_long(&r5, error_info, 1, PH_NOISY_CC);
	PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i0, "__construct", r4, r5, PH_CHECK);
	phalcon_throw_exception(i0 TSRMLS_CC);
	return;
}
示例#4
0
/**
 * Generates SQL to add the table creation options
 *
 * @param array $definition
 * @return array
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){

	zval *definition = NULL, *table_options = NULL, *engine = NULL, *auto_increment = NULL;
	zval *table_collation = NULL, *collation_parts = NULL;
	zval *a0 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL;
	zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL;
	zval *c0 = NULL, *c1 = NULL;
	int eval_int;

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

	PHALCON_INIT_VAR(a0);
	array_init(a0);
	PHALCON_CPY_WRT(table_options, a0);
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	phalcon_array_fetch_string(&r0, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
	eval_int = phalcon_array_isset_string(r0, "ENGINE", strlen("ENGINE")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r1);
		phalcon_array_fetch_string(&r1, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_ALLOC_ZVAL_MM(r2);
		phalcon_array_fetch_string(&r2, r1, "ENGINE", strlen("ENGINE"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(engine, r2);
		
		PHALCON_ALLOC_ZVAL_MM(r3);
		phalcon_array_fetch_string(&r3, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
		
		PHALCON_ALLOC_ZVAL_MM(r4);
		phalcon_array_fetch_string(&r4, r3, "ENGINE", strlen("ENGINE"), PHALCON_NOISY TSRMLS_CC);
		if (zend_is_true(r4)) {
			PHALCON_ALLOC_ZVAL_MM(r5);
			PHALCON_CONCAT_SV(r5, "ENGINE=", engine);
			phalcon_array_append(&table_options, r5, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(r6);
	phalcon_array_fetch_string(&r6, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
	eval_int = phalcon_array_isset_string(r6, "AUTO_INCREMENT", strlen("AUTO_INCREMENT")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r7);
		phalcon_array_fetch_string(&r7, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_ALLOC_ZVAL_MM(r8);
		phalcon_array_fetch_string(&r8, r7, "AUTO_INCREMENT", strlen("AUTO_INCREMENT"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(auto_increment, r8);
		if (zend_is_true(auto_increment)) {
			PHALCON_ALLOC_ZVAL_MM(r9);
			PHALCON_CONCAT_SV(r9, "AUTO_INCREMENT=", auto_increment);
			phalcon_array_append(&table_options, r9, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(r10);
	phalcon_array_fetch_string(&r10, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
	eval_int = phalcon_array_isset_string(r10, "TABLE_COLLATION", strlen("TABLE_COLLATION")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r11);
		phalcon_array_fetch_string(&r11, definition, "options", strlen("options"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_ALLOC_ZVAL_MM(r12);
		phalcon_array_fetch_string(&r12, r11, "TABLE_COLLATION", strlen("TABLE_COLLATION"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(table_collation, r12);
		if (zend_is_true(table_collation)) {
			PHALCON_INIT_VAR(c0);
			ZVAL_STRING(c0, "_", 1);
			PHALCON_ALLOC_ZVAL_MM(r13);
			phalcon_fast_explode(r13, c0, table_collation TSRMLS_CC);
			PHALCON_CPY_WRT(collation_parts, r13);
			
			PHALCON_ALLOC_ZVAL_MM(r14);
			
			PHALCON_ALLOC_ZVAL_MM(r15);
			phalcon_array_fetch_long(&r15, collation_parts, 0, PHALCON_NOISY TSRMLS_CC);
			PHALCON_CONCAT_SV(r14, "DEFAULT CHARSET=", r15);
			phalcon_array_append(&table_options, r14, PHALCON_SEPARATE_PLZ TSRMLS_CC);
			
			PHALCON_ALLOC_ZVAL_MM(r16);
			PHALCON_CONCAT_SV(r16, "COLLATE=", table_collation);
			phalcon_array_append(&table_options, r16, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		}
	}
	
	PHALCON_ALLOC_ZVAL_MM(r17);
	phalcon_fast_count(r17, table_options TSRMLS_CC);
	if (zend_is_true(r17)) {
		PHALCON_INIT_VAR(c1);
		ZVAL_STRING(c1, " ", 1);
		PHALCON_ALLOC_ZVAL_MM(r18);
		phalcon_fast_join(r18, c1, table_options TSRMLS_CC);
		PHALCON_RETURN_DZVAL(r18);
	}
	
	PHALCON_MM_RESTORE();
	RETURN_NULL();
}
示例#5
0
/**
 * Handles routing information received from the rewrite engine
 *
 * @param string $uri
 */
PHP_METHOD(Phalcon_Router_Rewrite, handle){

	zval *uri = NULL, *parts = NULL, *params = NULL, *number_parts = NULL, *i = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL;
	zval *c0 = NULL;
	zval *t0 = NULL, *t1 = NULL;
	zval *a0 = NULL;
	int eval_int;

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

	if (!uri) {
		
		PHALCON_INIT_VAR(uri);
		ZVAL_NULL(uri);
	} else {
		PHALCON_SEPARATE_PARAM(uri);
	}
	
	if (!zend_is_true(uri)) {
		PHALCON_ALLOC_ZVAL_MM(r0);
		PHALCON_CALL_METHOD(r0, this_ptr, "_getrewriteuri", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(uri, r0);
	}
	if (zend_is_true(uri)) {
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, "/", 1);
		PHALCON_ALLOC_ZVAL_MM(r1);
		phalcon_fast_explode(r1, c0, uri TSRMLS_CC);
		PHALCON_CPY_WRT(parts, r1);
		eval_int = phalcon_array_isset_long(parts, 0);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(r2);
			phalcon_array_fetch_long(&r2, parts, 0, PHALCON_NOISY TSRMLS_CC);
			PHALCON_ALLOC_ZVAL_MM(r3);
			phalcon_filter_alphanum(r3, r2);
			phalcon_update_property_zval(this_ptr, "_controller", strlen("_controller"), r3 TSRMLS_CC);
			
			PHALCON_ALLOC_ZVAL_MM(t0);
			phalcon_read_property(&t0, this_ptr, "_controller", sizeof("_controller")-1, PHALCON_NOISY TSRMLS_CC);
			if (!zend_is_true(t0)) {
				phalcon_update_property_null(this_ptr, "_controller", strlen("_controller") TSRMLS_CC);
			}
		} else {
			phalcon_update_property_null(this_ptr, "_controller", strlen("_controller") TSRMLS_CC);
		}
		
		eval_int = phalcon_array_isset_long(parts, 1);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(r4);
			phalcon_array_fetch_long(&r4, parts, 1, PHALCON_NOISY TSRMLS_CC);
			PHALCON_ALLOC_ZVAL_MM(r5);
			phalcon_filter_alphanum(r5, r4);
			phalcon_update_property_zval(this_ptr, "_action", strlen("_action"), r5 TSRMLS_CC);
			
			PHALCON_ALLOC_ZVAL_MM(t1);
			phalcon_read_property(&t1, this_ptr, "_action", sizeof("_action")-1, PHALCON_NOISY TSRMLS_CC);
			if (!zend_is_true(t1)) {
				phalcon_update_property_null(this_ptr, "_action", strlen("_action") TSRMLS_CC);
			}
		} else {
			phalcon_update_property_null(this_ptr, "_action", strlen("_action") TSRMLS_CC);
		}
		
		
		PHALCON_INIT_VAR(a0);
		array_init(a0);
		PHALCON_CPY_WRT(params, a0);
		
		PHALCON_ALLOC_ZVAL_MM(r6);
		phalcon_fast_count(r6, parts TSRMLS_CC);
		PHALCON_CPY_WRT(number_parts, r6);
		
		PHALCON_INIT_VAR(i);
		ZVAL_LONG(i, 2);
		fs_ef57_0:
			
			PHALCON_INIT_VAR(r7);
			is_smaller_function(r7, i, number_parts TSRMLS_CC);
			if (!zend_is_true(r7)) {
				goto fe_ef57_0;
			}
			PHALCON_INIT_VAR(r8);
			phalcon_array_fetch(&r8, parts, i, PHALCON_NOISY TSRMLS_CC);
			phalcon_array_append(&params, r8, PHALCON_SEPARATE_PLZ TSRMLS_CC);
			PHALCON_SEPARATE(i);
			increment_function(i);
			goto fs_ef57_0;
		fe_ef57_0:
		phalcon_update_property_zval(this_ptr, "_params", strlen("_params"), params TSRMLS_CC);
	} else {
		phalcon_update_property_null(this_ptr, "_controller", strlen("_controller") TSRMLS_CC);
		phalcon_update_property_null(this_ptr, "_action", strlen("_action") TSRMLS_CC);
	}
	
	PHALCON_MM_RESTORE();
}
示例#6
0
/**
 * Returns a slice of the resultset to show in the pagination
 *
 * @return stdClass
 */
PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){

	zval *one, *zero, *show, *config, *items, *page_number = NULL;
	zval *smaller, *n, *page, *last_show_page, *start;
	zval *last_page, *possible_pages = NULL, *total_pages;
	zval *compare = NULL, *page_items, *i, *valid = NULL, *current = NULL, *maximum_pages;
	zval *next = NULL, *additional_page, *before = NULL, *remainder;
	zval *pages_total = NULL;
	zval *r0 = NULL;

	PHALCON_MM_GROW();

	PHALCON_INIT_VAR(one);
	ZVAL_LONG(one, 1);
	
	PHALCON_INIT_VAR(zero);
	ZVAL_LONG(zero, 0);
	
	PHALCON_OBS_VAR(show);
	phalcon_read_property(&show, this_ptr, SL("_limitRows"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(config);
	phalcon_read_property(&config, this_ptr, SL("_config"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(items);
	phalcon_array_fetch_string(&items, config, SL("data"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(page_number);
	phalcon_read_property(&page_number, this_ptr, SL("_page"), PH_NOISY_CC);
	if (Z_TYPE_P(page_number) == IS_NULL) {
		PHALCON_CPY_WRT(page_number, one);
	}
	
	PHALCON_INIT_VAR(smaller);
	is_smaller_function(smaller, show, zero TSRMLS_CC);
	if (PHALCON_IS_TRUE(smaller)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less");
		return;
	}
	
	PHALCON_INIT_VAR(n);
	phalcon_fast_count(n, items TSRMLS_CC);
	
	PHALCON_INIT_VAR(page);
	object_init(page);
	
	PHALCON_INIT_VAR(last_show_page);
	sub_function(last_show_page, page_number, one TSRMLS_CC);
	
	PHALCON_INIT_VAR(start);
	mul_function(start, show, last_show_page TSRMLS_CC);
	
	PHALCON_INIT_VAR(last_page);
	sub_function(last_page, n, one TSRMLS_CC);
	
	PHALCON_INIT_VAR(possible_pages);
	div_function(possible_pages, last_page, show TSRMLS_CC);
	
	PHALCON_INIT_VAR(total_pages);
	PHALCON_CALL_FUNC_PARAMS_1(total_pages, "ceil", possible_pages);
	if (Z_TYPE_P(items) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator");
		return;
	}
	
	if (Z_TYPE_P(page_number) == IS_NULL) {
		PHALCON_CPY_WRT(page_number, zero);
	}
	
	PHALCON_INIT_VAR(compare);
	is_smaller_function(compare, start, zero TSRMLS_CC);
	if (PHALCON_IS_TRUE(compare)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less");
		return;
	}
	
	PHALCON_INIT_VAR(page_items);
	array_init(page_items);
	
	is_smaller_function(compare, zero, n TSRMLS_CC);
	if (PHALCON_IS_TRUE(compare)) {
	
		/** 
		 * Seek to the desired position
		 */
		is_smaller_or_equal_function(compare, start, n TSRMLS_CC);
		if (PHALCON_IS_TRUE(compare)) {
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(items, "seek", start);
		} else {
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(items, "seek", one);
			PHALCON_CPY_WRT(page_number, one);
		}
	
		/** 
		 * The record must be iterable
		 */
		PHALCON_INIT_VAR(i);
		ZVAL_LONG(i, 1);
	
		while (1) {
	
			PHALCON_INIT_NVAR(r0);
			PHALCON_CALL_METHOD(r0, items, "valid");
			PHALCON_CPY_WRT(valid, r0);
			if (PHALCON_IS_NOT_FALSE(valid)) {
			} else {
				break;
			}
	
			PHALCON_INIT_NVAR(current);
			PHALCON_CALL_METHOD(current, items, "current");
			phalcon_array_append(&page_items, current, PH_SEPARATE TSRMLS_CC);
	
			PHALCON_INIT_NVAR(compare);
			is_smaller_or_equal_function(compare, show, i TSRMLS_CC);
			if (PHALCON_IS_TRUE(compare)) {
				break;
			}
	
			PHALCON_SEPARATE(i);
			increment_function(i);
		}
	}
	
	phalcon_update_property_zval(page, SL("items"), page_items TSRMLS_CC);
	phalcon_update_property_zval(page, SL("first"), one TSRMLS_CC);
	
	PHALCON_INIT_VAR(maximum_pages);
	phalcon_add_function(maximum_pages, start, show TSRMLS_CC);
	
	is_smaller_function(compare, maximum_pages, n TSRMLS_CC);
	if (PHALCON_IS_TRUE(compare)) {
		PHALCON_INIT_VAR(next);
		phalcon_add_function(next, page_number, one TSRMLS_CC);
	} else {
		is_equal_function(compare, maximum_pages, n TSRMLS_CC);
		if (PHALCON_IS_TRUE(compare)) {
			PHALCON_CPY_WRT(next, n);
		} else {
			div_function(possible_pages, n, show TSRMLS_CC);
	
			PHALCON_INIT_VAR(additional_page);
			phalcon_add_function(additional_page, possible_pages, one TSRMLS_CC);
	
			PHALCON_INIT_NVAR(next);
			PHALCON_CALL_FUNC_PARAMS_1(next, "intval", additional_page);
		}
	}
	
	is_smaller_function(compare, total_pages, next TSRMLS_CC);
	if (PHALCON_IS_TRUE(compare)) {
		PHALCON_CPY_WRT(next, total_pages);
	}
	
	phalcon_update_property_zval(page, SL("next"), next TSRMLS_CC);
	
	is_smaller_function(compare, one, page_number TSRMLS_CC);
	if (PHALCON_IS_TRUE(compare)) {
		PHALCON_INIT_VAR(before);
		sub_function(before, page_number, one TSRMLS_CC);
	} else {
		PHALCON_CPY_WRT(before, one);
	}
	
	phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC);
	phalcon_update_property_zval(page, SL("current"), page_number TSRMLS_CC);
	
	PHALCON_INIT_VAR(remainder);
	mod_function(remainder, n, show TSRMLS_CC);
	
	div_function(possible_pages, n, show TSRMLS_CC);
	if (!PHALCON_IS_LONG(remainder, 0)) {
		PHALCON_INIT_NVAR(next);
		phalcon_add_function(next, possible_pages, one TSRMLS_CC);
	
		PHALCON_INIT_VAR(pages_total);
		PHALCON_CALL_FUNC_PARAMS_1(pages_total, "intval", next);
	} else {
		PHALCON_CPY_WRT(pages_total, possible_pages);
	}
	
	phalcon_update_property_zval(page, SL("last"), pages_total TSRMLS_CC);
	phalcon_update_property_zval(page, SL("total_pages"), pages_total TSRMLS_CC);
	
	RETURN_CTOR(page);
}
示例#7
0
文件: route.c 项目: 11mariom/cphalcon
/**
 * Reconfigure the route adding a new pattern and a set of paths
 *
 * @param string $pattern
 * @param array $paths
 */
PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){

	zval *pattern, *paths = NULL, *module_name = NULL, *controller_name = NULL;
	zval *action_name = NULL, *parts, *number_parts, *route_paths = NULL;
	zval *real_class_name = NULL, *namespace_name, *lower_name;
	zval *pcre_pattern = NULL, *compiled_pattern = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &pattern, &paths);
	
	if (!paths) {
		PHALCON_INIT_VAR(paths);
	}
	
	if (Z_TYPE_P(pattern) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The pattern must be string");
		return;
	}
	if (Z_TYPE_P(paths) != IS_NULL) {
		if (Z_TYPE_P(paths) == IS_STRING) {
	
			PHALCON_INIT_VAR(module_name);
	
			PHALCON_INIT_VAR(controller_name);
	
			PHALCON_INIT_VAR(action_name);
	
			/** 
			 * Explode the short paths using the :: separator
			 */
			PHALCON_INIT_VAR(parts);
			phalcon_fast_explode_str(parts, SL("::"), paths);
	
			PHALCON_INIT_VAR(number_parts);
			phalcon_fast_count(number_parts, parts TSRMLS_CC);
	
			/** 
			 * Create the array paths dynamically
			 */
	
			switch (phalcon_get_intval(number_parts)) {
	
				case 3:
					PHALCON_OBS_NVAR(module_name);
					phalcon_array_fetch_long(&module_name, parts, 0, PH_NOISY);
	
					PHALCON_OBS_NVAR(controller_name);
					phalcon_array_fetch_long(&controller_name, parts, 1, PH_NOISY);
	
					PHALCON_OBS_NVAR(action_name);
					phalcon_array_fetch_long(&action_name, parts, 2, PH_NOISY);
					break;
	
				case 2:
					PHALCON_OBS_NVAR(controller_name);
					phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY);
	
					PHALCON_OBS_NVAR(action_name);
					phalcon_array_fetch_long(&action_name, parts, 1, PH_NOISY);
					break;
	
				case 1:
					PHALCON_OBS_NVAR(controller_name);
					phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY);
					break;
	
			}
	
			PHALCON_INIT_VAR(route_paths);
			array_init(route_paths);
	
			/** 
			 * Process module name
			 */
			if (Z_TYPE_P(module_name) != IS_NULL) {
				phalcon_array_update_string(&route_paths, SL("module"), &module_name, PH_COPY | PH_SEPARATE);
			}
	
			/** 
			 * Process controller name
			 */
			if (Z_TYPE_P(controller_name) != IS_NULL) {
	
				/** 
				 * Check if we need to obtain the namespace
				 */
				if (phalcon_memnstr_str(controller_name, SL("\\"))) {
	
					/** 
					 * Extract the real class name from the namespaced class
					 */
					PHALCON_INIT_VAR(real_class_name);
					phalcon_get_class_ns(real_class_name, controller_name, 0 TSRMLS_CC);
	
					/** 
					 * Extract the namespace from the namespaced class
					 */
					PHALCON_INIT_VAR(namespace_name);
					phalcon_get_ns_class(namespace_name, controller_name, 0 TSRMLS_CC);
	
					/** 
					 * Update the namespace
					 */
					if (zend_is_true(namespace_name)) {
						phalcon_array_update_string(&route_paths, SL("namespace"), &namespace_name, PH_COPY | PH_SEPARATE);
					}
				} else {
					PHALCON_CPY_WRT(real_class_name, controller_name);
				}
	
				/** 
				 * Always pass the controller to lowercase
				 */
				PHALCON_INIT_VAR(lower_name);
				phalcon_uncamelize(lower_name, real_class_name);
	
				/** 
				 * Update the controller path
				 */
				phalcon_array_update_string(&route_paths, SL("controller"), &lower_name, PH_COPY | PH_SEPARATE);
			}
	
			/** 
			 * Process action name
			 */
			if (Z_TYPE_P(action_name) != IS_NULL) {
				phalcon_array_update_string(&route_paths, SL("action"), &action_name, PH_COPY | PH_SEPARATE);
			}
		} else {
			PHALCON_CPY_WRT(route_paths, paths);
		}
	} else {
		PHALCON_INIT_NVAR(route_paths);
		array_init(route_paths);
	}
	
	if (Z_TYPE_P(route_paths) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The route contains invalid paths");
		return;
	}
	
	/** 
	 * If the route starts with '#' we assume that it is a regular expression
	 */
	if (!phalcon_start_with_str(pattern, SL("#"))) {
		if (phalcon_memnstr_str(pattern, SL("{"))) {
			/** 
			 * The route has named parameters so we need to extract them
			 */
			PHALCON_INIT_VAR(pcre_pattern);
			phalcon_extract_named_params(pcre_pattern, pattern, route_paths);
		} else {
			PHALCON_CPY_WRT(pcre_pattern, pattern);
		}
	
		/** 
		 * Transform the route's pattern to a regular expression
		 */
		PHALCON_INIT_VAR(compiled_pattern);
		phalcon_call_method_p1(compiled_pattern, this_ptr, "compilepattern", pcre_pattern);
	} else {
		PHALCON_CPY_WRT(compiled_pattern, pattern);
	}
	
	/** 
	 * Update the original pattern
	 */
	phalcon_update_property_this(this_ptr, SL("_pattern"), pattern TSRMLS_CC);
	
	/** 
	 * Update the compiled pattern
	 */
	phalcon_update_property_this(this_ptr, SL("_compiledPattern"), compiled_pattern TSRMLS_CC);
	
	/** 
	 * Update the route's paths
	 */
	phalcon_update_property_this(this_ptr, SL("_paths"), route_paths TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
示例#8
0
文件: debug.c 项目: RSivakov/cphalcon
/**
 * Shows a backtrace item
 *
 * @param int $n
 * @param array $trace
 */
PHP_METHOD(Phalcon_Debug, showTraceItem){

	zval *n, *trace, *space, *two_spaces, *underscore;
	zval *minus, *html, *class_name, *pattern, *is_phalcon_class;
	zval *namespace_separator, *prepare_uri_class;
	zval *class_reflection, *is_internal = NULL, *lower_class_name;
	zval *prepare_internal_class, *type, *function_name = NULL;
	zval *function_reflection, *prepared_function_name;
	zval *trace_args, *arguments, *argument = NULL, *dumped_argument = NULL;
	zval *span_argument = NULL, *joined_arguments, *one;
	zval *file, *line, *show_files, *lines, *number_lines;
	zval *show_file_fragment, *seven, *before_line;
	zval *first_line = NULL, *five, *after_line, *last_line = NULL;
	zval *comment_pattern, *utf8, *ent_compat, *tab;
	zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL;
	zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL;
	zval *escaped_line = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	zend_class_entry *ce0, *ce1;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &n, &trace);
	
	PHALCON_INIT_VAR(space);
	ZVAL_STRING(space, " ", 1);
	
	PHALCON_INIT_VAR(two_spaces);
	ZVAL_STRING(two_spaces, "  ", 1);
	
	PHALCON_INIT_VAR(underscore);
	ZVAL_STRING(underscore, "_", 1);
	
	PHALCON_INIT_VAR(minus);
	ZVAL_STRING(minus, "-", 1);
	
	/** 
	 * Every trace in the backtrace have a unique number
	 */
	PHALCON_INIT_VAR(html);
	PHALCON_CONCAT_SVS(html, "<tr><td align=\"right\" valign=\"top\" class=\"error-number\">#", n, "</td><td>");
	if (phalcon_array_isset_string(trace, SS("class"))) {
	
		PHALCON_OBS_VAR(class_name);
		phalcon_array_fetch_string(&class_name, trace, SL("class"), PH_NOISY_CC);
	
		PHALCON_INIT_VAR(pattern);
		ZVAL_STRING(pattern, "/^Phalcon/", 1);
	
		PHALCON_INIT_VAR(is_phalcon_class);
	
		#if HAVE_BUNDLED_PCRE
		phalcon_preg_match(is_phalcon_class, pattern, class_name, NULL TSRMLS_CC);
		#else
		phalcon_call_func_p2(is_phalcon_class, "preg_match", pattern, class_name);
		#endif
	
		/** 
		 * We assume that classes starting by Phalcon are framework's classes
		 */
		if (zend_is_true(is_phalcon_class)) {
			PHALCON_INIT_VAR(namespace_separator);
			ZVAL_STRING(namespace_separator, "\\", 1);
	
			/** 
			 * Prepare the class name according to the Phalcon's conventions
			 */
			PHALCON_INIT_VAR(prepare_uri_class);
			phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name TSRMLS_CC);
	
			/** 
			 * Generate a link to the official docs
			 */
			PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://docs.phalconphp.com/en/latest/api/", prepare_uri_class, ".html\">", class_name, "</a></span>");
		} else {
			ce0 = zend_fetch_class(SL("ReflectionClass"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
			PHALCON_INIT_VAR(class_reflection);
			object_init_ex(class_reflection, ce0);
			if (phalcon_has_constructor(class_reflection TSRMLS_CC)) {
				phalcon_call_method_p1_noret(class_reflection, "__construct", class_name);
			}
	
			/** 
			 * Check if classes are PHP's classes
			 */
			PHALCON_INIT_VAR(is_internal);
			phalcon_call_method(is_internal, class_reflection, "isinternal");
			if (zend_is_true(is_internal)) {
				PHALCON_INIT_VAR(lower_class_name);
				phalcon_fast_strtolower(lower_class_name, class_name);
	
				PHALCON_INIT_VAR(prepare_internal_class);
				phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name TSRMLS_CC);
	
				/** 
				 * Generate a link to the official docs
				 */
				PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://php.net/manual/en/class.", prepare_internal_class, ".php\">", class_name, "</a></span>");
			} else {
				PHALCON_SCONCAT_SVS(html, "<span class=\"error-class\">", class_name, "</span>");
			}
		}
	
		/** 
		 * Object access operator: static/instance
		 */
		PHALCON_OBS_VAR(type);
		phalcon_array_fetch_string(&type, trace, SL("type"), PH_NOISY_CC);
		phalcon_concat_self(&html, type TSRMLS_CC);
	}
	
	/** 
	 * Normally the backtrace contains only classes
	 */
	if (phalcon_array_isset_string(trace, SS("class"))) {
		PHALCON_OBS_VAR(function_name);
		phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY_CC);
		PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
	} else {
		PHALCON_OBS_NVAR(function_name);
		phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY_CC);
	
		/** 
		 * Check if the function exists
		 */
		if (phalcon_function_exists(function_name TSRMLS_CC) == SUCCESS) {
			ce1 = zend_fetch_class(SL("ReflectionFunction"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
			PHALCON_INIT_VAR(function_reflection);
			object_init_ex(function_reflection, ce1);
			if (phalcon_has_constructor(function_reflection TSRMLS_CC)) {
				phalcon_call_method_p1_noret(function_reflection, "__construct", function_name);
			}
	
			PHALCON_INIT_NVAR(is_internal);
			phalcon_call_method(is_internal, function_reflection, "isinternal");
	
			/** 
			 * Internal functions links to the PHP documentation
			 */
			if (zend_is_true(is_internal)) {
				/** 
				 * Prepare function's name according to the conventions in the docs
				 */
				PHALCON_INIT_VAR(prepared_function_name);
				phalcon_fast_str_replace(prepared_function_name, underscore, minus, function_name TSRMLS_CC);
				PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-function\"><a target=\"_new\" href=\"http://php.net/manual/en/function.", prepared_function_name, ".php\">", function_name, "</a></span>");
			} else {
				PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
			}
		} else {
			PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
		}
	}
	
	/** 
	 * Check for arguments in the function
	 */
	if (phalcon_array_isset_string(trace, SS("args"))) {
	
		PHALCON_OBS_VAR(trace_args);
		phalcon_array_fetch_string(&trace_args, trace, SL("args"), PH_NOISY_CC);
		if (phalcon_fast_count_ev(trace_args TSRMLS_CC)) {
	
			PHALCON_INIT_VAR(arguments);
			array_init(arguments);
	
			phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0);
	
			while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
				PHALCON_GET_HVALUE(argument);
	
				/** 
				 * Every argument is generated using _getVarDump
				 */
				PHALCON_INIT_NVAR(dumped_argument);
				phalcon_call_method_p1(dumped_argument, this_ptr, "_getvardump", argument);
	
				PHALCON_INIT_NVAR(span_argument);
				PHALCON_CONCAT_SVS(span_argument, "<span class=\"error-parameter\">", dumped_argument, "</span>");
	
				/** 
				 * Append the HTML generated to the argument's list
				 */
				phalcon_array_append(&arguments, span_argument, PH_SEPARATE TSRMLS_CC);
	
				zend_hash_move_forward_ex(ah0, &hp0);
			}
	
			/** 
			 * Join all the arguments
			 */
			PHALCON_INIT_VAR(joined_arguments);
			phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC);
			PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")");
		} else {
			phalcon_concat_self_str(&html, SL("()") TSRMLS_CC);
		}
	}
	
	/** 
	 * When 'file' is present, it usually means the function is provided by the user
	 */
	if (phalcon_array_isset_string(trace, SS("file"))) {
	
		PHALCON_INIT_VAR(one);
		ZVAL_LONG(one, 1);
	
		PHALCON_OBS_VAR(file);
		phalcon_array_fetch_string(&file, trace, SL("file"), PH_NOISY_CC);
	
		PHALCON_OBS_VAR(line);
		phalcon_array_fetch_string(&line, trace, SL("line"), PH_NOISY_CC);
	
		/** 
		 * Realpath to the file and its line using a special header
		 */
		PHALCON_SCONCAT_SVSVS(html, "<br/><div class=\"error-file\">", file, " (", line, ")</div>");
	
		PHALCON_OBS_VAR(show_files);
		phalcon_read_property_this(&show_files, this_ptr, SL("_showFiles"), PH_NOISY_CC);
	
		/** 
		 * The developer can change if the files must be opened or not
		 */
		if (zend_is_true(show_files)) {
	
			/** 
			 * Open the file to an array using 'file', this respects the openbase-dir directive
			 */
			PHALCON_INIT_VAR(lines);
			phalcon_call_func_p1(lines, "file", file);
	
			PHALCON_INIT_VAR(number_lines);
			phalcon_fast_count(number_lines, lines TSRMLS_CC);
	
			PHALCON_OBS_VAR(show_file_fragment);
			phalcon_read_property_this(&show_file_fragment, this_ptr, SL("_showFileFragment"), PH_NOISY_CC);
	
			/** 
			 * File fragments just show a piece of the file where the exception is located
			 */
			if (zend_is_true(show_file_fragment)) {
	
				/** 
				 * Take seven lines back to the current exception's line, @TODO add an option for
				 * this
				 */
				PHALCON_INIT_VAR(seven);
				ZVAL_LONG(seven, 7);
	
				PHALCON_INIT_VAR(before_line);
				sub_function(before_line, line, seven TSRMLS_CC);
	
				/** 
				 * Check for overflows
				 */
				if (PHALCON_LT_LONG(before_line, 1)) {
					PHALCON_CPY_WRT(first_line, one);
				} else {
					PHALCON_CPY_WRT(first_line, before_line);
				}
	
				/** 
				 * Take five lines after the current exception's line, @TODO add an option for this
				 */
				PHALCON_INIT_VAR(five);
				ZVAL_LONG(five, 5);
	
				PHALCON_INIT_VAR(after_line);
				phalcon_add_function(after_line, line, five TSRMLS_CC);
	
				/** 
				 * Check for overflows
				 */
				if (PHALCON_GT(after_line, number_lines)) {
					PHALCON_CPY_WRT(last_line, number_lines);
				} else {
					PHALCON_CPY_WRT(last_line, after_line);
				}
	
				PHALCON_SCONCAT_SVSVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums:", first_line, "'>");
			} else {
				PHALCON_CPY_WRT(first_line, one);
				PHALCON_CPY_WRT(last_line, number_lines);
				PHALCON_SCONCAT_SVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums error-scroll'>");
			}
	
			PHALCON_INIT_VAR(comment_pattern);
			ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1);
	
			/** 
			 * We assume the file is utf-8 encoded, @TODO add an option for this
			 */
			PHALCON_INIT_VAR(utf8);
			ZVAL_STRING(utf8, "UTF-8", 1);
	
			/** 
			 * Don't escape quotes
			 */
			PHALCON_INIT_VAR(ent_compat);
			ZVAL_LONG(ent_compat, 2);
	
			PHALCON_INIT_VAR(tab);
			ZVAL_STRING(tab, "\t", 1);
	
			PHALCON_INIT_VAR(comment);
			ZVAL_STRING(comment, "* /", 1);
			PHALCON_CPY_WRT(i, first_line);
	
			while (1) {
	
				if (PHALCON_LE(i, last_line)) {
				} else {
					break;
				}
	
				/** 
				 * Current line in the file
				 */
				PHALCON_INIT_NVAR(line_position);
				sub_function(line_position, i, one TSRMLS_CC);
	
				/** 
				 * Current line content in the piece of file
				 */
				PHALCON_OBS_NVAR(current_line);
				phalcon_array_fetch(&current_line, lines, line_position, PH_NOISY_CC);
	
				/** 
				 * File fragments are cleaned, removing tabs and comments
				 */
				if (zend_is_true(show_file_fragment)) {
					if (PHALCON_IS_EQUAL(i, first_line)) {
	
						PHALCON_INIT_NVAR(trimmed);
						phalcon_fast_trim(trimmed, current_line, PHALCON_TRIM_RIGHT TSRMLS_CC);
	
						PHALCON_INIT_NVAR(is_comment);
	
						#if HAVE_BUNDLED_PCRE
						phalcon_preg_match(is_comment, comment_pattern, current_line, NULL TSRMLS_CC);
						#else
						phalcon_call_func_p2(is_comment, "preg_match", comment_pattern, current_line);
						#endif
	
						if (zend_is_true(is_comment)) {
							PHALCON_INIT_NVAR(spaced_current_line);
							phalcon_fast_str_replace(spaced_current_line, comment, space, current_line TSRMLS_CC);
							PHALCON_CPY_WRT(current_line, spaced_current_line);
						}
					}
				}
	
				/** 
				 * Print a non break space if the current line is a line break, this allows to show
				 * the html zebra properly
				 */
				if (PHALCON_IS_STRING(current_line, "\n")) {
					phalcon_concat_self_str(&html, SL("&nbsp;\n") TSRMLS_CC);
				} else {
					if (PHALCON_IS_STRING(current_line, "\r\n")) {
						phalcon_concat_self_str(&html, SL("&nbsp;\n") TSRMLS_CC);
					} else {
						PHALCON_INIT_NVAR(spaced_current_line);
						phalcon_fast_str_replace(spaced_current_line, tab, two_spaces, current_line TSRMLS_CC);
	
						PHALCON_INIT_NVAR(escaped_line);
						phalcon_call_func_p3(escaped_line, "htmlentities", spaced_current_line, ent_compat, utf8);
						phalcon_concat_self(&html, escaped_line TSRMLS_CC);
					}
				}
	
				PHALCON_SEPARATE(i);
				phalcon_increment(i);
			}
			phalcon_concat_self_str(&html, SL("</pre>") TSRMLS_CC);
		}
	}
	
	phalcon_concat_self_str(&html, SL("</td></tr>") TSRMLS_CC);
	
	RETURN_CTOR(html);
}
示例#9
0
/**
 * Phalcon\Db\Reference constructor
 *
 * @param string $referenceName
 * @param array $definition
 */
PHP_METHOD(Phalcon_Db_Reference, __construct){

	zval *reference_name, *definition, *referenced_table;
	zval *columns, *referenced_columns, *schema;
	zval *referenced_schema, *number_columns;
	zval *number_referenced_columns;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &reference_name, &definition);
	
	phalcon_update_property_this(this_ptr, SL("_referenceName"), reference_name TSRMLS_CC);
	if (phalcon_array_isset_string(definition, SS("referencedTable"))) {
		PHALCON_OBS_VAR(referenced_table);
		phalcon_array_fetch_string(&referenced_table, definition, SL("referencedTable"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_referencedTable"), referenced_table TSRMLS_CC);
	} else {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Referenced table is required");
		return;
	}
	
	if (phalcon_array_isset_string(definition, SS("columns"))) {
		PHALCON_OBS_VAR(columns);
		phalcon_array_fetch_string(&columns, definition, SL("columns"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_columns"), columns TSRMLS_CC);
	} else {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Foreign key columns are required");
		return;
	}
	
	if (phalcon_array_isset_string(definition, SS("referencedColumns"))) {
		PHALCON_OBS_VAR(referenced_columns);
		phalcon_array_fetch_string(&referenced_columns, definition, SL("referencedColumns"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_referencedColumns"), referenced_columns TSRMLS_CC);
	} else {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Referenced columns of the foreign key are required");
		return;
	}
	
	if (phalcon_array_isset_string(definition, SS("schema"))) {
		PHALCON_OBS_VAR(schema);
		phalcon_array_fetch_string(&schema, definition, SL("schema"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_schemaName"), schema TSRMLS_CC);
	}
	
	if (phalcon_array_isset_string(definition, SS("referencedSchema"))) {
		PHALCON_OBS_VAR(referenced_schema);
		phalcon_array_fetch_string(&referenced_schema, definition, SL("referencedSchema"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_referencedSchema"), referenced_schema TSRMLS_CC);
	}
	
	PHALCON_INIT_VAR(number_columns);
	phalcon_fast_count(number_columns, columns TSRMLS_CC);
	
	PHALCON_INIT_VAR(number_referenced_columns);
	phalcon_fast_count(number_referenced_columns, referenced_columns TSRMLS_CC);
	if (!PHALCON_IS_EQUAL(number_columns, number_referenced_columns)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Number of columns is not equals than the number of columns referenced");
		return;
	}
	
	PHALCON_MM_RESTORE();
}
示例#10
0
文件: debug.c 项目: RSivakov/cphalcon
/**
 * Produces a recursive representation of an array
 *
 * @param array $argument
 * @return string
 */
PHP_METHOD(Phalcon_Debug, _getArrayDump){

	zval *argument, *n = NULL, *number_arguments, *one, *dump;
	zval *v = NULL, *k = NULL, *var_dump = NULL, *escaped_string = NULL, *next = NULL, *array_dump = NULL;
	zval *class_name = NULL, *joined_dump;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &argument, &n);
	
	if (!n) {
		PHALCON_INIT_VAR(n);
		ZVAL_LONG(n, 0);
	}
	
	PHALCON_INIT_VAR(number_arguments);
	phalcon_fast_count(number_arguments, argument TSRMLS_CC);
	if (PHALCON_LT_LONG(n, 3)) {
		if (PHALCON_GT_LONG(number_arguments, 0)) {
			if (PHALCON_LT_LONG(number_arguments, 10)) {
	
				PHALCON_INIT_VAR(one);
				ZVAL_LONG(one, 1);
	
				PHALCON_INIT_VAR(dump);
				array_init(dump);
	
				phalcon_is_iterable(argument, &ah0, &hp0, 0, 0);
	
				while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
					PHALCON_GET_HKEY(k, ah0, hp0);
					PHALCON_GET_HVALUE(v);
	
					if (PHALCON_IS_SCALAR(v)) {
						if (PHALCON_IS_STRING(v, "")) {
							PHALCON_INIT_NVAR(var_dump);
							PHALCON_CONCAT_SVS(var_dump, "[", k, "] =&gt; (empty string)");
						} else {
							PHALCON_INIT_NVAR(escaped_string);
							phalcon_call_method_p1(escaped_string, this_ptr, "_escapestring", v);
	
							PHALCON_INIT_NVAR(var_dump);
							PHALCON_CONCAT_SVSV(var_dump, "[", k, "] =&gt; ", escaped_string);
						}
						phalcon_array_append(&dump, var_dump, PH_SEPARATE TSRMLS_CC);
					} else {
						if (Z_TYPE_P(v) == IS_ARRAY) { 
							PHALCON_INIT_NVAR(next);
							phalcon_add_function(next, n, one TSRMLS_CC);
	
							PHALCON_INIT_NVAR(array_dump);
							phalcon_call_method_p2(array_dump, this_ptr, "_getarraydump", v, next);
	
							PHALCON_INIT_NVAR(var_dump);
							PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] =&gt; Array(", array_dump, ")");
							phalcon_array_append(&dump, var_dump, PH_SEPARATE TSRMLS_CC);
							zend_hash_move_forward_ex(ah0, &hp0);
							continue;
						}
						if (Z_TYPE_P(v) == IS_OBJECT) {
							PHALCON_INIT_NVAR(class_name);
							phalcon_get_class(class_name, v, 0 TSRMLS_CC);
	
							PHALCON_INIT_NVAR(var_dump);
							PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] =&gt; Object(", class_name, ")");
							phalcon_array_append(&dump, var_dump, PH_SEPARATE TSRMLS_CC);
							zend_hash_move_forward_ex(ah0, &hp0);
							continue;
						}
	
						if (Z_TYPE_P(v) == IS_NULL) {
							PHALCON_INIT_NVAR(var_dump);
							PHALCON_CONCAT_SVS(var_dump, "[", k, "] =&gt; null");
							phalcon_array_append(&dump, var_dump, PH_SEPARATE TSRMLS_CC);
							zend_hash_move_forward_ex(ah0, &hp0);
							continue;
						}
	
						PHALCON_INIT_NVAR(var_dump);
						PHALCON_CONCAT_SVSV(var_dump, "[", k, "] =&gt; ", v);
						phalcon_array_append(&dump, var_dump, PH_SEPARATE TSRMLS_CC);
					}
	
					zend_hash_move_forward_ex(ah0, &hp0);
				}
	
				PHALCON_INIT_VAR(joined_dump);
				phalcon_fast_join_str(joined_dump, SL(", "), dump TSRMLS_CC);
	
				RETURN_CTOR(joined_dump);
			}
	
			RETURN_NCTOR(number_arguments);
		}
	}
	
	RETURN_MM_NULL();
}
示例#11
0
文件: debug.c 项目: Myleft/cphalcon
/**
 * Shows a backtrace item
 *
 * @param int $n
 * @param array $trace
 */
PHP_METHOD(Phalcon_Debug, showTraceItem){

	zval *n, *trace, *link_format, *space, *two_spaces, *underscore;
	zval *minus, *html, *class_name;
	zval *namespace_separator, *prepare_uri_class;
	zval *lower_class_name, *prepared_function_name;
	zval *prepare_internal_class, *type, *function_name = NULL;
	zval *trace_args, *arguments, *argument = NULL, *dumped_argument = NULL;
	zval *span_argument = NULL, *joined_arguments, *z_one;
	zval *file, *line, *show_files, *lines = NULL, *number_lines;
	zval *show_file_fragment, *before_context, *before_line;
	zval *first_line = NULL, *after_context, *after_line, *last_line = NULL;
	zval *comment_pattern, *charset, *tab;
	zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL;
	zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL;
	zval *escaped_line = NULL, *formatted_file = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 3, 0, &n, &trace, &link_format);

	PHALCON_INIT_VAR(space);
	ZVAL_STRING(space, " ", 1);

	PHALCON_INIT_VAR(two_spaces);
	ZVAL_STRING(two_spaces, "  ", 1);

	PHALCON_INIT_VAR(underscore);
	ZVAL_STRING(underscore, "_", 1);

	PHALCON_INIT_VAR(minus);
	ZVAL_STRING(minus, "-", 1);

	/** 
	 * Every trace in the backtrace have a unique number
	 */
	PHALCON_INIT_VAR(html);
	PHALCON_CONCAT_SVS(html, "<tr><td align=\"right\" valign=\"top\" class=\"error-number\">#", n, "</td><td>");
	if (phalcon_array_isset_string(trace, SS("class"))) {
		zend_class_entry *class_ce;

		PHALCON_OBS_VAR(class_name);
		phalcon_array_fetch_string(&class_name, trace, SL("class"), PH_NOISY);

		class_ce = zend_fetch_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_SILENT TSRMLS_CC);

		if (!class_ce) {
			/* Unable to load the class, should never happen */
		}
		else if (is_phalcon_class(class_ce)) {
			PHALCON_INIT_VAR(namespace_separator);
			ZVAL_STRING(namespace_separator, "\\", 1);

			/* Prepare the class name according to the Phalcon's conventions */
			PHALCON_INIT_VAR(prepare_uri_class);
			phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name);

			/* Generate a link to the official docs */
			PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://docs.phalconphp.com/en/latest/api/", prepare_uri_class, ".html\">", class_name, "</a></span>");
		} else if (class_ce->type == ZEND_INTERNAL_CLASS) {
			PHALCON_INIT_VAR(lower_class_name);
			phalcon_fast_strtolower(lower_class_name, class_name);

			PHALCON_INIT_VAR(prepare_internal_class);
			phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name);

			/* Generate a link to the official docs */
			PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://php.net/manual/en/class.", prepare_internal_class, ".php\">", class_name, "</a></span>");
		} else {
			PHALCON_SCONCAT_SVS(html, "<span class=\"error-class\">", class_name, "</span>");
		}

		/** 
		 * Object access operator: static/instance
		 */
		PHALCON_OBS_VAR(type);
		phalcon_array_fetch_string(&type, trace, SL("type"), PH_NOISY);
		phalcon_concat_self(&html, type TSRMLS_CC);
	}

	/** 
	 * Normally the backtrace contains only classes
	 */
	if (phalcon_array_isset_string(trace, SS("class"))) {
		PHALCON_OBS_VAR(function_name);
		phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY);
		PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
	} else {
		zend_function *func;

		PHALCON_OBS_NVAR(function_name);
		phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY);
		convert_to_string(function_name);

		/** 
		 * Check if the function exists
		 */
		if (phalcon_fetch_function(&func, Z_STRVAL_P(function_name), Z_STRLEN_P(function_name) TSRMLS_CC) == SUCCESS) {

			/** 
			 * Internal functions links to the PHP documentation
			 */
			if (func->type == ZEND_INTERNAL_FUNCTION) {
				/** 
				 * Prepare function's name according to the conventions in the docs
				 */
				PHALCON_INIT_VAR(prepared_function_name);
				phalcon_fast_str_replace(prepared_function_name, underscore, minus, function_name);
				PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-function\"><a target=\"_new\" href=\"http://php.net/manual/en/function.", prepared_function_name, ".php\">", function_name, "</a></span>");
			} else {
				PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
			}
		} else {
			PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
		}
	}

	/** 
	 * Check for arguments in the function
	 */
	if (phalcon_array_isset_string(trace, SS("args"))) {

		PHALCON_OBS_VAR(trace_args);
		phalcon_array_fetch_string(&trace_args, trace, SL("args"), PH_NOISY);
		if (phalcon_fast_count_ev(trace_args TSRMLS_CC)) {

			PHALCON_INIT_VAR(arguments);
			array_init(arguments);

			phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0);

			while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

				PHALCON_GET_HVALUE(argument);

				/** 
				 * Every argument is generated using _getVarDump
				 */
				PHALCON_CALL_METHOD(&dumped_argument, this_ptr, "_getvardump", argument);

				PHALCON_INIT_NVAR(span_argument);
				PHALCON_CONCAT_SVS(span_argument, "<span class=\"error-parameter\">", dumped_argument, "</span>");

				/** 
				 * Append the HTML generated to the argument's list
				 */
				phalcon_array_append(&arguments, span_argument, PH_COPY);

				zend_hash_move_forward_ex(ah0, &hp0);
			}

			/** 
			 * Join all the arguments
			 */
			PHALCON_INIT_VAR(joined_arguments);
			phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC);
			PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")");
		} else {
			phalcon_concat_self_str(&html, SL("()") TSRMLS_CC);
		}
	}

	/** 
	 * When 'file' is present, it usually means the function is provided by the user
	 */
	if (phalcon_array_isset_string(trace, SS("file"))) {

		z_one = PHALCON_GLOBAL(z_one);

		PHALCON_OBS_VAR(file);
		phalcon_array_fetch_string(&file, trace, SL("file"), PH_NOISY);

		PHALCON_OBS_VAR(line);
		phalcon_array_fetch_string(&line, trace, SL("line"), PH_NOISY);

		PHALCON_CALL_METHOD(&formatted_file, getThis(), "getfilelink", file, line, link_format);

		/** 
		 * Realpath to the file and its line using a special header
		 */
		PHALCON_SCONCAT_SVSVS(html, "<br/><div class=\"error-file\">", formatted_file, " (", line, ")</div>");

		PHALCON_OBS_VAR(show_files);
		phalcon_read_property_this(&show_files, this_ptr, SL("_showFiles"), PH_NOISY TSRMLS_CC);

		/** 
		 * The developer can change if the files must be opened or not
		 */
		if (zend_is_true(show_files)) {

			/** 
			 * Open the file to an array using 'file', this respects the openbase-dir directive
			 */
			PHALCON_CALL_FUNCTION(&lines, "file", file);

			PHALCON_INIT_VAR(number_lines);
			phalcon_fast_count(number_lines, lines TSRMLS_CC);

			PHALCON_OBS_VAR(show_file_fragment);
			phalcon_read_property_this(&show_file_fragment, this_ptr, SL("_showFileFragment"), PH_NOISY TSRMLS_CC);

			/** 
			 * File fragments just show a piece of the file where the exception is located
			 */
			if (zend_is_true(show_file_fragment)) {

				/** 
				 * Take lines back to the current exception's line
				 */
				before_context = phalcon_fetch_nproperty_this(getThis(), SL("_beforeContext"), PH_NOISY TSRMLS_CC);

				PHALCON_INIT_VAR(before_line);
				phalcon_sub_function(before_line, line, before_context);

				/** 
				 * Check for overflows
				 */
				if (PHALCON_LT_LONG(before_line, 1)) {
					PHALCON_CPY_WRT_CTOR(first_line, z_one);
				} else {
					PHALCON_CPY_WRT(first_line, before_line);
				}

				/** 
				 * Take lines after the current exception's line
				 */
				after_context = phalcon_fetch_nproperty_this(getThis(), SL("_afterContext"), PH_NOISY TSRMLS_CC);

				PHALCON_INIT_VAR(after_line);
				phalcon_add_function(after_line, line, after_context);

				/** 
				 * Check for overflows
				 */
				if (PHALCON_GT(after_line, number_lines)) {
					PHALCON_CPY_WRT(last_line, number_lines);
				} else {
					PHALCON_CPY_WRT(last_line, after_line);
				}

				PHALCON_SCONCAT_SVSVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums:", first_line, "'>");
			} else {
				PHALCON_CPY_WRT_CTOR(first_line, z_one);
				PHALCON_CPY_WRT(last_line, number_lines);
				PHALCON_SCONCAT_SVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums error-scroll'>");
			}

			PHALCON_INIT_VAR(comment_pattern);
			ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1);

			charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC);

			PHALCON_INIT_VAR(tab);
			ZVAL_STRING(tab, "\t", 1);

			PHALCON_INIT_VAR(comment);
			ZVAL_STRING(comment, "* /", 1);
			PHALCON_CPY_WRT(i, first_line);

			while (PHALCON_LE(i, last_line)) {

				/** 
				 * Current line in the file
				 */
				PHALCON_INIT_NVAR(line_position);
				phalcon_sub_function(line_position, i, z_one);

				/** 
				 * Current line content in the piece of file
				 */
				PHALCON_OBS_NVAR(current_line);
				phalcon_array_fetch(&current_line, lines, line_position, PH_NOISY);

				/** 
				 * File fragments are cleaned, removing tabs and comments
				 */
				if (zend_is_true(show_file_fragment)) {
					if (PHALCON_IS_EQUAL(i, first_line)) {

						PHALCON_INIT_NVAR(trimmed);
						phalcon_fast_trim(trimmed, current_line, NULL, PHALCON_TRIM_RIGHT TSRMLS_CC);

						PHALCON_INIT_NVAR(is_comment);

						RETURN_MM_ON_FAILURE(phalcon_preg_match(is_comment, comment_pattern, current_line, NULL TSRMLS_CC));

						if (zend_is_true(is_comment)) {
							PHALCON_INIT_NVAR(spaced_current_line);
							phalcon_fast_str_replace(spaced_current_line, comment, space, current_line);
							PHALCON_CPY_WRT(current_line, spaced_current_line);
						}
					}
				}

				/** 
				 * Print a non break space if the current line is a line break, this allows to show
				 * the html zebra properly
				 */
				if (PHALCON_IS_STRING(current_line, "\n")) {
					phalcon_concat_self_str(&html, SL("&nbsp;\n") TSRMLS_CC);
				} else {
					if (PHALCON_IS_STRING(current_line, "\r\n")) {
						phalcon_concat_self_str(&html, SL("&nbsp;\n") TSRMLS_CC);
					} else {
						PHALCON_INIT_NVAR(spaced_current_line);
						phalcon_fast_str_replace(spaced_current_line, tab, two_spaces, current_line);

						PHALCON_INIT_NVAR(escaped_line);
						phalcon_htmlentities(escaped_line, spaced_current_line, NULL, charset TSRMLS_CC);
						phalcon_concat_self(&html, escaped_line TSRMLS_CC);
					}
				}

				phalcon_increment(i);
			}
			phalcon_concat_self_str(&html, SL("</pre>") TSRMLS_CC);
		}
	}

	phalcon_concat_self_str(&html, SL("</td></tr>") TSRMLS_CC);

	RETURN_CTOR(html);
}
示例#12
0
文件: view.c 项目: kenjiroy/cphalcon
/**
 * Loads registered template engines, if none is registered it will use Phalcon\Mvc\View\Engine\Php
 *
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_View, _loadTemplateEngines){

	zval *engines = NULL, *dependency_injector, *registered_engines;
	zval *number_engines, *php_engine, *arguments;
	zval *engine_service = NULL, *extension = NULL, *engine_object = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;

	PHALCON_MM_GROW();

	PHALCON_INIT_VAR(engines);
	phalcon_read_property(&engines, this_ptr, SL("_engines"), PH_NOISY_CC);
	if (PHALCON_IS_FALSE(engines)) {
		PHALCON_INIT_VAR(dependency_injector);
		phalcon_read_property(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
		
		PHALCON_INIT_NVAR(engines);
		array_init(engines);
		
		PHALCON_INIT_VAR(registered_engines);
		phalcon_read_property(&registered_engines, this_ptr, SL("_registeredEngines"), PH_NOISY_CC);
		
		PHALCON_INIT_VAR(number_engines);
		phalcon_fast_count(number_engines, registered_engines TSRMLS_CC);
		if (phalcon_compare_strict_long(number_engines, 0 TSRMLS_CC)) {
			PHALCON_INIT_VAR(php_engine);
			object_init_ex(php_engine, phalcon_mvc_view_engine_php_ce);
			PHALCON_CALL_METHOD_PARAMS_2_NORETURN(php_engine, "__construct", this_ptr, dependency_injector, PH_CHECK);
			phalcon_array_update_string(&engines, SL(".phtml"), &php_engine, PH_COPY | PH_SEPARATE TSRMLS_CC);
		} else {
			if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
				PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the application services");
				return;
			}
			
			PHALCON_INIT_VAR(arguments);
			array_init(arguments);
			phalcon_array_append(&arguments, this_ptr, PH_SEPARATE TSRMLS_CC);
			phalcon_array_append(&arguments, dependency_injector, PH_SEPARATE TSRMLS_CC);
			
			if (!phalcon_valid_foreach(registered_engines TSRMLS_CC)) {
				return;
			}
			
			ah0 = Z_ARRVAL_P(registered_engines);
			zend_hash_internal_pointer_reset_ex(ah0, &hp0);
			
			ph_cycle_start_0:
			
				if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) {
					goto ph_cycle_end_0;
				}
				
				PHALCON_GET_FOREACH_KEY(extension, ah0, hp0);
				PHALCON_GET_FOREACH_VALUE(engine_service);
				
				PHALCON_INIT_NVAR(engine_object);
				PHALCON_CALL_METHOD_PARAMS_2(engine_object, dependency_injector, "getshared", engine_service, arguments, PH_NO_CHECK);
				phalcon_array_update_zval(&engines, extension, &engine_object, PH_COPY | PH_SEPARATE TSRMLS_CC);
				
				zend_hash_move_forward_ex(ah0, &hp0);
				goto ph_cycle_start_0;
				
			ph_cycle_end_0:
			if(0){}
			
		}
		
		phalcon_update_property_zval(this_ptr, SL("_engines"), engines TSRMLS_CC);
	} else {
		PHALCON_INIT_NVAR(engines);
		phalcon_read_property(&engines, this_ptr, SL("_engines"), PH_NOISY_CC);
	}
	
	
	RETURN_CCTOR(engines);
}
示例#13
0
/**
 * Returns a slice of the resultset to show in the pagination
 *
 * @return stdClass
 */
PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, getPaginate){

	zval *one, *config, *items, *show, *page_number = NULL, *page;
	zval *number, *rounded_total, *total_pages, *before_page_number;
	zval *start, *slice, *next = NULL, *before = NULL;

	PHALCON_MM_GROW();

	/** 
	 * TODO: Rewrite the whole method!
	 */
	PHALCON_INIT_VAR(one);
	ZVAL_LONG(one, 1);
	
	PHALCON_OBS_VAR(config);
	phalcon_read_property_this(&config, this_ptr, SL("_config"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(items);
	phalcon_array_fetch_string(&items, config, SL("data"), PH_NOISY);
	if (Z_TYPE_P(items) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator");
		return;
	}
	
	PHALCON_OBS_VAR(show);
	phalcon_read_property_this(&show, this_ptr, SL("_limitRows"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(page_number);
	phalcon_read_property_this(&page_number, this_ptr, SL("_page"), PH_NOISY_CC);
	if (!zend_is_true(page_number)) {
		PHALCON_CPY_WRT(page_number, one);
	}
	
	PHALCON_INIT_VAR(page);
	object_init(page);
	
	PHALCON_INIT_VAR(number);
	phalcon_fast_count(number, items TSRMLS_CC);
	
	PHALCON_INIT_VAR(rounded_total);
	div_function(rounded_total, number, show TSRMLS_CC);
	
	PHALCON_INIT_VAR(total_pages);
	ZVAL_LONG(total_pages, phalcon_get_intval(rounded_total));
	
	/** 
	 * Increase total_pages if wasn't integer
	 */
	if (!PHALCON_IS_EQUAL(total_pages, rounded_total)) {
		phalcon_increment(total_pages);
	}
	
	PHALCON_INIT_VAR(before_page_number);
	sub_function(before_page_number, page_number, one TSRMLS_CC);
	
	PHALCON_INIT_VAR(start);
	mul_function(start, show, before_page_number TSRMLS_CC);
	
	PHALCON_INIT_VAR(slice);
	phalcon_call_func_p3(slice, "array_slice", items, start, show);
	phalcon_update_property_zval(page, SL("items"), slice TSRMLS_CC);
	if (PHALCON_LT(page_number, total_pages)) {
		PHALCON_INIT_VAR(next);
		phalcon_add_function(next, page_number, one TSRMLS_CC);
	} else {
		PHALCON_CPY_WRT(next, total_pages);
	}
	
	phalcon_update_property_zval(page, SL("next"), next TSRMLS_CC);
	if (PHALCON_GT(page_number, one)) {
		PHALCON_INIT_VAR(before);
		sub_function(before, page_number, one TSRMLS_CC);
	} else {
		PHALCON_CPY_WRT(before, one);
	}
	
	phalcon_update_property_zval(page, SL("first"), one TSRMLS_CC);
	phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC);
	phalcon_update_property_zval(page, SL("current"), page_number TSRMLS_CC);
	phalcon_update_property_zval(page, SL("last"), total_pages TSRMLS_CC);
	phalcon_update_property_zval(page, SL("total_pages"), total_pages TSRMLS_CC);
	phalcon_update_property_zval(page, SL("total_items"), number TSRMLS_CC);
	
	RETURN_CTOR(page);
}
示例#14
0
文件: memory.c 项目: bicouy0/cphalcon
/**
 * Rebuild the list of access from the inherit lists
 *
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, _rebuildAccessList){

	zval *roles, *number_roles, *pow_roles, *two, *middle_roles;
	zval *middle, *roles_names, *roles_inherits;
	zval *changed = NULL, *i, *internal_access = NULL, *one = NULL, *role_name = NULL;
	zval *role_inherit = NULL, *inherit_internal = NULL, *access = NULL;
	zval *resource_name = NULL, *value = NULL, *name = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL;
	HashTable *ah0, *ah1, *ah2, *ah3;
	HashPosition hp0, hp1, hp2, hp3;
	zval **hd;

	PHALCON_MM_GROW();

	PHALCON_OBS_VAR(roles);
	phalcon_read_property(&roles, this_ptr, SL("_roles"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(number_roles);
	phalcon_fast_count(number_roles, roles TSRMLS_CC);
	
	PHALCON_INIT_VAR(pow_roles);
	Z_LVAL_P(pow_roles) = Z_LVAL_P(number_roles) * Z_LVAL_P(number_roles);
	
	PHALCON_INIT_VAR(two);
	ZVAL_LONG(two, 2);
	
	PHALCON_INIT_VAR(middle_roles);
	div_function(middle_roles, pow_roles, two TSRMLS_CC);
	
	PHALCON_INIT_VAR(middle);
	PHALCON_CALL_FUNC_PARAMS_1(middle, "ceil", middle_roles);
	
	PHALCON_OBS_VAR(roles_names);
	phalcon_read_property(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(roles_inherits);
	phalcon_read_property(&roles_inherits, this_ptr, SL("_roleInherits"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(changed);
	ZVAL_BOOL(changed, 1);
	
	PHALCON_INIT_VAR(i);
	ZVAL_LONG(i, 0);
	while (1) {
	
		PHALCON_INIT_NVAR(r0);
		is_smaller_or_equal_function(r0, i, middle TSRMLS_CC);
		if (!zend_is_true(r0)) {
			break;
		}
		PHALCON_OBS_NVAR(internal_access);
		phalcon_read_property(&internal_access, this_ptr, SL("_access"), PH_NOISY_CC);
	
		if (!phalcon_is_iterable(roles_names, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
			return;
		}
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_FOREACH_KEY(role_name, ah0, hp0);
			PHALCON_GET_FOREACH_VALUE(one);
	
			if (phalcon_array_isset(roles_inherits, role_name)) {
	
				PHALCON_OBS_NVAR(r1);
				phalcon_array_fetch(&r1, roles_inherits, role_name, PH_NOISY_CC);
	
				if (!phalcon_is_iterable(r1, &ah1, &hp1, 0, 0 TSRMLS_CC)) {
					return;
				}
	
				while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
	
					PHALCON_GET_FOREACH_VALUE(role_inherit);
	
					if (phalcon_array_isset(internal_access, role_inherit)) {
	
						PHALCON_OBS_NVAR(inherit_internal);
						phalcon_array_fetch(&inherit_internal, internal_access, role_inherit, PH_NOISY_CC);
	
						if (!phalcon_is_iterable(inherit_internal, &ah2, &hp2, 0, 0 TSRMLS_CC)) {
							return;
						}
	
						while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) {
	
							PHALCON_GET_FOREACH_KEY(resource_name, ah2, hp2);
							PHALCON_GET_FOREACH_VALUE(access);
	
	
							if (!phalcon_is_iterable(access, &ah3, &hp3, 0, 0 TSRMLS_CC)) {
								return;
							}
	
							while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) {
	
								PHALCON_GET_FOREACH_KEY(name, ah3, hp3);
								PHALCON_GET_FOREACH_VALUE(value);
	
								if (phalcon_array_isset(internal_access, role_name)) {
	
									PHALCON_OBS_NVAR(r2);
									phalcon_array_fetch(&r2, internal_access, role_name, PH_NOISY_CC);
									if (phalcon_array_isset(r2, resource_name)) {
	
										PHALCON_OBS_NVAR(r3);
										phalcon_array_fetch(&r3, internal_access, role_name, PH_NOISY_CC);
										PHALCON_OBS_NVAR(r4);
										phalcon_array_fetch(&r4, r3, resource_name, PH_NOISY_CC);
										if (phalcon_array_isset(r4, name)) {
											zend_hash_move_forward_ex(ah3, &hp3);
											continue;
										}
									}
								}
								phalcon_array_update_zval_zval_zval_multi_3(&internal_access, role_name, resource_name, name, &value, 0 TSRMLS_CC);
	
								PHALCON_INIT_NVAR(changed);
								ZVAL_BOOL(changed, 1);
	
								zend_hash_move_forward_ex(ah3, &hp3);
							}
	
	
							zend_hash_move_forward_ex(ah2, &hp2);
						}
	
					}
	
					zend_hash_move_forward_ex(ah1, &hp1);
				}
	
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
		if (zend_is_true(changed)) {
			phalcon_update_property_zval(this_ptr, SL("_access"), internal_access TSRMLS_CC);
		}
		PHALCON_SEPARATE(i);
		increment_function(i);
	}
	
	PHALCON_MM_RESTORE();
}