示例#1
0
/**
 * Phalcon\Config\Adapter\Ini constructor
 *
 * @param string $filePath
 */
PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){

	zval *file_path, *process_sections, *ini_config;
	zval *exception_message, *config, *directives = NULL;
	zval *section = NULL, *value = NULL, *key = NULL, *directive_parts = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &file_path);
	
	PHALCON_INIT_VAR(process_sections);
	ZVAL_BOOL(process_sections, 1);
	
	/** 
	 * Use the standard parse_ini_file
	 */
	PHALCON_INIT_VAR(ini_config);
	phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, process_sections);
	
	/** 
	 * Check if the file had errors
	 */
	if (PHALCON_IS_FALSE(ini_config)) {
		PHALCON_INIT_VAR(exception_message);
		PHALCON_CONCAT_SVS(exception_message, "Configuration file ", file_path, " can't be loaded");
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_config_exception_ce, exception_message);
		return;
	}
	
	PHALCON_INIT_VAR(config);
	array_init(config);
	
	phalcon_is_iterable(ini_config, &ah0, &hp0, 0, 0);
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_HKEY(section, ah0, hp0);
		PHALCON_GET_HVALUE(directives);
	
		if (unlikely(Z_TYPE_P(directives) != IS_ARRAY)) {
			Z_ADDREF_P(directives);
			if (phalcon_array_update_zval(&config, section, &directives, 0) != SUCCESS) {
				Z_DELREF_P(directives);
			}
			zend_hash_move_forward_ex(ah0, &hp0);
			continue;
		}
	
		phalcon_is_iterable(directives, &ah1, &hp1, 0, 0);
	
		if (zend_hash_num_elements(ah1) == 0) {
			Z_ADDREF_P(directives);
			phalcon_array_update_zval(&config, section, &directives, 0);
			zend_hash_move_forward_ex(ah0, &hp0);
			continue;
		}
	
		while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
	
			PHALCON_GET_HKEY(key, ah1, hp1);
			PHALCON_GET_HVALUE(value);
	
			if (phalcon_memnstr_str(key, SL("."))) {
				PHALCON_INIT_NVAR(directive_parts);
				phalcon_fast_explode_str(directive_parts, SL("."), key);
				phalcon_config_adapter_ini_update_zval_directive(&config, section, directive_parts, &value, 0 TSRMLS_CC);
			} else {
				phalcon_array_update_multi_2(&config, section, key, &value, 0);
			}
	
			zend_hash_move_forward_ex(ah1, &hp1);
		}
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	/** 
	 * Calls the Phalcon\Config constructor
	 */
	PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Config\\Adapter\\Ini", "__construct", config);
	
	PHALCON_MM_RESTORE();
}
示例#2
0
文件: ini.c 项目: rcpsec/cphalcon
/**
 * Phalcon_Config_Adapter_Ini constructor
 *
 * @param string $filePath
 * @return Phalcon_Config_Adapter_Ini
 *
 */
PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){

	zval *file_path = NULL, *config = NULL, *ini_config = NULL, *directives = NULL;
	zval *section = NULL, *value = NULL, *key = NULL, *directive_parts = NULL;
	zval *a0 = NULL;
	zval *c0 = NULL, *c1 = NULL, *c2 = NULL;
	zval *i0 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL;
	zval *t0 = NULL, *t1 = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	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, "z", &file_path) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_INIT_VAR(a0);
	array_init(a0);
	PHALCON_CPY_WRT(config, a0);
	
	PHALCON_INIT_VAR(c0);
	ZVAL_BOOL(c0, 1);
	
	PHALCON_INIT_VAR(ini_config);
	PHALCON_CALL_FUNC_PARAMS_2(ini_config, "parse_ini_file", file_path, c0);
	if (Z_TYPE_P(ini_config) == IS_BOOL && !Z_BVAL_P(ini_config)) {
		PHALCON_ALLOC_ZVAL_MM(i0);
		object_init_ex(i0, phalcon_config_exception_ce);
		PHALCON_ALLOC_ZVAL_MM(r0);
		PHALCON_ALLOC_ZVAL_MM(r1);
		PHALCON_CALL_FUNC_PARAMS_1(r1, "basename", file_path);
		PHALCON_CONCAT_SVS(r0, "Configuration file ", r1, " can't be loaded");
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r0, PHALCON_CHECK);
		phalcon_throw_exception(i0 TSRMLS_CC);
		return;
	}
	
	if (phalcon_valid_foreach(ini_config TSRMLS_CC)) {
		ah0 = Z_ARRVAL_P(ini_config);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_b840_0:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_b840_0;
		} else {
			PHALCON_INIT_VAR(section);
			PHALCON_GET_FOREACH_KEY(section, ah0, hp0);
		}
		PHALCON_INIT_VAR(directives);
		ZVAL_ZVAL(directives, *hd, 1, 0);
		if (phalcon_valid_foreach(directives TSRMLS_CC)) {
			ah1 = Z_ARRVAL_P(directives);
			zend_hash_internal_pointer_reset_ex(ah1, &hp1);
			fes_b840_1:
			if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
				goto fee_b840_1;
			} else {
				PHALCON_INIT_VAR(key);
				PHALCON_GET_FOREACH_KEY(key, ah1, hp1);
			}
			PHALCON_INIT_VAR(value);
			ZVAL_ZVAL(value, *hd, 1, 0);
			PHALCON_INIT_VAR(c1);
			ZVAL_STRING(c1, ".", 1);
			PHALCON_INIT_VAR(r2);
			phalcon_fast_strpos(r2, key, c1 TSRMLS_CC);
			if (Z_TYPE_P(r2) != IS_BOOL || (Z_TYPE_P(r2) == IS_BOOL && Z_BVAL_P(r2))) {
				PHALCON_INIT_VAR(c2);
				ZVAL_STRING(c2, ".", 1);
				PHALCON_INIT_VAR(r3);
				phalcon_fast_explode(r3, c2, key TSRMLS_CC);
				PHALCON_CPY_WRT(directive_parts, r3);
				if (Z_TYPE_P(config) == IS_ARRAY) {
					PHALCON_INIT_VAR(t0);
					phalcon_array_fetch(&t0, config, section, PHALCON_SILENT TSRMLS_CC);
				}
				if (Z_REFCOUNT_P(t0) > 1) {
					phalcon_array_update(&config, section, &t0, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_CTOR TSRMLS_CC);
				}
				if (Z_TYPE_P(t0) != IS_ARRAY) {
					convert_to_array(t0);
					phalcon_array_update(&config, section, &t0, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
				}
				PHALCON_INIT_VAR(r4);
				phalcon_array_fetch_long(&r4, directive_parts, 0, PHALCON_NOISY TSRMLS_CC);
				if (Z_TYPE_P(t0) == IS_ARRAY) {
					PHALCON_INIT_VAR(t1);
					phalcon_array_fetch(&t1, t0, r4, PHALCON_SILENT TSRMLS_CC);
				}
				if (Z_REFCOUNT_P(t1) > 1) {
					phalcon_array_update(&t0, r4, &t1, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_CTOR TSRMLS_CC);
				}
				if (Z_TYPE_P(t1) != IS_ARRAY) {
					convert_to_array(t1);
					phalcon_array_update(&t0, r4, &t1, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
				}
				
				PHALCON_INIT_VAR(r5);
				phalcon_array_fetch_long(&r5, directive_parts, 1, PHALCON_NOISY TSRMLS_CC);
				phalcon_array_update(&t1, r5, &value, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC);
			} else {
				phalcon_array_update_multi_2(&config, section, key, &value, PHALCON_NO_SEPARATE_THX TSRMLS_CC);
			}
			zend_hash_move_forward_ex(ah1, &hp1);
			goto fes_b840_1;
			fee_b840_1:
			if(0){}
		} else {
			return;
		}
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_b840_0;
		fee_b840_0:
		if(0){}
	} else {
		return;
	}
	PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon_Config_Adapter_Ini", "__construct", config);
	
	PHALCON_MM_RESTORE();
}
示例#3
0
/**
 * Writes meta-data for certain model using a MODEL_* constant
 *
 *<code>
 *	print_r($metaData->writeColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP, array('leName' => 'name')));
 *</code>
 *
 * @param Phalcon\Mvc\ModelInterface $model
 * @param int $index
 * @param mixed $data
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData, writeMetaDataIndex) {

    zval *model, *index, *data, *replace, *table, *schema, *class_name;
    zval *key, *meta_data = NULL, *arr, *value;
    HashTable *ah2;
    HashPosition hp2;
    zval **hd;

    PHALCON_MM_GROW();

    phalcon_fetch_params(1, 4, 0, &model, &index, &data, &replace);

    if (Z_TYPE_P(model) != IS_OBJECT) {
        PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A model instance is required to retrieve the meta-data");
        return;
    }
    if (Z_TYPE_P(index) != IS_LONG) {
        PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Index must be a valid integer constant");
        return;
    }

    if (Z_TYPE_P(data) != IS_ARRAY) {
        if (Z_TYPE_P(data) != IS_STRING) {
            if (Z_TYPE_P(data) != IS_BOOL) {
                PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid data for index");
                return;
            }
        }
    }

    PHALCON_INIT_VAR(table);
    phalcon_call_method(table, model, "getsource");

    PHALCON_INIT_VAR(schema);
    phalcon_call_method(schema, model, "getschema");

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

    /**
     * Unique key for meta-data is created using class-name-schema-table
     */
    PHALCON_INIT_VAR(key);
    PHALCON_CONCAT_VSVV(key, class_name, "-", schema, table);

    PHALCON_OBS_VAR(meta_data);
    phalcon_read_property_this(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC);
    if (!phalcon_array_isset(meta_data, key)) {
        phalcon_call_method_p4_noret(this_ptr, "_initialize", model, key, table, schema);

        PHALCON_OBS_NVAR(meta_data);
        phalcon_read_property_this(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC);
    } else if (!zend_is_true(replace)) {
        PHALCON_OBS_VAR(arr);
        phalcon_array_fetch(&arr, meta_data, key, PH_NOISY);

        PHALCON_OBS_VAR(value);
        phalcon_array_fetch(&value, arr, index, PH_NOISY);

        PHALCON_SEPARATE_PARAM(data);
        phalcon_is_iterable(value, &ah2, &hp2, 0, 0);

        while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) {

            zval key2 = phalcon_get_current_key_w(ah2, &hp2);

            if (!phalcon_array_isset(data, &key2)) {
                phalcon_array_update_zval(&data, &key2, hd, PH_COPY | PH_SEPARATE);
            }

            zend_hash_move_forward_ex(ah2, &hp2);
        }
    }

    phalcon_array_update_multi_2(&meta_data, key, index, &data, 0);
    phalcon_update_property_this(this_ptr, SL("_metaData"), meta_data TSRMLS_CC);

    PHALCON_MM_RESTORE();
}
示例#4
0
文件: gridfs.c 项目: Myleft/cphalcon7
PHP_METHOD(Phalcon_Mvc_Collection_GridFS, remove){

	zval *sha1 = NULL, *md5 = NULL, *source = NULL, *files_source;
	zval *connection = NULL, *mongo_collection = NULL;
	zval *criteria, *operation, *field, *value, *new_object;
	zval *status = NULL, *ok, *exist, *options, *grid_fs = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 2, &sha1, &md5);

	if (!sha1) {
		sha1 = phalcon_read_property(getThis(), SL("sha1"), PH_NOISY);
	}

	if (!md5) {
		md5 = phalcon_read_property(getThis(), SL("md5"), PH_NOISY);
	}

	PHALCON_CALL_METHOD(&source, getThis(), "getsource");

	PHALCON_INIT_VAR(files_source);
	PHALCON_CONCAT_VS(files_source, source, ".files");

	PHALCON_CALL_METHOD(&connection, getThis(), "getconnection");

	PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", files_source);
	if (Z_TYPE_P(mongo_collection) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo collection");
		return;
	}

	PHALCON_INIT_VAR(criteria);
	array_init_size(criteria, 2);

	phalcon_array_update_str(criteria, SL("md5"), md5, PH_COPY);
	phalcon_array_update_str(criteria, SL("sha1"), sha1, PH_COPY);

	PHALCON_INIT_VAR(operation);
	ZVAL_STRING(operation, "$inc");

	PHALCON_INIT_VAR(field);
	ZVAL_STRING(field, "use");

	PHALCON_INIT_VAR(value);
	ZVAL_LONG(value, -1)

	PHALCON_INIT_VAR(new_object);
	array_init_size(new_object, 1);

	phalcon_array_update_multi_2(new_object, operation, field, value, PH_COPY);
	
	PHALCON_CALL_METHOD(&status, mongo_collection, "update", criteria, new_object);

	if (phalcon_array_isset_str_fetch(&ok, status, SL("ok"))) {
		if (zend_is_true(ok)) {
			if (phalcon_array_isset_str_fetch(&exist, status, SL("updatedExisting"))) {
				if (!zend_is_true(exist)) {
					RETURN_MM_FALSE;
				}
			}
		} else {
			RETURN_MM_FALSE;
		}
	}

	PHALCON_CALL_METHOD(&grid_fs, connection, "getgridfs", source);
	if (Z_TYPE_P(grid_fs) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo GridFS");
		return;
	}

	PHALCON_INIT_NVAR(criteria);
	array_init_size(criteria, 3);

	phalcon_array_update_str(criteria, SL("sha1"), sha1, PH_COPY);
	phalcon_array_update_str(criteria, SL("md5"), md5, PH_COPY);

	PHALCON_INIT_NVAR(operation);
	ZVAL_STRING(operation, "$lte");

	PHALCON_INIT_NVAR(value);
	ZVAL_LONG(value, 0)

	phalcon_array_update_multi_2(criteria, field, operation, value, PH_COPY);

	PHALCON_INIT_VAR(options);
	array_init_size(options, 1);

	phalcon_array_update_str_long(options, SL("w"), 0, PH_COPY);

	PHALCON_RETURN_CALL_METHOD(grid_fs, "remove", criteria, options);
	RETURN_MM();
}
示例#5
0
文件: gridfs.c 项目: Myleft/cphalcon7
PHP_METHOD(Phalcon_Mvc_Collection_GridFS, store){

	zval *file, *metadata = NULL, *options = NULL, *isBytes = NULL;
	zval *mongo_id = NULL, *source = NULL, *files_source;
	zval *connection = NULL, *mongo_collection = NULL, *grid_fs = NULL;
	zval *sha1, *md5, *criteria, *operation, *field, *value, *new_object;
	zval *status = NULL, *ok, *exist;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 3, &file, &metadata, &options, &isBytes);

	if (!metadata) {
		PHALCON_INIT_VAR(metadata);
		array_init_size(metadata, 1);
	} else {
		PHALCON_SEPARATE_PARAM(metadata);

		if (Z_TYPE_P(metadata) != IS_ARRAY) {
			PHALCON_INIT_NVAR(metadata);
			array_init_size(metadata, 1);
		}
	}

	if (!options) {
		PHALCON_INIT_NVAR(options);
		array_init_size(options, 1);
	} else {
		PHALCON_SEPARATE_PARAM(options);

		if (Z_TYPE_P(options) != IS_ARRAY) {
			PHALCON_INIT_NVAR(options);
			array_init_size(options, 1);
		}
	}

	if (!isBytes) {
		isBytes = &PHALCON_GLOBAL(z_false);
	}

	phalcon_array_update_str_long(options, SL("w"), 0, 0);

	PHALCON_CALL_SELF(&mongo_id, "getid");

	if (!zend_is_true(mongo_id)) {
		RETURN_MM_FALSE;
	}

	PHALCON_CALL_METHOD(&source, getThis(), "getsource");

	PHALCON_INIT_VAR(files_source);
	PHALCON_CONCAT_VS(files_source, source, ".files");

	PHALCON_CALL_METHOD(&connection, getThis(), "getconnection");

	PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", files_source);
	if (Z_TYPE_P(mongo_collection) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo collection");
		return;
	}

	sha1 = phalcon_read_property(getThis(), SL("sha1"), PH_NOISY);
	md5 = phalcon_read_property(getThis(), SL("md5"), PH_NOISY);

	PHALCON_INIT_VAR(criteria);
	array_init_size(criteria, 3);

	phalcon_array_update_str(criteria, SL("md5"), md5, PH_COPY);
	phalcon_array_update_str(criteria, SL("sha1"), sha1, PH_COPY);

	PHALCON_INIT_VAR(operation);
	ZVAL_STRING(operation, "$gte");

	PHALCON_INIT_VAR(field);
	ZVAL_STRING(field, "use");

	PHALCON_INIT_VAR(value);
	ZVAL_LONG(value, 1)

	phalcon_array_update_multi_2(criteria, field, operation, value, PH_COPY);

	PHALCON_INIT_NVAR(operation);
	ZVAL_STRING(operation, "$inc");

	PHALCON_INIT_VAR(new_object);
	array_init_size(new_object, 1);

	phalcon_array_update_multi_2(new_object, operation, field, value, PH_COPY);
	
	PHALCON_CALL_METHOD(&status, mongo_collection, "update", criteria, new_object);

	if (phalcon_array_isset_str_fetch(&ok, status, SL("ok"))) {
		if (zend_is_true(ok)) {
			if (phalcon_array_isset_str_fetch(&exist, status, SL("updatedExisting"))) {
				if (zend_is_true(exist)) {
					RETURN_MM_TRUE;
				}
			}
		} else {
			RETURN_MM_FALSE;
		}
	}

	PHALCON_CALL_METHOD(&grid_fs, connection, "getgridfs", source);
	if (Z_TYPE_P(grid_fs) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo GridFS");
		return;
	}

	phalcon_array_update_str(metadata, SL("sha1"), sha1, PH_COPY);
	phalcon_array_update_str(metadata, SL("use"), value, PH_COPY);

	if (zend_is_true(isBytes)) {
		PHALCON_CALL_METHOD(&status, grid_fs, "storebytes", file, metadata, options);
	} else {
		PHALCON_CALL_METHOD(&status, grid_fs, "storefile", file, metadata, options);
	}

	if (zend_is_true(status)) {
		RETURN_MM_TRUE;
	}

	RETURN_MM_FALSE;
}
示例#6
0
文件: ini.c 项目: vguardiola/cphalcon
/**
 * Phalcon\Config\Adapter\Ini constructor
 *
 * @param string $filePath
 */
PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct) {

    zval *file_path, *config, *process_sections;
    zval *ini_config, *base_path, *exception_message;
    zval *dot, *directives = NULL, *section = NULL, *value = NULL, *key = NULL, *directive_parts = NULL;
    zval *left_part = NULL, *right_part = NULL;
    HashTable *ah0, *ah1;
    HashPosition hp0, hp1;
    zval **hd;

    PHALCON_MM_GROW();

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

    PHALCON_INIT_VAR(config);
    array_init(config);

    PHALCON_INIT_VAR(process_sections);
    ZVAL_BOOL(process_sections, 1);

    PHALCON_INIT_VAR(ini_config);
    PHALCON_CALL_FUNC_PARAMS_2(ini_config, "parse_ini_file", file_path, process_sections);
    if (PHALCON_IS_FALSE(ini_config)) {
        PHALCON_INIT_VAR(base_path);
        PHALCON_CALL_FUNC_PARAMS_1(base_path, "basename", file_path);

        PHALCON_INIT_VAR(exception_message);
        PHALCON_CONCAT_SVS(exception_message, "Configuration file ", base_path, " can't be loaded");
        PHALCON_THROW_EXCEPTION_ZVAL(phalcon_config_exception_ce, exception_message);
        return;
    }

    PHALCON_INIT_VAR(dot);
    ZVAL_STRING(dot, ".", 1);

    if (!phalcon_is_iterable(ini_config, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
        return;
    }

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

        PHALCON_GET_FOREACH_KEY(section, ah0, hp0);
        PHALCON_GET_FOREACH_VALUE(directives);


        if (!phalcon_is_iterable(directives, &ah1, &hp1, 0, 0 TSRMLS_CC)) {
            return;
        }

        while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {

            PHALCON_GET_FOREACH_KEY(key, ah1, hp1);
            PHALCON_GET_FOREACH_VALUE(value);

            if (phalcon_memnstr_str(key, SL(".") TSRMLS_CC)) {
                PHALCON_INIT_NVAR(directive_parts);
                phalcon_fast_explode(directive_parts, dot, key TSRMLS_CC);

                PHALCON_OBS_NVAR(left_part);
                phalcon_array_fetch_long(&left_part, directive_parts, 0, PH_NOISY_CC);

                PHALCON_OBS_NVAR(right_part);
                phalcon_array_fetch_long(&right_part, directive_parts, 1, PH_NOISY_CC);
                phalcon_array_update_zval_zval_zval_multi_3(&config, section, left_part, right_part, &value, 0 TSRMLS_CC);
            } else {
                phalcon_array_update_multi_2(&config, section, key, &value, 0 TSRMLS_CC);
            }

            zend_hash_move_forward_ex(ah1, &hp1);
        }


        zend_hash_move_forward_ex(ah0, &hp0);
    }

    PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Config\\Adapter\\Ini", "__construct", config);

    PHALCON_MM_RESTORE();
}
示例#7
0
文件: memory.c 项目: bicouy0/cphalcon
/**
 * Checks if a role has access to a resource
 *
 * @param string $roleName
 * @param string $resourceName
 * @param string $access
 * @param string $action
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, _allowOrDeny){

	zval *role_name, *resource_name, *access, *action;
	zval *roles_names, *exception_message = NULL, *resources_names;
	zval *default_access, *access_list, *access_name = NULL;
	zval *empty_arr = NULL, *_access = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL;
	zval *t7 = NULL, *t8 = NULL, *t9 = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzz", &role_name, &resource_name, &access, &action) == FAILURE) {
		RETURN_MM_NULL();
	}

	PHALCON_OBS_VAR(roles_names);
	phalcon_read_property(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC);
	if (!phalcon_array_isset(roles_names, role_name)) {
		PHALCON_INIT_VAR(exception_message);
		PHALCON_CONCAT_SVS(exception_message, "Role \"", role_name, "\" does not exist in ACL");
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
		return;
	}
	
	PHALCON_OBS_VAR(resources_names);
	phalcon_read_property(&resources_names, this_ptr, SL("_resourcesNames"), PH_NOISY_CC);
	if (!phalcon_array_isset(resources_names, resource_name)) {
		PHALCON_INIT_NVAR(exception_message);
		PHALCON_CONCAT_SVS(exception_message, "Resource \"", resource_name, "\" does not exist in ACL");
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
		return;
	}
	
	PHALCON_OBS_VAR(default_access);
	phalcon_read_property(&default_access, this_ptr, SL("_defaultAccess"), PH_NOISY_CC);
	if (Z_TYPE_P(access) == IS_ARRAY) { 
	
		PHALCON_OBS_VAR(access_list);
		phalcon_read_property(&access_list, this_ptr, SL("_accessList"), PH_NOISY_CC);
	
		if (!phalcon_is_iterable(access, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
			return;
		}
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_FOREACH_VALUE(access_name);
	
			PHALCON_OBS_NVAR(r0);
			phalcon_array_fetch(&r0, access_list, resource_name, PH_NOISY_CC);
			if (!phalcon_array_isset(r0, access_name)) {
				PHALCON_INIT_NVAR(exception_message);
				PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access_name, "' does not exist in resource '", resource_name, "' in ACL");
				PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
				return;
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	
		if (!phalcon_is_iterable(access, &ah1, &hp1, 0, 0 TSRMLS_CC)) {
			return;
		}
	
		while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
	
			PHALCON_GET_FOREACH_VALUE(access_name);
	
			PHALCON_OBS_NVAR(t0);
			phalcon_read_property(&t0, this_ptr, SL("_access"), PH_NOISY_CC);
			PHALCON_OBS_NVAR(r1);
			phalcon_array_fetch(&r1, t0, role_name, PH_NOISY_CC);
			if (!phalcon_array_isset(r1, resource_name)) {
				PHALCON_INIT_NVAR(empty_arr);
				array_init(empty_arr);
	
				PHALCON_OBS_NVAR(_access);
				phalcon_read_property(&_access, this_ptr, SL("_access"), PH_NOISY_CC);
				phalcon_array_update_multi_2(&_access, role_name, resource_name, &empty_arr, 0 TSRMLS_CC);
				phalcon_update_property_zval(this_ptr, SL("_access"), _access TSRMLS_CC);
			}
	
			PHALCON_OBS_NVAR(t1);
			phalcon_read_property(&t1, this_ptr, SL("_access"), PH_NOISY_CC);
			phalcon_array_update_zval_zval_zval_multi_3(&t1, role_name, resource_name, access_name, &action, 0 TSRMLS_CC);
	
			PHALCON_OBS_NVAR(t2);
			phalcon_read_property(&t2, this_ptr, SL("_access"), PH_NOISY_CC);
	
			PHALCON_OBS_NVAR(r2);
			phalcon_array_fetch(&r2, t2, role_name, PH_NOISY_CC);
	
			PHALCON_OBS_NVAR(r3);
			phalcon_array_fetch(&r3, r2, resource_name, PH_NOISY_CC);
			if (!phalcon_array_isset_string(r3, SS("*"))) {
				PHALCON_OBS_NVAR(t3);
				phalcon_read_property(&t3, this_ptr, SL("_access"), PH_NOISY_CC);
				phalcon_array_update_string_zval_zval_multi_3(&t3, role_name, resource_name, SL("*"), &default_access, 0 TSRMLS_CC);
			}
	
			zend_hash_move_forward_ex(ah1, &hp1);
		}
	
	} else {
		if (!PHALCON_IS_STRING(access, "*")) {
	
			PHALCON_OBS_VAR(t4);
			phalcon_read_property(&t4, this_ptr, SL("_accessList"), PH_NOISY_CC);
			PHALCON_OBS_VAR(r4);
			phalcon_array_fetch(&r4, t4, resource_name, PH_NOISY_CC);
			if (!phalcon_array_isset(r4, access)) {
				PHALCON_INIT_NVAR(exception_message);
				PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access, "' does not exist in resource '", resource_name, "' in ACL");
				PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
				return;
			}
		}
	
		PHALCON_OBS_VAR(t5);
		phalcon_read_property(&t5, this_ptr, SL("_access"), PH_NOISY_CC);
	
		PHALCON_OBS_VAR(r5);
		phalcon_array_fetch(&r5, t5, role_name, PH_NOISY_CC);
		if (!phalcon_array_isset(r5, resource_name)) {
			PHALCON_INIT_NVAR(empty_arr);
			array_init(empty_arr);
	
			PHALCON_OBS_VAR(t6);
			phalcon_read_property(&t6, this_ptr, SL("_access"), PH_NOISY_CC);
			phalcon_array_update_multi_2(&t6, role_name, resource_name, &empty_arr, 0 TSRMLS_CC);
			phalcon_update_property_zval(this_ptr, SL("_access"), t6 TSRMLS_CC);
		}
	
		PHALCON_OBS_VAR(t7);
		phalcon_read_property(&t7, this_ptr, SL("_access"), PH_NOISY_CC);
	
		PHALCON_OBS_VAR(r6);
		phalcon_array_fetch(&r6, t7, role_name, PH_NOISY_CC);
	
		PHALCON_OBS_VAR(r7);
		phalcon_array_fetch(&r7, r6, resource_name, PH_NOISY_CC);
		if (!phalcon_array_isset_string(r7, SS("*"))) {
			PHALCON_OBS_VAR(t8);
			phalcon_read_property(&t8, this_ptr, SL("_access"), PH_NOISY_CC);
			phalcon_array_update_string_zval_zval_multi_3(&t8, role_name, resource_name, SL("*"), &default_access, 0 TSRMLS_CC);
		}
	
		PHALCON_OBS_VAR(t9);
		phalcon_read_property(&t9, this_ptr, SL("_access"), PH_NOISY_CC);
		phalcon_array_update_zval_zval_zval_multi_3(&t9, role_name, resource_name, access, &action, 0 TSRMLS_CC);
	}
	
	PHALCON_CALL_METHOD_NORETURN(this_ptr, "_rebuildaccesslist");
	
	PHALCON_MM_RESTORE();
}
示例#8
0
文件: memory.c 项目: bicouy0/cphalcon
/**
 * Adds access to resources
 *
 * @param string $resourceName
 * @param mixed $accessList
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess){

	zval *resource_name, *access_list, *resources_names;
	zval *exception_message, *access_name = NULL, *internal_access_list = NULL;
	zval *_accessList = NULL;
	zval *r0 = NULL, *r1 = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &resource_name, &access_list) == FAILURE) {
		RETURN_MM_NULL();
	}

	PHALCON_OBS_VAR(resources_names);
	phalcon_read_property(&resources_names, this_ptr, SL("_resourcesNames"), PH_NOISY_CC);
	if (!phalcon_array_isset(resources_names, resource_name)) {
		PHALCON_INIT_VAR(exception_message);
		PHALCON_CONCAT_SVS(exception_message, "Resource '", resource_name, "' does not exist in ACL");
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
		return;
	}
	
	if (Z_TYPE_P(access_list) == IS_ARRAY) { 
	
		if (!phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
			return;
		}
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_FOREACH_VALUE(access_name);
	
			PHALCON_OBS_NVAR(internal_access_list);
			phalcon_read_property(&internal_access_list, this_ptr, SL("_accessList"), PH_NOISY_CC);
	
			PHALCON_OBS_NVAR(r0);
			phalcon_array_fetch(&r0, internal_access_list, resource_name, PH_NOISY_CC);
			if (!phalcon_array_isset(r0, access_name)) {
				PHALCON_OBS_NVAR(_accessList);
				phalcon_read_property(&_accessList, this_ptr, SL("_accessList"), PH_NOISY_CC);
				PHALCON_INIT_NVAR(t0);
				ZVAL_LONG(t0, 1);
				phalcon_array_update_multi_2(&_accessList, resource_name, access_name, &t0, 0 TSRMLS_CC);
				phalcon_update_property_zval(this_ptr, SL("_accessList"), _accessList TSRMLS_CC);
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	} else {
		if (Z_TYPE_P(access_list) == IS_STRING) {
	
			PHALCON_OBS_VAR(t1);
			phalcon_read_property(&t1, this_ptr, SL("_accessList"), PH_NOISY_CC);
			PHALCON_OBS_VAR(r1);
			phalcon_array_fetch(&r1, t1, resource_name, PH_NOISY_CC);
			if (!phalcon_array_isset(r1, access_list)) {
				PHALCON_OBS_VAR(t2);
				phalcon_read_property(&t2, this_ptr, SL("_accessList"), PH_NOISY_CC);
				PHALCON_INIT_VAR(t3);
				ZVAL_LONG(t3, 1);
				phalcon_array_update_multi_2(&t2, resource_name, access_list, &t3, 0 TSRMLS_CC);
				phalcon_update_property_zval(this_ptr, SL("_accessList"), t2 TSRMLS_CC);
			}
		}
	}
	
	RETURN_MM_TRUE;
}