当前位置: 首页>>代码示例>>C++>>正文


C++ PHALCON_INIT_NVAR函数代码示例

本文整理汇总了C++中PHALCON_INIT_NVAR函数的典型用法代码示例。如果您正苦于以下问题:C++ PHALCON_INIT_NVAR函数的具体用法?C++ PHALCON_INIT_NVAR怎么用?C++ PHALCON_INIT_NVAR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PHALCON_INIT_NVAR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PHP_METHOD

/**
 * Builds a Phalcon\Mvc\Model\Criteria based on an input array like $_POST
 *
 * @param Phalcon\DiInterface $dependencyInjector
 * @param string $modelName
 * @param array $data
 * @return Phalcon\Mvc\Model\Criteria
 */
PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){

	zval *dependency_injector, *model_name, *data;
	zval *conditions, *service, *meta_data = NULL, *model;
	zval *data_types = NULL, *bind, *value = NULL, *field = NULL, *type, *condition = NULL;
	zval *value_pattern = NULL, *join_conditions;
	zval *column_map = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	zend_class_entry *ce0;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 3, 0, &dependency_injector, &model_name, &data);
	
	if (Z_TYPE_P(data) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Input data must be an Array");
		return;
	}

	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services");
		return;
	}
	
	object_init_ex(return_value, phalcon_mvc_model_criteria_ce);

	if (zend_hash_num_elements(Z_ARRVAL_P(data))) {
	
		PHALCON_INIT_VAR(service);
		PHALCON_ZVAL_MAYBE_INTERNED_STRING(service, phalcon_interned_modelsMetadata);
	
		PHALCON_CALL_METHOD(&meta_data, dependency_injector, "getshared", service);
		PHALCON_VERIFY_INTERFACE(meta_data, phalcon_mvc_model_metadatainterface_ce);
		ce0 = phalcon_fetch_class(model_name TSRMLS_CC);
	
		PHALCON_INIT_VAR(model);
		object_init_ex(model, ce0);
		if (phalcon_has_constructor(model TSRMLS_CC)) {
			PHALCON_CALL_METHOD(NULL, model, "__construct");
		}

		PHALCON_VERIFY_INTERFACE_EX(model, phalcon_mvc_modelinterface_ce, phalcon_mvc_model_exception_ce, 1);

		if (PHALCON_GLOBAL(orm).column_renaming) {
			PHALCON_CALL_METHOD(&column_map, meta_data, "getreversecolumnmap", model);
			if (Z_TYPE_P(column_map) != IS_ARRAY) {
				PHALCON_INIT_NVAR(column_map);
			}
		}
		else {
			column_map = PHALCON_GLOBAL(z_null);
		}

		PHALCON_CALL_METHOD(&data_types, meta_data, "getdatatypes", model);
	
		PHALCON_INIT_VAR(bind);
		array_init(bind);
	
		PHALCON_INIT_VAR(conditions);
		array_init(conditions);

		/** 
		 * We look for attributes in the array passed as data
		 */
		phalcon_is_iterable(data, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
			zval *real_field;
	
			PHALCON_GET_HKEY(field, ah0, hp0);
			PHALCON_GET_HVALUE(value);

			if (Z_TYPE_P(column_map) != IS_ARRAY || !phalcon_array_isset_fetch(&real_field, column_map, field)) {
				real_field = field;
			}
	
			if (phalcon_array_isset_fetch(&type, data_types, real_field)) {
				if (Z_TYPE_P(value) != IS_NULL && !PHALCON_IS_STRING(value, "")) {
					if (PHALCON_IS_LONG(type, 2)) {
						/**
						 * For varchar types we use LIKE operator
						 */
						PHALCON_INIT_NVAR(condition);
						PHALCON_CONCAT_VSVS(condition, field, " LIKE :", field, ":");

						PHALCON_INIT_NVAR(value_pattern);
						PHALCON_CONCAT_SVS(value_pattern, "%", value, "%");
						phalcon_array_update_zval(&bind, field, value_pattern, PH_COPY);
					} else {
						/**
//.........这里部分代码省略.........
开发者ID:CoolCloud,项目名称:cphalcon,代码行数:101,代码来源:criteria.c

示例2: PHP_METHOD

/**
 * Returns the translation related to the given key
 *
 * @param string $index
 * @param array $placeholders
 * @return string
 */
PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, query){

	zval *index, *placeholders = NULL, *translate, *translation = NULL;
	zval *value = NULL, *key = NULL, *key_placeholder = NULL, *replaced = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	int eval_int;

	PHALCON_MM_GROW();

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

	if (!placeholders) {
		PHALCON_INIT_NVAR(placeholders);
	}
	
	PHALCON_INIT_VAR(translate);
	phalcon_read_property(&translate, this_ptr, SL("_translate"), PH_NOISY_CC);
	eval_int = phalcon_array_isset(translate, index);
	if (eval_int) {
		PHALCON_INIT_VAR(translation);
		phalcon_array_fetch(&translation, translate, index, PH_NOISY_CC);
		if (Z_TYPE_P(placeholders) == IS_ARRAY) { 
			if (phalcon_fast_count_ev(placeholders TSRMLS_CC)) {
				
				if (!phalcon_valid_foreach(placeholders TSRMLS_CC)) {
					return;
				}
				
				ah0 = Z_ARRVAL_P(placeholders);
				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(key, ah0, hp0);
					PHALCON_GET_FOREACH_VALUE(value);
					
					PHALCON_INIT_NVAR(key_placeholder);
					PHALCON_CONCAT_SVS(key_placeholder, "%", key, "%");
					
					PHALCON_INIT_NVAR(replaced);
					phalcon_fast_str_replace(replaced, key_placeholder, value, translation TSRMLS_CC);
					PHALCON_CPY_WRT(translation, replaced);
					
					zend_hash_move_forward_ex(ah0, &hp0);
					goto ph_cycle_start_0;
					
				ph_cycle_end_0:
				if(0){}
				
			}
		}
		
		
		RETURN_CCTOR(translation);
	}
	
	
	RETURN_CCTOR(index);
}
开发者ID:alantonilopez,项目名称:cphalcon,代码行数:79,代码来源:nativearray.c

示例3: PHP_METHOD

/**
 * Read the model's column map, this can't be inferred
 *
 * @param Phalcon\Mvc\ModelInterface $model
 * @param Phalcon\DiInterface $dependencyInjector
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getColumnMaps){

	zval *model, *dependency_injector, *service;
	zval *ordered_column_map, *reversed_column_map = NULL;
	zval *annotations = NULL, *class_name, *reflection = NULL;
	zval *exception_message = NULL, *properties_annotations = NULL;
	zval *column_annot_name, *column_map_name;
	zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL;
	zval *column_annotation = NULL, *real_property = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &model, &dependency_injector);

	if (!PHALCON_GLOBAL(orm).column_renaming) {
		RETURN_MM_NULL();
	}

	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid");
		return;
	}

	PHALCON_INIT_VAR(service);
	ZVAL_STRING(service, "annotations", 1);

	PHALCON_CALL_METHOD(&annotations, dependency_injector, "get", service);

	PHALCON_INIT_VAR(class_name);
	phalcon_get_class(class_name, model, 0 TSRMLS_CC);

	PHALCON_CALL_METHOD(&reflection, annotations, "get", class_name);
	if (Z_TYPE_P(reflection) != IS_OBJECT) {
		PHALCON_INIT_VAR(exception_message);
		PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name);
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message);
		return;
	}

	/** 
	 * Get the properties defined in 
	 */
	PHALCON_CALL_METHOD(&properties_annotations, reflection, "getpropertiesannotations");
	if (!phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) {
		PHALCON_INIT_NVAR(exception_message);
		PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name);
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message);
		return;
	}

	/** 
	 * Initialize meta-data
	 */
	PHALCON_INIT_VAR(ordered_column_map);
	array_init(ordered_column_map);

	PHALCON_INIT_VAR(reversed_column_map);
	array_init(reversed_column_map);

	PHALCON_INIT_VAR(column_annot_name);
	ZVAL_STRING(column_annot_name, "Column", 1);

	PHALCON_INIT_VAR(column_map_name);
	ZVAL_STRING(column_map_name, "column", 1);

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

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

		PHALCON_GET_HKEY(property, ah0, hp0);
		PHALCON_GET_HVALUE(prop_annotations);

		/** 
		 * All columns marked with the 'Column' annotation are considered columns
		 */
		PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", column_annot_name);
		if (!zend_is_true(has_annotation)) {
			zend_hash_move_forward_ex(ah0, &hp0);
			continue;
		}

		/** 
		 * Fetch the 'column' annotation
		 */
		PHALCON_CALL_METHOD(&column_annotation, prop_annotations, "get", column_annot_name);

		/** 
		 * Check column map
		 */
		PHALCON_CALL_METHOD(&real_property, column_annotation, "getargument", column_map_name);
//.........这里部分代码省略.........
开发者ID:Myleft,项目名称:cphalcon,代码行数:101,代码来源:annotations.c

示例4: PHP_METHOD

/**
 * Phalcon\Mvc\Model\MetaData\Redis constructor
 *
 * @param array $options
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Redis, __construct){

	zval *options = NULL;
	zval *host, *port, *auth, *persistent, *lifetime, *prefix;
	zval *frontend_data, *redis, *option;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &options);
	
	if (Z_TYPE_P(options) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The options must be an array");
		return;
	}

	if (!phalcon_array_isset_string_fetch(&host, options, SS("host"))) {
		host = NULL;
	}

	if (!phalcon_array_isset_string_fetch(&port, options, SS("port"))) {
		port = NULL;
	}

	if (!phalcon_array_isset_string_fetch(&auth, options, SS("auth"))) {
		auth = NULL;
	}

	if (!phalcon_array_isset_string_fetch(&persistent, options, SS("persistent"))) {
		persistent = NULL;
	}

	if (!phalcon_array_isset_string_fetch(&lifetime, options, SS("lifetime"))) {
		PHALCON_INIT_VAR(lifetime);
		ZVAL_LONG(lifetime, 8600);
	}

	phalcon_update_property_this(this_ptr, SL("_lifetime"), lifetime TSRMLS_CC);

	if (!phalcon_array_isset_string_fetch(&prefix, options, SS("prefix"))) {
		PHALCON_INIT_VAR(prefix);
		ZVAL_EMPTY_STRING(prefix);
	}

	/* create redis instance */
	PHALCON_INIT_VAR(option);
	array_init_size(option, 1);

	phalcon_array_update_string(&option, SL("lifetime"), lifetime, PH_COPY);

	PHALCON_INIT_VAR(frontend_data);
	object_init_ex(frontend_data, phalcon_cache_frontend_data_ce);

	PHALCON_CALL_METHOD(NULL, frontend_data, "__construct", option);

	PHALCON_INIT_NVAR(option);
	array_init(option);

	phalcon_array_update_string_string(&option, SL("statsKey"), SL("$PMM$"), PH_COPY);

	if (host) {
		phalcon_array_update_string(&option, SL("host"), host, PH_COPY);
	}

	if (port) {
		phalcon_array_update_string(&option, SL("port"), port, PH_COPY);
	}

	if (auth) {
		phalcon_array_update_string(&option, SL("auth"), auth, PH_COPY);
	}

	if (persistent) {
		phalcon_array_update_string(&option, SL("persistent"), persistent, PH_COPY);
	}

	phalcon_array_update_string(&option, SL("prefix"), prefix, PH_COPY);

	PHALCON_INIT_VAR(redis);
	object_init_ex(redis, phalcon_cache_backend_redis_ce);

	PHALCON_CALL_METHOD(NULL, redis, "__construct", frontend_data, option);

	phalcon_update_property_this(this_ptr, SL("_redis"), redis TSRMLS_CC);
	
	phalcon_update_property_empty_array(this_ptr, SL("_metaData") TSRMLS_CC);

	PHALCON_MM_RESTORE();
}
开发者ID:Myleft,项目名称:cphalcon,代码行数:93,代码来源:redis.c

示例5: PHP_METHOD

/**
 * Check whether internal resource has rows to fetch
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, valid){

	zval *type = NULL, *result, *row = NULL, *rows, *underscore, *empty_str;
	zval *active_row, *columns_types, *column = NULL, *alias = NULL;
	zval *source = NULL, *instance = NULL, *attributes = NULL, *column_map = NULL;
	zval *row_model = NULL, *attribute = NULL, *column_alias = NULL, *value = NULL;
	zval *model_attribute = NULL, *sql_alias = NULL, *n_alias = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;
	int eval_int;

	PHALCON_MM_GROW();

	PHALCON_INIT_VAR(type);
	phalcon_read_property(&type, this_ptr, SL("_type"), PH_NOISY_CC);
	if (zend_is_true(type)) {
		PHALCON_INIT_VAR(result);
		phalcon_read_property(&result, this_ptr, SL("_result"), PH_NOISY_CC);
		if (PHALCON_IS_NOT_FALSE(result)) {
			PHALCON_INIT_VAR(row);
			PHALCON_CALL_METHOD_PARAMS_1(row, result, "fetch", result, PH_NO_CHECK);
		} else {
			PHALCON_INIT_NVAR(row);
			ZVAL_BOOL(row, 0);
		}
	} else {
		PHALCON_INIT_VAR(rows);
		phalcon_read_property(&rows, this_ptr, SL("_rows"), PH_NOISY_CC);
		Z_SET_ISREF_P(rows);
	
		PHALCON_INIT_NVAR(row);
		PHALCON_CALL_FUNC_PARAMS_1(row, "current", rows);
		Z_UNSET_ISREF_P(rows);
		if (zend_is_true(row)) {
			Z_SET_ISREF_P(rows);
			PHALCON_CALL_FUNC_PARAMS_1_NORETURN("next", rows);
			Z_UNSET_ISREF_P(rows);
		}
	}
	
	if (PHALCON_IS_NOT_FALSE(row)) {
		PHALCON_INIT_VAR(underscore);
		ZVAL_STRING(underscore, "_", 1);
	
		PHALCON_INIT_VAR(empty_str);
		ZVAL_STRING(empty_str, "", 1);
	
		PHALCON_INIT_VAR(active_row);
		object_init_ex(active_row, phalcon_mvc_model_row_ce);
	
		PHALCON_INIT_VAR(columns_types);
		phalcon_read_property(&columns_types, this_ptr, SL("_columnTypes"), PH_NOISY_CC);
	
		if (!phalcon_valid_foreach(columns_types TSRMLS_CC)) {
			return;
		}
	
		ah0 = Z_ARRVAL_P(columns_types);
		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(alias, ah0, hp0);
			PHALCON_GET_FOREACH_VALUE(column);
	
			PHALCON_INIT_NVAR(type);
			phalcon_array_fetch_string(&type, column, SL("type"), PH_NOISY_CC);
			if (PHALCON_COMPARE_STRING(type, "object")) {
				/** 
				 * Object columns are assigned column by column
				 */
				PHALCON_INIT_NVAR(source);
				phalcon_array_fetch_string(&source, column, SL("column"), PH_NOISY_CC);
	
				PHALCON_INIT_NVAR(instance);
				phalcon_array_fetch_string(&instance, column, SL("instance"), PH_NOISY_CC);
	
				PHALCON_INIT_NVAR(attributes);
				phalcon_array_fetch_string(&attributes, column, SL("attributes"), PH_NOISY_CC);
	
				PHALCON_INIT_NVAR(column_map);
				phalcon_array_fetch_string(&column_map, column, SL("columnMap"), PH_NOISY_CC);
	
				/** 
				 * Assign the values from the _source_attribute notation to its real column name
				 */
//.........这里部分代码省略.........
开发者ID:Tigerlee1987,项目名称:cphalcon,代码行数:101,代码来源:complex.c

示例6: PHP_METHOD

/**
 * Moves internal resulset cursor to another position letting us to fetch a certain row
 *
 *<code>
 *	$result = $connection->query("SELECT * FROM robots ORDER BY name");
 *	$result->dataSeek(2); // Move to third row on result
 *	$row = $result->fetch(); // Fetch third row
 *</code>
 *
 * @param int $number
 */
PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){

	long number = 0, n;
	zval *connection, *pdo, *sql_statement;
	zval *bind_params, *bind_types, *statement = NULL;
	zval *temp_statement = NULL;
	pdo_stmt_t *stmt;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &number) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(connection);
	phalcon_read_property(&connection, this_ptr, SL("_connection"), PH_NOISY_CC);

	PHALCON_INIT_VAR(pdo);
	PHALCON_CALL_METHOD(pdo, connection, "getinternalhandler", PH_NO_CHECK);

	PHALCON_INIT_VAR(sql_statement);
	phalcon_read_property(&sql_statement, this_ptr, SL("_sqlStatement"), PH_NOISY_CC);

	PHALCON_INIT_VAR(bind_params);
	phalcon_read_property(&bind_params, this_ptr, SL("_bindParams"), PH_NOISY_CC);

	/**
	 * PDO doesn't support scrollable cursors, so we need to re-execute the statement again
	 */
	if (Z_TYPE_P(bind_params) == IS_ARRAY) {

		PHALCON_INIT_VAR(bind_types);
		phalcon_read_property(&bind_types, this_ptr, SL("_bindTypes"), PH_NOISY_CC);

		PHALCON_INIT_VAR(statement);
		PHALCON_CALL_METHOD_PARAMS_1(statement, pdo, "prepare", sql_statement, PH_NO_CHECK);
		if (Z_TYPE_P(statement) == IS_OBJECT) {
			PHALCON_INIT_VAR(temp_statement);
			PHALCON_CALL_METHOD_PARAMS_3(temp_statement, connection, "executeprepared", statement, bind_params, bind_types, PH_NO_CHECK);
			PHALCON_CPY_WRT(statement, temp_statement);
		}

	} else {
		PHALCON_INIT_NVAR(statement);
		PHALCON_CALL_METHOD_PARAMS_1(statement, pdo, "query", sql_statement, PH_NO_CHECK);
	}

	phalcon_update_property_zval(this_ptr, SL("_pdoStatement"), statement TSRMLS_CC);

	/**
	 * This a fetch scroll to reach the desired position, however with a big number of records
	 * maybe it may be very slow
	 */

	stmt = (pdo_stmt_t*) zend_object_store_get_object(statement TSRMLS_CC);
	if (!stmt->dbh) {
		PHALCON_MM_RESTORE();
		RETURN_FALSE;
	}

	n = -1;
	number--;
	while (n != number) {

		if(!stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0 TSRMLS_CC)) {
			PHALCON_MM_RESTORE();
			RETURN_NULL();
		}

		n++;
	}

	PHALCON_MM_RESTORE();
}
开发者ID:Tigerlee1987,项目名称:cphalcon,代码行数:86,代码来源:pdo.c

示例7: PHP_METHOD

/**
 * Handles a MVC request
 *
 * @param string $uri
 * @return Phalcon\Http\ResponseInterface
 */
PHP_METHOD(Phalcon_Mvc_JsonRpc, handle){

	zval *uri = NULL, *dependency_injector, *events_manager;
	zval *status = NULL, *service = NULL, *request = NULL, *response = NULL;
	zval *json = NULL, *data = NULL, *jsonrpc_message, *jsonrpc_error, *jsonrpc_result = NULL;
	zval *jsonrpc_method, *jsonrpc_params, *jsonrpc_id;
	zval *url = NULL, *router = NULL, *module_name = NULL;
	zval *module_object = NULL, *modules;
	zval *module, *class_name = NULL, *module_params;
	zval *namespace_name = NULL;
	zval *controller_name = NULL, *action_name = NULL, *params = NULL, *exact = NULL;
	zval *dispatcher = NULL, *controller = NULL, *returned_response = NULL;
	zval *path;

	PHALCON_MM_GROW();
	
	dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY);
	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_jsonrpc_exception_ce, "A dependency injection object is required to access internal services");
		return;
	}
	
	events_manager = phalcon_read_property(getThis(), SL("_eventsManager"), PH_NOISY);
	if (Z_TYPE_P(events_manager) != IS_OBJECT) {
		events_manager = NULL;
	}
	else {
		PHALCON_VERIFY_INTERFACE_EX(events_manager, phalcon_events_managerinterface_ce, phalcon_mvc_jsonrpc_exception_ce, 1);
	}

	/* Call boot event, this allows the developer to perform initialization actions */
	if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:boot", getThis(), NULL)) {
		RETURN_MM_FALSE;
	}

	/* Deserializer Json */

	PHALCON_INIT_NVAR(service);
	ZVAL_STR(service, IS(request));
	
	PHALCON_CALL_METHOD(&request, dependency_injector, "getshared", service);
	PHALCON_VERIFY_INTERFACE(request, phalcon_http_requestinterface_ce);

	PHALCON_CALL_METHOD(&json, request, "getrawbody");
	PHALCON_CALL_FUNCTION(&data, "json_decode", json, &PHALCON_GLOBAL(z_true));


	PHALCON_INIT_NVAR(service);
	ZVAL_STR(service, IS(response));

	PHALCON_CALL_METHOD(&response, dependency_injector, "getshared", service);
	PHALCON_VERIFY_INTERFACE(response, phalcon_http_responseinterface_ce);

	PHALCON_INIT_VAR(jsonrpc_message);
	array_init(jsonrpc_message);
	
	PHALCON_INIT_VAR(jsonrpc_error);
	array_init(jsonrpc_error);

	if (PHALCON_IS_EMPTY(data)) {
		phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0);
		phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Parse error"), PH_COPY);
	} else if (Z_TYPE_P(data) != IS_ARRAY) {
		phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0);
		phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Parse error"), PH_COPY);
	} else if (!phalcon_array_isset_str(data, SL("jsonrpc"))) {		
			phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0);
			phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Invalid Request"), PH_COPY);
	} else if (!phalcon_array_isset_str(data, SL("method"))) {
			phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0);
			phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Invalid Request"), PH_COPY);
	} else {
		PHALCON_OBS_VAR(jsonrpc_method);
		phalcon_array_fetch_str(&jsonrpc_method, data, SL("method"), PH_NOISY);

		if (phalcon_array_isset_str(data, SL("params"))) {
			PHALCON_OBS_VAR(jsonrpc_params);
			phalcon_array_fetch_str(&jsonrpc_params, data, SL("params"), PH_NOISY);
		} else {
			PHALCON_INIT_VAR(jsonrpc_params);
			array_init(jsonrpc_params);
		}

		PHALCON_INIT_NVAR(service);
		ZVAL_STR(service, IS(url));
		PHALCON_CALL_METHOD(&url, dependency_injector, "getshared", service);
		PHALCON_VERIFY_INTERFACE(url, phalcon_mvc_urlinterface_ce);

		PHALCON_CALL_METHOD(&uri, url, "get", jsonrpc_method);

		PHALCON_INIT_NVAR(service);
		ZVAL_STR(service, IS(router));
		PHALCON_CALL_METHOD(&router, dependency_injector, "getshared", service);
		PHALCON_VERIFY_INTERFACE(router, phalcon_mvc_routerinterface_ce);
//.........这里部分代码省略.........
开发者ID:Myleft,项目名称:cphalcon7,代码行数:101,代码来源:jsonrpc.c

示例8: PHP_METHOD

/**
 * Lists table references
 *
 *<code>
 * print_r($connection->describeReferences('robots_parts'));
 *</code>
 *
 * @param string $table
 * @param string $schema
 * @return Phalcon\Db\Reference[]
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, describeReferences){

	zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *empty_arr;
	zval *references, *describe, *reference = NULL, *constraint_name = NULL;
	zval *referenced_schema = NULL, *referenced_table = NULL;
	zval *reference_array = NULL, *column_name = NULL, *referenced_columns = NULL;
	zval *reference_objects, *array_reference = NULL;
	zval *name = NULL, *columns = NULL, *definition = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &table, &schema) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (!schema) {
		PHALCON_INIT_VAR(schema);
	}
	
	PHALCON_OBS_VAR(dialect);
	phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC);
	
	/** 
	 * We're using FETCH_NUM to fetch the columns
	 */
	PHALCON_INIT_VAR(fetch_num);
	ZVAL_LONG(fetch_num, 3);
	
	/** 
	 * Get the SQL required to describe the references from the Dialect
	 */
	PHALCON_INIT_VAR(sql);
	PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "describereferences", table, schema);
	
	PHALCON_INIT_VAR(empty_arr);
	array_init(empty_arr);
	
	PHALCON_INIT_VAR(references);
	array_init(references);
	
	/** 
	 * Execute the SQL returning the 
	 */
	PHALCON_INIT_VAR(describe);
	PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_num);
	
	if (!phalcon_is_iterable(describe, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
		return;
	}
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_FOREACH_VALUE(reference);
	
		PHALCON_OBS_NVAR(constraint_name);
		phalcon_array_fetch_long(&constraint_name, reference, 2, PH_NOISY_CC);
		if (!phalcon_array_isset(references, constraint_name)) {
			PHALCON_OBS_NVAR(referenced_schema);
			phalcon_array_fetch_long(&referenced_schema, reference, 3, PH_NOISY_CC);
	
			PHALCON_OBS_NVAR(referenced_table);
			phalcon_array_fetch_long(&referenced_table, reference, 4, PH_NOISY_CC);
	
			PHALCON_INIT_NVAR(reference_array);
			array_init_size(reference_array, 4);
			phalcon_array_update_string(&reference_array, SL("referencedSchema"), &referenced_schema, PH_COPY | PH_SEPARATE TSRMLS_CC);
			phalcon_array_update_string(&reference_array, SL("referencedTable"), &referenced_table, PH_COPY | PH_SEPARATE TSRMLS_CC);
			phalcon_array_update_string(&reference_array, SL("columns"), &empty_arr, PH_COPY | PH_SEPARATE TSRMLS_CC);
			phalcon_array_update_string(&reference_array, SL("referencedColumns"), &empty_arr, PH_COPY | PH_SEPARATE TSRMLS_CC);
			phalcon_array_update_zval(&references, constraint_name, &reference_array, PH_COPY | PH_SEPARATE TSRMLS_CC);
		}
	
		PHALCON_OBS_NVAR(column_name);
		phalcon_array_fetch_long(&column_name, reference, 1, PH_NOISY_CC);
		phalcon_array_update_zval_string_append_multi_3(&references, constraint_name, SL("columns"), &column_name, 0 TSRMLS_CC);
	
		PHALCON_OBS_NVAR(referenced_columns);
		phalcon_array_fetch_long(&referenced_columns, reference, 5, PH_NOISY_CC);
		phalcon_array_update_zval_string_append_multi_3(&references, constraint_name, SL("referencedColumns"), &referenced_columns, 0 TSRMLS_CC);
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	PHALCON_INIT_VAR(reference_objects);
	array_init(reference_objects);
	
//.........这里部分代码省略.........
开发者ID:BlueShark,项目名称:cphalcon,代码行数:101,代码来源:pdo.c

示例9: PHP_METHOD

/**
 * Gets the column name in Sqlite
 *
 * @param Phalcon\Db\ColumnInterface $column
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Sqlite, getColumnDefinition){

	zval *column, *size = NULL, *column_type = NULL, *column_sql = NULL;
	zval *scale = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &column);
	
	if (Z_TYPE_P(column) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an instance of Phalcon\\Db\\Column");
		return;
	}
	
	PHALCON_CALL_METHOD(&size, column, "getsize");
	PHALCON_CALL_METHOD(&column_type, column, "gettype");
	
	switch (phalcon_get_intval(column_type)) {
	
		case 0:
			PHALCON_INIT_VAR(column_sql);
			ZVAL_STRING(column_sql, "INT");
			break;
	
		case 1:
			PHALCON_INIT_NVAR(column_sql);
			ZVAL_STRING(column_sql, "DATE");
			break;
	
		case 2:
			PHALCON_INIT_NVAR(column_sql);
			PHALCON_CONCAT_SVS(column_sql, "VARCHAR(", size, ")");
			break;
	
		case 3:
			PHALCON_CALL_METHOD(&scale, column, "getscale");
	
			PHALCON_INIT_NVAR(column_sql);
			PHALCON_CONCAT_SVSVS(column_sql, "NUMERIC(", size, ",", scale, ")");
			break;
	
		case 4:
			PHALCON_INIT_NVAR(column_sql);
			ZVAL_STRING(column_sql, "TIMESTAMP");
			break;
	
		case 5:
			PHALCON_INIT_NVAR(column_sql);
			PHALCON_CONCAT_SVS(column_sql, "CHARACTER(", size, ")");
			break;
	
		case 6:
			PHALCON_INIT_NVAR(column_sql);
			ZVAL_STRING(column_sql, "TEXT");
			break;
	
		case 7:
			PHALCON_INIT_NVAR(column_sql);
			ZVAL_STRING(column_sql, "FLOAT");
			break;
	
		default:
			PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized SQLite data type");
			return;
	
	}
	
	RETURN_CTOR(column_sql);
}
开发者ID:Myleft,项目名称:cphalcon7,代码行数:75,代码来源:sqlite.c

示例10: PHP_METHOD

/**
 * Executes validator
 *
 * @param Phalcon\Mvc\ModelInterface $record
 * @return boolean
 */
PHP_METHOD(Phalcon_Mvc_Model_Validator_Inclusionin, validate){

	zval *record, *field = NULL, *is_set = NULL, *domain = NULL;
	zval *value = NULL, *option, *message = NULL, *joined_domain, *is_set_code = NULL, *code = NULL;
	zval *type;
	zval *allow_empty = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &record);
	
	PHALCON_INIT_VAR(option);
	ZVAL_STRING(option, "field", 1);
	
	PHALCON_CALL_METHOD(&field, this_ptr, "getoption", option);
	if (Z_TYPE_P(field) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string");
		return;
	}
	
	/** 
	 * The 'domain' option must be a valid array of not allowed values
	 */
	PHALCON_INIT_NVAR(option);
	ZVAL_STRING(option, "domain", 1);
	
	PHALCON_CALL_METHOD(&is_set, this_ptr, "issetoption", option);
	if (PHALCON_IS_FALSE(is_set)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'domain' is required for this validator");
		return;
	}
	
	PHALCON_INIT_NVAR(option);
	ZVAL_STRING(option, "domain", 1);
	
	PHALCON_CALL_METHOD(&domain, this_ptr, "getoption", option);
	if (Z_TYPE_P(domain) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Option 'domain' must be an array");
		return;
	}
	
	PHALCON_CALL_METHOD(&value, record, "readattribute", field);

	/*
	 * Allow empty
	 */
	PHALCON_INIT_NVAR(option);
	ZVAL_STRING(option, "allowEmpty", 1);

	PHALCON_CALL_METHOD(&allow_empty, this_ptr, "getoption", option);
	if (allow_empty && zend_is_true(allow_empty) && PHALCON_IS_EMPTY(value)) {
		RETURN_MM_TRUE;
	}
	
	/** 
	 * Check if the value is contained in the array
	 */
	if (!phalcon_fast_in_array(value, domain TSRMLS_CC)) {
	
		/** 
		 * Check if the developer has defined a custom message
		 */
		PHALCON_INIT_NVAR(option);
		PHALCON_ZVAL_MAYBE_INTERNED_STRING(option, phalcon_interned_message);
	
		PHALCON_CALL_METHOD(&message, this_ptr, "getoption", option);
		if (!zend_is_true(message)) {
			PHALCON_INIT_VAR(joined_domain);
			phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC);
	
			PHALCON_INIT_NVAR(message);
			PHALCON_CONCAT_SVSV(message, "Value of field '", field, "' must be part of list: ", joined_domain);
		}
	
		PHALCON_INIT_VAR(type);
		ZVAL_STRING(type, "Inclusion", 1);

		/*
		 * Is code set
		 */
		PHALCON_INIT_NVAR(option);
		PHALCON_ZVAL_MAYBE_INTERNED_STRING(option, phalcon_interned_code);

		PHALCON_CALL_METHOD(&is_set_code, this_ptr, "issetoption", option);
		if (zend_is_true(is_set_code)) {
			PHALCON_CALL_METHOD(&code, this_ptr, "getoption", option);
		} else {
			PHALCON_INIT_VAR(code);
			ZVAL_LONG(code, 0);
		}

		PHALCON_CALL_METHOD(NULL, this_ptr, "appendmessage", message, field, type, code);
		RETURN_MM_FALSE;
	}
//.........这里部分代码省略.........
开发者ID:9466,项目名称:cphalcon,代码行数:101,代码来源:inclusionin.c

示例11: PHP_METHOD

/**
 * Gets number of rows returned by a resulset
 *
 *<code>
 *	$result = $connection->query("SELECT * FROM robots ORDER BY name");
 *	echo 'There are ', $result->numRows(), ' rows in the resulset';
 *</code>
 *
 * @return int
 */
PHP_METHOD(Phalcon_Db_Result_Pdo, numRows){

	zval *row_count = NULL, *connection, *type = NULL, *pdo_statement = NULL;
	zval *sql_statement, *bind_params, *bind_types;
	zval *matches, *pattern, *match, *else_clauses;
	zval *sql, *result = NULL, *row = NULL;

	PHALCON_MM_GROW();

	row_count = phalcon_read_property(getThis(), SL("_rowCount"), PH_NOISY);
	if (PHALCON_IS_FALSE(row_count)) {
		connection = phalcon_read_property(getThis(), SL("_connection"), PH_NOISY);
	
		PHALCON_CALL_METHOD(&type, connection, "gettype");
	
		/** 
		 * MySQL/PostgreSQL library property returns the number of records
		 */
		if (PHALCON_IS_STRING(type, "mysql") || PHALCON_IS_STRING(type, "pgsql")) {
			pdo_statement = phalcon_read_property(getThis(), SL("_pdoStatement"), PH_NOISY);
			PHALCON_CALL_METHOD(&row_count, pdo_statement, "rowcount");
		}
	
		/** 
		 * We should get the count using a new statement :(
		 */
		if (PHALCON_IS_FALSE(row_count)) {
	
			/** 
			 * SQLite/Oracle/SQLServer returns resultsets that to the client eyes (PDO) has an
			 * arbitrary number of rows, so we need to perform an extra count to know that
			 */
			sql_statement = phalcon_read_property(getThis(), SL("_sqlStatement"), PH_NOISY);
	
			/** 
			 * If the sql_statement starts with SELECT COUNT(*) we don't make the count
			 */
			if (!phalcon_start_with_str(sql_statement, SL("SELECT COUNT(*) "))) {
				bind_params = phalcon_read_property(getThis(), SL("_bindParams"), PH_NOISY);
				bind_types = phalcon_read_property(getThis(), SL("_bindTypes"), PH_NOISY);
	
				PHALCON_INIT_VAR(matches);
	
				PHALCON_INIT_VAR(pattern);
				ZVAL_STRING(pattern, "/^SELECT\\s+(.*)$/i");
	
				PHALCON_INIT_VAR(match);
				RETURN_MM_ON_FAILURE(phalcon_preg_match(match, pattern, sql_statement, matches));
	
				if (zend_is_true(match)) {
					PHALCON_OBS_VAR(else_clauses);
					phalcon_array_fetch_long(&else_clauses, matches, 1, PH_NOISY);
	
					PHALCON_INIT_VAR(sql);
					PHALCON_CONCAT_SVS(sql, "SELECT COUNT(*) \"numrows\" FROM (SELECT ", else_clauses, ")");
	
					PHALCON_CALL_METHOD(&result, connection, "query", sql, bind_params, bind_types);
					PHALCON_CALL_METHOD(&row, result, "fetch");
	
					PHALCON_OBS_NVAR(row_count);
					phalcon_array_fetch_str(&row_count, row, SL("numrows"), PH_NOISY);
				}
			} else {
				PHALCON_INIT_NVAR(row_count);
				ZVAL_LONG(row_count, 1);
			}
		}
	
		/** 
		 * Update the value to avoid further calculations
		 */
		phalcon_update_property_this(getThis(), SL("_rowCount"), row_count);
	}
	
	RETURN_CCTOR(row_count);
}
开发者ID:Myleft,项目名称:cphalcon7,代码行数:86,代码来源:pdo.c

示例12: PHP_METHOD

/**
 * Magic method __get
 *
 * @param string $propertyName
 */
PHP_METHOD(Phalcon_DI_Injectable, __get){


	zval *property_name, *dependency_injector = NULL;
	zval *has_service, *service = NULL, *class_name, *arguments;
	zval *persistent;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &property_name);

	PHALCON_OBS_VAR(dependency_injector);
	phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {

		PHALCON_INIT_NVAR(dependency_injector);
		PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault");

		if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "A dependency injection object is required to access the application services");
			return;
		}
	}

	/**
	 * Fallback to the PHP userland if the cache is not available
	 */
	PHALCON_INIT_VAR(has_service);
	phalcon_call_method_p1(has_service, dependency_injector, "has", property_name);
	if (zend_is_true(has_service)) {
		PHALCON_INIT_VAR(service);
		phalcon_call_method_p1(service, dependency_injector, "getshared", property_name);
		phalcon_update_property_zval_zval(this_ptr, property_name, service TSRMLS_CC);
		RETURN_CCTOR(service);
	}

	if (PHALCON_IS_STRING(property_name, "di")) {
		phalcon_update_property_this(this_ptr, SL("di"), dependency_injector TSRMLS_CC);
		RETURN_CCTOR(dependency_injector);
	}

	/**
	 * Accessing the persistent property will create a session bag in any class
	 */
	if (PHALCON_IS_STRING(property_name, "persistent")) {
		PHALCON_INIT_VAR(class_name);
		phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC);

		PHALCON_INIT_VAR(arguments);
		array_init_size(arguments, 1);
		phalcon_array_append(&arguments, class_name, PH_SEPARATE);

		PHALCON_INIT_NVAR(service);
		ZVAL_STRING(service, "sessionBag", 1);

		PHALCON_INIT_VAR(persistent);
		phalcon_call_method_p2(persistent, dependency_injector, "get", service, arguments);
		phalcon_update_property_this(this_ptr, SL("persistent"), persistent TSRMLS_CC);
		RETURN_CCTOR(persistent);
	}

	/**
	 * A notice is shown if the property is not defined and isn't a valid service
	 */
	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Access to undefined property %s", Z_STRVAL_P(property_name));
	RETURN_MM_NULL();
}
开发者ID:11mariom,项目名称:cphalcon,代码行数:72,代码来源:injectable.c

示例13: PHP_METHOD

/**
 * Stores cached content into the APC backend and stops the frontend
 *
 * @param string $keyName
 * @param string $content
 * @param long $lifetime
 * @param boolean $stopBuffer
 */
PHP_METHOD(Phalcon_Cache_Backend_Apc, save) {

    zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL;
    zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL;
    zval *prepared_content, *ttl = NULL, *is_buffering;

    PHALCON_MM_GROW();

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zzzz", &key_name, &content, &lifetime, &stop_buffer) == FAILURE) {
        RETURN_MM_NULL();
    }

    if (!key_name) {
        PHALCON_INIT_VAR(key_name);
    }

    if (!content) {
        PHALCON_INIT_VAR(content);
    }

    if (!lifetime) {
        PHALCON_INIT_VAR(lifetime);
    }

    if (!stop_buffer) {
        PHALCON_INIT_VAR(stop_buffer);
        ZVAL_BOOL(stop_buffer, 1);
    }

    if (Z_TYPE_P(key_name) == IS_NULL) {
        PHALCON_OBS_VAR(last_key);
        phalcon_read_property_this(&last_key, this_ptr, SL("_lastKey"), PH_NOISY_CC);
    } else {
        PHALCON_OBS_VAR(prefix);
        phalcon_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);

        PHALCON_INIT_NVAR(last_key);
        PHALCON_CONCAT_SVV(last_key, "_PHCA", prefix, key_name);
    }
    if (!zend_is_true(last_key)) {
        PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first");
        return;
    }

    PHALCON_OBS_VAR(frontend);
    phalcon_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC);
    if (Z_TYPE_P(content) == IS_NULL) {
        PHALCON_INIT_VAR(cached_content);
        PHALCON_CALL_METHOD(cached_content, frontend, "getcontent");
    } else {
        PHALCON_CPY_WRT(cached_content, content);
    }

    PHALCON_INIT_VAR(prepared_content);
    PHALCON_CALL_METHOD_PARAMS_1(prepared_content, frontend, "beforestore", cached_content);
    if (Z_TYPE_P(lifetime) == IS_NULL) {
        PHALCON_INIT_VAR(ttl);
        PHALCON_CALL_METHOD(ttl, frontend, "getlifetime");
    } else {
        PHALCON_CPY_WRT(ttl, lifetime);
    }

    PHALCON_CALL_FUNC_PARAMS_3_NORETURN("apc_store", last_key, prepared_content, ttl);

    PHALCON_INIT_VAR(is_buffering);
    PHALCON_CALL_METHOD(is_buffering, frontend, "isbuffering");
    if (PHALCON_IS_TRUE(stop_buffer)) {
        PHALCON_CALL_METHOD_NORETURN(frontend, "stop");
    }

    if (PHALCON_IS_TRUE(is_buffering)) {
        zend_print_zval(cached_content, 0);
    }

    phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC);

    PHALCON_MM_RESTORE();
}
开发者ID:vguardiola,项目名称:cphalcon,代码行数:86,代码来源:apc.c

示例14: PHP_METHOD

/**
 * Outputs a message formatting it with HTML
 *
 *<code>
 * $flash->outputMessage('error', $message);
 *</code>
 *
 * @param string $type
 * @param string $message
 */
PHP_METHOD(Phalcon_Flash, outputMessage){

	zval *type, *message, *automatic_html, *classes;
	zval *type_classes, *joined_classes, *css_classes = NULL;
	zval *implicit_flush, *content, *msg = NULL, *html_message = NULL;
	int flag_automatic_html;
	int flag_implicit_flush;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &type, &message);

	automatic_html      = phalcon_read_property(getThis(), SL("_automaticHtml"), PH_NOISY);
	flag_automatic_html = zend_is_true(automatic_html);
	if (flag_automatic_html) {

		classes = phalcon_read_property(getThis(), SL("_cssClasses"), PH_NOISY);

		PHALCON_INIT_VAR(css_classes);
		if (phalcon_array_isset_fetch(&type_classes, classes, type)) {
			if (Z_TYPE_P(type_classes) == IS_ARRAY) {
				PHALCON_INIT_VAR(joined_classes);
				phalcon_fast_join_str(joined_classes, SL(" "), type_classes);

				PHALCON_CONCAT_SVS(css_classes, " class=\"", joined_classes, "\"");
			} else {
				PHALCON_CONCAT_SVS(css_classes, " class=\"", type_classes, "\"");
			}
		} else {
			ZVAL_EMPTY_STRING(css_classes);
		}
	}

	implicit_flush      = phalcon_read_property(getThis(), SL("_implicitFlush"), PH_NOISY);
	flag_implicit_flush = zend_is_true(implicit_flush);
	if (Z_TYPE_P(message) == IS_ARRAY) {

		/**
		 * We create the message with implicit flush or other
		 */
		if (!flag_implicit_flush) {
			PHALCON_INIT_VAR(content);
			ZVAL_EMPTY_STRING(content);
		}

		/**
		 * We create the message with implicit flush or other
		 */
		ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(message), msg) {
			/**
			 * We create the applying formatting or not
			 */
			if (flag_automatic_html) {
				PHALCON_INIT_NVAR(html_message);
				PHALCON_CONCAT_SVSVS(html_message, "<div", css_classes, ">", msg, "</div>" PHP_EOL);
			} else {
				PHALCON_CPY_WRT(html_message, msg);
			}

			if (flag_implicit_flush) {
				zend_print_zval(html_message, 0);
			} else {
				phalcon_concat_self(content, html_message);
			}
		} ZEND_HASH_FOREACH_END();

		/**
		 * We return the message as string if the implicit_flush is turned off
		 */
		if (!flag_implicit_flush) {
			RETURN_CTOR(content);
		}
	} else {
		/**
		 * We create the applying formatting or not
		 */
		if (flag_automatic_html) {
开发者ID:Myleft,项目名称:cphalcon7,代码行数:87,代码来源:flash.c

示例15: PHP_METHOD

/**
 * Read the model's column map, this can't be infered
 *
 * @param Phalcon\Mvc\ModelInterface $model
 * @param Phalcon\DiInterface $dependencyInjector
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getColumnMaps){

	zval *model, *dependency_injector;
	zval *ordered_column_map = NULL, *columns = NULL, *column_name = NULL, *reversed_column_map = NULL;
	zval *user_name = NULL, *name = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &model, &dependency_injector);

	if (!PHALCON_GLOBAL(orm).column_renaming) {
		RETURN_MM_NULL();
	}

	/** 
	 * Check for a columnMap() method on the model
	 */
	if (phalcon_method_exists_ex(model, SS("columnmap") TSRMLS_CC) == SUCCESS) {
	
		PHALCON_CALL_METHOD(&ordered_column_map, model, "columnmap");
		if (Z_TYPE_P(ordered_column_map) != IS_ARRAY) { 
			PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "columnMap() not returned an array");
			return;
		}

		PHALCON_CALL_METHOD(&columns, model, "getcolumns");

		if (Z_TYPE_P(columns) == IS_ARRAY) {

			phalcon_is_iterable(columns, &ah0, &hp0, 0, 0);	
			while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

				PHALCON_GET_HVALUE(column_name);

				if (!phalcon_array_isset(ordered_column_map, column_name)) {
					phalcon_array_update_zval(&ordered_column_map, column_name, column_name, PH_COPY);
				}
		
				zend_hash_move_forward_ex(ah0, &hp0);
			}
		}

		PHALCON_INIT_VAR(reversed_column_map);
		array_init(reversed_column_map);

		phalcon_is_iterable(ordered_column_map, &ah1, &hp1, 0, 0);	
		while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {

			PHALCON_GET_HKEY(name, ah1, hp1);
			PHALCON_GET_HVALUE(user_name);

			phalcon_array_update_zval(&reversed_column_map, user_name, name, PH_COPY);
	
			zend_hash_move_forward_ex(ah1, &hp1);
		}
	} else {
		PHALCON_INIT_NVAR(ordered_column_map);
		PHALCON_INIT_VAR(reversed_column_map);
	}
	
	/** 
	 * Store the column map
	 */
	array_init_size(return_value, 2);
	phalcon_array_update_long(&return_value, 0, ordered_column_map, PH_COPY);
	phalcon_array_update_long(&return_value, 1, reversed_column_map, PH_COPY);
	
	PHALCON_MM_RESTORE();
}
开发者ID:tianhendi,项目名称:cphalcon,代码行数:79,代码来源:introspection.c


注:本文中的PHALCON_INIT_NVAR函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。