Пример #1
0
/**
 * Returns the paths using positions as keys and names as values
 *
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Router_Route, getReversedPaths){

	zval *paths, *position = NULL, *path = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	PHALCON_OBS_VAR(paths);
	phalcon_read_property_this(&paths, this_ptr, SL("_paths"), PH_NOISY TSRMLS_CC);
	
	phalcon_is_iterable(paths, &ah0, &hp0, 0, 0);

	array_init_size(return_value, zend_hash_num_elements(ah0));

	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_HKEY(path, ah0, hp0);
		PHALCON_GET_HVALUE(position);
	
		phalcon_array_update_zval(&return_value, position, path, PH_COPY);
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	RETURN_MM();
}
Пример #2
0
/**
 * Removes an access from a resource
 *
 * @param string $resourceName
 * @param mixed $accessList
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, dropResourceAccess){

	zval *resource_name, *access_list, *access_name = NULL;
	zval *access_key = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &resource_name, &access_list);
	
	if (Z_TYPE_P(access_list) == IS_ARRAY) { 
	
		phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HVALUE(access_name);
	
			PHALCON_INIT_NVAR(access_key);
			PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name);
			phalcon_unset_property_array(this_ptr, SL("_accessList"), access_key TSRMLS_CC);
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	} else {
		PHALCON_INIT_NVAR(access_key);
		PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name);
		phalcon_unset_property_array(this_ptr, SL("_accessList"), access_key TSRMLS_CC);
	}
	
	PHALCON_MM_RESTORE();
}
Пример #3
0
/**
 * Phalcon\Translate\Adapter\Gettext constructor
 *
 * @param array $options
 * @throws \Phalcon\Translate\Exception
 */
PHP_METHOD(Phalcon_Translate_Adapter_Gettext, __construct){

	zval *options, *locale, *default_domain, *directory, *setting, *key = NULL, *value = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &options);
	
	if (Z_TYPE_P(options) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STRW(phalcon_translate_exception_ce, "Invalid options");
		return;
	}

	if (!phalcon_array_isset_string_fetch(&locale, options, SS("locale"))) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_translate_exception_ce, "Parameter \"locale\" is required");
		return;
	}

	if (!phalcon_array_isset_string_fetch(&default_domain, options, SS("defaultDomain"))) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_translate_exception_ce, "Parameter \"defaultDomain\" is required");
		return;
	}

	if (!phalcon_array_isset_string_fetch(&directory, options, SS("directory"))) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_translate_exception_ce, "Parameter \"directory\" is required");
		return;
	}

	phalcon_update_property_this(this_ptr, SL("_locale"), locale TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_defaultDomain"), default_domain TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_directory"), directory TSRMLS_CC);

	PHALCON_INIT_VAR(setting);
	PHALCON_CONCAT_SV(setting, "LC_ALL=", locale);

	PHALCON_CALL_FUNCTION(NULL, "putenv", setting);

	setlocale(LC_ALL, Z_STRVAL_P(locale));
	
	if (Z_TYPE_P(directory) == IS_ARRAY) {
		phalcon_is_iterable(directory, &ah0, &hp0, 0, 0);
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
			PHALCON_GET_HKEY(key, ah0, hp0);
			PHALCON_GET_HVALUE(value);

			bindtextdomain(Z_STRVAL_P(key), Z_STRVAL_P(value));

			zend_hash_move_forward_ex(ah0, &hp0);
		}
	} else {
		bindtextdomain(Z_STRVAL_P(default_domain), Z_STRVAL_P(directory));
	}

	textdomain(Z_STRVAL_P(default_domain));

	PHALCON_MM_RESTORE();
}
Пример #4
0
/**
 * Returns an HTML string of debugging information about any number of
 * variables, each wrapped in a "pre" tag.
 *
 * <code>
 *    $foo = "string";
 *    $bar = ["key" => "value"];
 *    $baz = new stdClass();
 *    echo (new \Phalcon\Debug\Dump())->variables($foo, $bar, $baz);
 *</code>
 *
 * @param mixed variable
 * @param ...
 */
PHP_METHOD(Phalcon_Debug_Dump, variables){

	zval *arg_list = NULL, *name = NULL, *variable = NULL, *output = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	PHALCON_CALL_FUNCTION(&arg_list, "func_get_args");

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

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

		PHALCON_GET_HKEY(name, ah0, hp0);
		PHALCON_GET_HVALUE(variable);

		PHALCON_CALL_SELF(&output, "variable", variable);
		PHALCON_SCONCAT(return_value, output);

		zend_hash_move_forward_ex(ah0, &hp0);
	}

	RETURN_MM();
}
Пример #5
0
/**
 * Sends a message to each registered logger
 *
 * @param string $message
 * @param int $type
 */
PHP_METHOD(Phalcon_Logger_Multiple, log){

	zval *message, *type = NULL, *loggers, *logger = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &message, &type);
	
	if (!type) {
		PHALCON_INIT_VAR(type);
		ZVAL_LONG(type, 7);
	}
	
	PHALCON_OBS_VAR(loggers);
	phalcon_read_property_this(&loggers, this_ptr, SL("_loggers"), PH_NOISY_CC);
	if (Z_TYPE_P(loggers) == IS_ARRAY) { 
	
		phalcon_is_iterable(loggers, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HVALUE(logger);
	
			phalcon_call_method_p2_noret(logger, "log", message, type);
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	}
	
	PHALCON_MM_RESTORE();
}
Пример #6
0
/**
 * Remove all the transactions from the manager
 *
 */
PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, collectTransactions){

	zval *transactions, *managed_transaction = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	PHALCON_OBS_VAR(transactions);
	phalcon_read_property_this(&transactions, this_ptr, SL("_transactions"), PH_NOISY_CC);
	if (phalcon_fast_count_ev(transactions TSRMLS_CC)) {
	
		phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HVALUE(managed_transaction);
	
			phalcon_property_decr(this_ptr, SL("_number") TSRMLS_CC);
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
		phalcon_update_property_null(this_ptr, SL("_transactions") TSRMLS_CC);
	}
	
	PHALCON_MM_RESTORE();
}
Пример #7
0
/**
 * Deny access to a role on a resource
 *
 * You can use '*' as wildcard
 *
 * Example:
 * <code>
 * //Deny access to guests to search on customers
 * $acl->deny('guests', 'customers', 'search');
 *
 * //Deny access to guests to search or create on customers
 * $acl->deny('guests', 'customers', array('search', 'create'));
 *
 * //Deny access to any role to browse on products
 * $acl->deny('*', 'products', 'browse');
 *
 * //Deny access to any role to browse on any resource
 * $acl->deny('*', '*', 'browse');
 * </code>
 *
 * @param string $roleName
 * @param string $resourceName
 * @param mixed $access
 * @return boolean
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, deny){

	zval *role_name, *resource_name, *access, *action, *roles_names;
	zval *key = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 3, 0, &role_name, &resource_name, &access);
	
	PHALCON_INIT_VAR(action);
	ZVAL_LONG(action, 0);

	if (!PHALCON_IS_STRING(role_name, "*")) {
		PHALCON_RETURN_CALL_METHOD(this_ptr, "_allowordeny", role_name, resource_name, access, action);
	} else {
		PHALCON_OBS_VAR(roles_names);
		phalcon_read_property_this(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY TSRMLS_CC);

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

			PHALCON_CALL_METHOD(NULL, this_ptr, "_allowordeny", key, resource_name, access, action);
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	}

	RETURN_MM();
}
Пример #8
0
/**
 * Returns the paths using positions as keys and names as values
 *
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Router_Route, getReversedPaths){

	zval *reversed, *paths, *position = NULL, *path = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	PHALCON_INIT_VAR(reversed);
	array_init(reversed);
	
	PHALCON_OBS_VAR(paths);
	phalcon_read_property_this(&paths, this_ptr, SL("_paths"), PH_NOISY_CC);
	
	phalcon_is_iterable(paths, &ah0, &hp0, 0, 0);
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_HKEY(path, ah0, hp0);
		PHALCON_GET_HVALUE(position);
	
		phalcon_array_update_zval(&reversed, position, &path, PH_COPY | PH_SEPARATE);
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	RETURN_CTOR(reversed);
}
Пример #9
0
/**
 * Restore a Phalcon\Http\Response\Headers object
 *
 * @param array $data
 * @return Phalcon\Http\Response\Headers
 */
PHP_METHOD(Phalcon_Http_Response_Headers, __set_state){

	zval *data, *headers, *data_headers, *value = NULL, *key = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &data);
	
	PHALCON_INIT_VAR(headers);
	object_init_ex(headers, phalcon_http_response_headers_ce);
	if (phalcon_array_isset_string(data, SS("_headers"))) {
	
		PHALCON_OBS_VAR(data_headers);
		phalcon_array_fetch_string(&data_headers, data, SL("_headers"), PH_NOISY);
	
		phalcon_is_iterable(data_headers, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HKEY(key, ah0, hp0);
			PHALCON_GET_HVALUE(value);
	
			phalcon_call_method_p2_noret(headers, "set", key, value);
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	}
	
	RETURN_CTOR(headers);
}
Пример #10
0
/**
 * Prints the messages in the session flasher
 *
 * @param string $type
 * @param boolean $remove
 */
PHP_METHOD(Phalcon_Flash_Session, output){

	zval *remove = NULL, *messages = NULL, *message = NULL, *type = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &remove);
	
	if (!remove) {
		remove = PHALCON_GLOBAL(z_true);
	}
	
	PHALCON_CALL_METHOD(&messages, this_ptr, "_getsessionmessages", remove);
	if (Z_TYPE_P(messages) == IS_ARRAY) { 
	
		phalcon_is_iterable(messages, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HKEY(type, ah0, hp0);
			PHALCON_GET_HVALUE(message);
	
			PHALCON_CALL_METHOD(NULL, this_ptr, "outputmessage", type, message);
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	}
	
	PHALCON_MM_RESTORE();
}
Пример #11
0
/**
 * Sets a global formatter
 *
 * @param Phalcon\Logger\FormatterInterface $formatter
 */
PHP_METHOD(Phalcon_Logger_Multiple, setFormatter){

	zval *formatter, *loggers, *logger = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &formatter);
	
	PHALCON_OBS_VAR(loggers);
	phalcon_read_property_this(&loggers, this_ptr, SL("_loggers"), PH_NOISY_CC);
	if (Z_TYPE_P(loggers) == IS_ARRAY) { 
	
		phalcon_is_iterable(loggers, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HVALUE(logger);
	
			phalcon_call_method_p1_noret(logger, "setformatter", formatter);
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	}
	
	phalcon_update_property_this(this_ptr, SL("_formatter"), formatter TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Пример #12
0
/**
 * Gets a list of columns with escaped identifiers
 *
 *<code>
 * echo $dialect->getColumnList(array('column1', 'column'));
 *</code>
 *
 * @param array $columnList
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect, getColumnList){

	zval *column_list, *str_list, *escape_char, *column = NULL;
	zval *column_quoted = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &column_list);
	
	PHALCON_INIT_VAR(str_list);
	array_init(str_list);
	
	PHALCON_OBS_VAR(escape_char);
	phalcon_read_property_this(&escape_char, this_ptr, SL("_escapeChar"), PH_NOISY_CC);
	
	phalcon_is_iterable(column_list, &ah0, &hp0, 0, 0);
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_HVALUE(column);
	
		PHALCON_INIT_NVAR(column_quoted);
		PHALCON_CONCAT_VVV(column_quoted, escape_char, column, escape_char);
		phalcon_array_append(&str_list, column_quoted, PH_SEPARATE);
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	phalcon_fast_join_str(return_value, SL(", "), str_list TSRMLS_CC);
	RETURN_MM();
}
Пример #13
0
/**
 * Renders a view using the template engine
 *
 * @param string $path
 * @param array $params
 * @param boolean $mustClean
 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Php, render) {

    zval *path, *params, *must_clean = NULL, *value = NULL, *key = NULL, *contents;
    zval *view;
    HashTable *ah0;
    HashPosition hp0;
    zval **hd;

    PHALCON_MM_GROW();

    phalcon_fetch_params(1, 2, 1, &path, &params, &must_clean);

    if (!must_clean) {
        PHALCON_INIT_VAR(must_clean);
        ZVAL_BOOL(must_clean, 0);
    }

    if (PHALCON_IS_TRUE(must_clean)) {
        phalcon_ob_clean(TSRMLS_C);
    }

    /**
     * Create the variables in local symbol table
     */
    if (Z_TYPE_P(params) == IS_ARRAY) {

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

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

            PHALCON_GET_HKEY(key, ah0, hp0);
            PHALCON_GET_HVALUE(value);

            if (phalcon_set_symbol(key, value TSRMLS_CC) == FAILURE) {
                return;
            }

            zend_hash_move_forward_ex(ah0, &hp0);
        }

    }

    /**
     * Require the file
     */
    if (phalcon_require(path TSRMLS_CC) == FAILURE) {
        return;
    }
    if (PHALCON_IS_TRUE(must_clean)) {
        PHALCON_INIT_VAR(contents);
        phalcon_ob_get_contents(contents TSRMLS_CC);

        PHALCON_OBS_VAR(view);
        phalcon_read_property_this(&view, this_ptr, SL("_view"), PH_NOISY_CC);
        phalcon_call_method_p1_noret(view, "setcontent", contents);
    }

    PHALCON_MM_RESTORE();
}
Пример #14
0
/**
 * 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, *exists, *internal_access_list;
	zval *access_name = NULL, *access_key = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &resource_name, &access_list);
	
	PHALCON_OBS_VAR(resources_names);
	phalcon_read_property_this(&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;
	}
	
	PHALCON_INIT_VAR(exists);
	ZVAL_BOOL(exists, 1);
	
	PHALCON_OBS_VAR(internal_access_list);
	phalcon_read_property_this(&internal_access_list, this_ptr, SL("_accessList"), PH_NOISY_CC);
	if (Z_TYPE_P(access_list) == IS_ARRAY) { 
	
		phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HVALUE(access_name);
	
			PHALCON_INIT_NVAR(access_key);
			PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name);
			if (!phalcon_array_isset(internal_access_list, access_key)) {
				phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, exists TSRMLS_CC);
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	} else {
		if (Z_TYPE_P(access_list) == IS_STRING) {
	
			PHALCON_INIT_NVAR(access_key);
			PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_list);
			if (!phalcon_array_isset(internal_access_list, access_key)) {
				phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, exists TSRMLS_CC);
			}
		}
	}
	
	RETURN_MM_TRUE;
}
Пример #15
0
/**
 * Returns the annotations found in the properties' docblocks
 *
 * @return Phalcon\Annotations\Collection[]
 */
PHP_METHOD(Phalcon_Annotations_Reflection, getPropertiesAnnotations){

	zval *annotations, *reflection_data, *reflection_properties;
	zval *collections, *reflection_property = NULL, *property = NULL;
	zval *collection = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	PHALCON_OBS_VAR(annotations);
	phalcon_read_property(&annotations, this_ptr, SL("_propertyAnnotations"), PH_NOISY_CC);
	if (Z_TYPE_P(annotations) != IS_OBJECT) {
	
		PHALCON_OBS_VAR(reflection_data);
		phalcon_read_property(&reflection_data, this_ptr, SL("_reflectionData"), PH_NOISY_CC);
		if (phalcon_array_isset_string(reflection_data, SS("properties"))) {
	
			PHALCON_OBS_VAR(reflection_properties);
			phalcon_array_fetch_string(&reflection_properties, reflection_data, SL("properties"), PH_NOISY_CC);
			if (phalcon_fast_count_ev(reflection_properties TSRMLS_CC)) {
	
				PHALCON_INIT_VAR(collections);
				array_init(collections);
	
				if (!phalcon_is_iterable(reflection_properties, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
					return;
				}
	
				while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
					PHALCON_GET_FOREACH_KEY(property, ah0, hp0);
					PHALCON_GET_FOREACH_VALUE(reflection_property);
	
					PHALCON_INIT_NVAR(collection);
					object_init_ex(collection, phalcon_annotations_collection_ce);
					PHALCON_CALL_METHOD_PARAMS_1_NORETURN(collection, "__construct", reflection_property);
	
					phalcon_array_update_zval(&collections, property, &collection, PH_COPY | PH_SEPARATE TSRMLS_CC);
	
					zend_hash_move_forward_ex(ah0, &hp0);
				}
	
				phalcon_update_property_zval(this_ptr, SL("_propertyAnnotations"), collections TSRMLS_CC);
	
				RETURN_CTOR(collections);
			}
		}
	
		phalcon_update_property_bool(this_ptr, SL("_propertyAnnotations"), 0 TSRMLS_CC);
		RETURN_MM_FALSE;
	}
	
	
	RETURN_CCTOR(annotations);
}
Пример #16
0
/**
 * 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, *ordered_column_map = NULL;
    zval *reversed_column_map = NULL, *user_column_map;
    zval *user_name = NULL, *name = NULL, *model_column_map;
    HashTable *ah0;
    HashPosition hp0;
    zval **hd;

    PHALCON_MM_GROW();

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

    PHALCON_INIT_VAR(ordered_column_map);

    PHALCON_INIT_VAR(reversed_column_map);

    /**
     * Check for a columnMap() method on the model
     */
    if (phalcon_method_exists_ex(model, SS("columnmap") TSRMLS_CC) == SUCCESS) {

        PHALCON_INIT_VAR(user_column_map);
        phalcon_call_method(user_column_map, model, "columnmap");
        if (Z_TYPE_P(user_column_map) != IS_ARRAY) {
            PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "columnMap() not returned an array");
            return;
        }

        array_init(reversed_column_map);
        PHALCON_CPY_WRT(ordered_column_map, user_column_map);

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

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

            PHALCON_GET_HKEY(name, ah0, hp0);
            PHALCON_GET_HVALUE(user_name);

            phalcon_array_update_zval(&reversed_column_map, user_name, &name, PH_COPY | PH_SEPARATE);

            zend_hash_move_forward_ex(ah0, &hp0);
        }

    }

    /**
     * Store the column map
     */
    PHALCON_INIT_VAR(model_column_map);
    array_init(model_column_map);
    phalcon_array_update_long(&model_column_map, 0, &ordered_column_map, PH_COPY | PH_SEPARATE);
    phalcon_array_update_long(&model_column_map, 1, &reversed_column_map, PH_COPY | PH_SEPARATE);

    RETURN_CTOR(model_column_map);
}
Пример #17
0
/**
 * Renders a view using the template engine
 *
 * @param string $path
 * @param array $params
 * @param boolean $mustClean
 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Php, render){

	zval *path, *params, *must_clean = NULL, *value = NULL, *key = NULL, *contents;
	zval *view;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &path, &params, &must_clean) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (!must_clean) {
		PHALCON_INIT_VAR(must_clean);
		ZVAL_BOOL(must_clean, 0);
	}
	
	if (PHALCON_IS_TRUE(must_clean)) {
		PHALCON_CALL_FUNC_NORETURN("ob_clean");
	}
	if (Z_TYPE_P(params) == IS_ARRAY) { 
	
		if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
			return;
		}
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_FOREACH_KEY(key, ah0, hp0);
			PHALCON_GET_FOREACH_VALUE(value);
	
			if (phalcon_set_symbol(key, value TSRMLS_CC) == FAILURE){
				return;
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	}
	
	if (phalcon_require(path TSRMLS_CC) == FAILURE) {
		return;
	}
	if (PHALCON_IS_TRUE(must_clean)) {
		PHALCON_INIT_VAR(contents);
		PHALCON_CALL_FUNC(contents, "ob_get_contents");
	
		PHALCON_OBS_VAR(view);
		phalcon_read_property(&view, this_ptr, SL("_view"), PH_NOISY_CC);
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(view, "setcontent", contents);
	}
	
	PHALCON_MM_RESTORE();
}
Пример #18
0
/**
 * Returns the annotations found in a specific property
 *
 * @param string $className
 * @param string $propertyName
 * @return Phalcon\Annotations\Collection
 */
PHP_METHOD(Phalcon_Annotations_Adapter, getProperty){

	zval *class_name, *property_name, *class_annotations;
	zval *properties, *property = NULL, *name = NULL, *collection;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &class_name, &property_name);
	
	/** 
	 * Get the full annotations from the class
	 */
	PHALCON_INIT_VAR(class_annotations);
	PHALCON_CALL_METHOD_PARAMS_1(class_annotations, this_ptr, "get", class_name);
	
	/** 
	 * A valid annotations reflection is an object
	 */
	if (Z_TYPE_P(class_annotations) == IS_OBJECT) {
	
		PHALCON_INIT_VAR(properties);
		PHALCON_CALL_METHOD(properties, class_annotations, "getpropertyannotations");
		if (Z_TYPE_P(properties) == IS_ARRAY) { 
	
			if (!phalcon_is_iterable(properties, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
				return;
			}
	
			while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
				PHALCON_GET_FOREACH_KEY(name, ah0, hp0);
				PHALCON_GET_FOREACH_VALUE(property);
	
				if (PHALCON_IS_EQUAL(name, property_name)) {
					RETURN_CCTOR(property);
				}
	
				zend_hash_move_forward_ex(ah0, &hp0);
			}
	
		}
	}
	
	/** 
	 * Returns a collection anyways
	 */
	PHALCON_INIT_VAR(collection);
	object_init_ex(collection, phalcon_annotations_collection_ce);
	PHALCON_CALL_METHOD_NORETURN(collection, "__construct");
	
	
	RETURN_CTOR(collection);
}
Пример #19
0
/**
 * Concatenates strings using the separator only once without duplication in places concatenation
 *
 * <code>
 *    $str = Phalcon\Text::concat("/", "/tmp/", "/folder_1/", "/folder_2", "folder_3/");
 *    echo $str; // /tmp/folder_1/folder_2/folder_3/
 * </code>
 *
 * @param string separator
 * @param string a
 * @param string b
 * @param string ...N
 */
PHP_METHOD(Phalcon_Text, concat){

	zval *separator, *a, *b;
	zval *arg_num = NULL, *arg_list = NULL, *offset, *args = NULL;
	zval *c = NULL, *a_trimmed = NULL, *b_trimmed = NULL, *c_trimmed = NULL, *tmp = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 3, 0, &separator, &a, &b);

	PHALCON_CALL_FUNCTION(&arg_num, "func_num_args");

	if (Z_LVAL_P(arg_num) > 3) {
		PHALCON_CALL_FUNCTION(&arg_list, "func_get_args");

		PHALCON_INIT_VAR(offset);
		ZVAL_LONG(offset, 3);

		PHALCON_CALL_FUNCTION(&args, "array_slice", arg_list, offset);

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

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

			PHALCON_GET_HVALUE(c);

			PHALCON_INIT_NVAR(b_trimmed);
			phalcon_fast_trim(b_trimmed, b, separator, PHALCON_TRIM_RIGHT TSRMLS_CC);

			PHALCON_INIT_NVAR(c_trimmed);
			phalcon_fast_trim(c_trimmed, c, separator, PHALCON_TRIM_LEFT TSRMLS_CC);

			PHALCON_INIT_NVAR(tmp);
			PHALCON_CONCAT_VVV(tmp, b_trimmed, separator, c_trimmed)

			PHALCON_CPY_WRT(b, tmp);

			zend_hash_move_forward_ex(ah0, &hp0);
		}
	}

	PHALCON_INIT_NVAR(a_trimmed);
	phalcon_fast_trim(a_trimmed, a, separator, PHALCON_TRIM_RIGHT TSRMLS_CC);

	PHALCON_INIT_NVAR(b_trimmed);
	phalcon_fast_trim(b_trimmed, b, separator, PHALCON_TRIM_LEFT TSRMLS_CC);

	PHALCON_INIT_NVAR(tmp);
	PHALCON_CONCAT_VVV(tmp, a_trimmed, separator, b_trimmed)

	RETURN_CTOR(tmp);
}
Пример #20
0
/**
 * Phalcon\Annotations\Annotation constructor
 *
 * @param array $reflectionData
 */
PHP_METHOD(Phalcon_Annotations_Annotation, __construct){

	zval *reflection_data, *name = NULL, *arguments, *expr_arguments;
	zval *argument = NULL, *expr = NULL, *resolved_argument = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &reflection_data);
	
	if (Z_TYPE_P(reflection_data) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Reflection data must be an array");
		return;
	}
	
	PHALCON_OBS_VAR(name);
	phalcon_array_fetch_string(&name, reflection_data, SL("name"), PH_NOISY);
	phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC);
	
	/** 
	 * Process annotation arguments
	 */
	if (phalcon_array_isset_string_fetch(&expr_arguments, reflection_data, SS("arguments"))) {
	
		phalcon_is_iterable(expr_arguments, &ah0, &hp0, 0, 0);
	
		PHALCON_INIT_VAR(arguments);
		array_init_size(arguments, zend_hash_num_elements(ah0));

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

			PHALCON_GET_HVALUE(argument);
	
			PHALCON_OBS_NVAR(expr);
			phalcon_array_fetch_string(&expr, argument, SL("expr"), PH_NOISY);
	
			PHALCON_CALL_METHOD(&resolved_argument, this_ptr, "getexpression", expr);
			if (phalcon_array_isset_string_fetch(&n, argument, SS("name"))) {
				phalcon_array_update_zval(&arguments, n, resolved_argument, PH_COPY);
			} else {
				phalcon_array_append(&arguments, resolved_argument, 0);
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
		phalcon_update_property_this(this_ptr, SL("_arguments"), arguments TSRMLS_CC);
		phalcon_update_property_this(this_ptr, SL("_exprArguments"), expr_arguments TSRMLS_CC);
	}
	
	PHALCON_MM_RESTORE();
}
Пример #21
0
/**
 * Returns the messages generated in the validation
 *
 * @param boolean $byItemName
 * @return array
 */
PHP_METHOD(Phalcon_Forms_Form, getMessages){

	zval *by_item_name = NULL, *messages, *group = NULL, *element_messages = NULL;
	zval *element = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

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

	if (!by_item_name) {
		PHALCON_INIT_VAR(by_item_name);
		ZVAL_BOOL(by_item_name, 0);
	}
	
	PHALCON_OBS_VAR(messages);
	phalcon_read_property(&messages, this_ptr, SL("_messages"), PH_NOISY_CC);
	if (zend_is_true(by_item_name)) {
		if (Z_TYPE_P(messages) != IS_ARRAY) { 
			PHALCON_INIT_VAR(group);
			object_init_ex(group, phalcon_validation_message_group_ce);
			PHALCON_CALL_METHOD_NORETURN(group, "__construct");
	
			RETURN_CTOR(group);
		}
	
		RETURN_CCTOR(messages);
	}
	
	PHALCON_INIT_NVAR(group);
	object_init_ex(group, phalcon_validation_message_group_ce);
	PHALCON_CALL_METHOD_NORETURN(group, "__construct");
	
	
	if (!phalcon_is_iterable(messages, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
		return;
	}
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_FOREACH_KEY(element, ah0, hp0);
		PHALCON_GET_FOREACH_VALUE(element_messages);
	
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(group, "appendmessages", element_messages);
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	
	RETURN_CTOR(group);
}
Пример #22
0
/**
 * Returns the annotations found in the methods' docblocks
 *
 * @return Phalcon\Annotations\Collection[]
 */
PHP_METHOD(Phalcon_Annotations_Reflection, getMethodsAnnotations){

	zval *annotations, *reflection_data, *reflection_methods;
	zval *collections, *reflection_method = NULL, *method_name = NULL;
	zval *collection = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	PHALCON_OBS_VAR(annotations);
	phalcon_read_property_this(&annotations, this_ptr, SL("_methodAnnotations"), PH_NOISY_CC);
	if (Z_TYPE_P(annotations) != IS_OBJECT) {
	
		PHALCON_OBS_VAR(reflection_data);
		phalcon_read_property_this(&reflection_data, this_ptr, SL("_reflectionData"), PH_NOISY_CC);
		if (phalcon_array_isset_string(reflection_data, SS("methods"))) {
	
			PHALCON_OBS_VAR(reflection_methods);
			phalcon_array_fetch_string(&reflection_methods, reflection_data, SL("methods"), PH_NOISY_CC);
			if (phalcon_fast_count_ev(reflection_methods TSRMLS_CC)) {
	
				PHALCON_INIT_VAR(collections);
				array_init(collections);
	
				phalcon_is_iterable(reflection_methods, &ah0, &hp0, 0, 0);
	
				while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
					PHALCON_GET_HKEY(method_name, ah0, hp0);
					PHALCON_GET_HVALUE(reflection_method);
	
					PHALCON_INIT_NVAR(collection);
					object_init_ex(collection, phalcon_annotations_collection_ce);
					phalcon_call_method_p1_noret(collection, "__construct", reflection_method);
	
					phalcon_array_update_zval(&collections, method_name, &collection, PH_COPY | PH_SEPARATE TSRMLS_CC);
	
					zend_hash_move_forward_ex(ah0, &hp0);
				}
	
				phalcon_update_property_this(this_ptr, SL("_methodAnnotations"), collections TSRMLS_CC);
	
				RETURN_CTOR(collections);
			}
		}
	
		phalcon_update_property_bool(this_ptr, SL("_methodAnnotations"), 0 TSRMLS_CC);
		RETURN_MM_FALSE;
	}
	
	RETURN_CCTOR(annotations);
}
Пример #23
0
/**
 * Sends the headers to the client
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Response_Headers, send){

	zval *headers, *value = NULL, *header = NULL;
	zval *http_header = NULL;
	zval copy;
	int use_copy;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	sapi_header_line ctr = { NULL, 0, 0 };

	PHALCON_MM_GROW();

	if (!SG(headers_sent)) {
	
		PHALCON_OBS_VAR(headers);
		phalcon_read_property_this(&headers, this_ptr, SL("_headers"), PH_NOISY_CC);
	
		phalcon_is_iterable(headers, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HKEY(header, ah0, hp0);
			PHALCON_GET_HVALUE(value);

			if (PHALCON_IS_NOT_EMPTY(value)) {
				PHALCON_INIT_NVAR(http_header);
				PHALCON_CONCAT_VSV(http_header, header, ": ", value);
				ctr.line     = Z_STRVAL_P(http_header);
				ctr.line_len = Z_STRLEN_P(http_header);
				sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
			} else {
				zend_make_printable_zval(header, &copy, &use_copy);
				if (unlikely(use_copy)) {
					header = &copy;
				}

				ctr.line     = Z_STRVAL_P(header);
				ctr.line_len = Z_STRLEN_P(header);
				sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);

				if (unlikely(use_copy)) {
					zval_dtor(&copy);
				}
			}

			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
		RETURN_MM_TRUE;
	}
	
	RETURN_MM_FALSE;
}
Пример #24
0
/**
 * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor.
 * Call it when you need to restore a database connection.
 *
 * @param array $descriptor
 * @return boolean
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, connect) {

    zval *descriptor = NULL, *startup, *value = NULL;
    HashTable *ah0;
    HashPosition hp0;
    zval **hd;

    PHALCON_MM_GROW();

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

    if (!descriptor) {
        PHALCON_INIT_VAR(descriptor);
    } else {
        PHALCON_SEPARATE_PARAM(descriptor);
    }

    if (!zend_is_true(descriptor)) {
        PHALCON_OBS_NVAR(descriptor);
        phalcon_read_property_this(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY TSRMLS_CC);
    }

    /**
     * Connect
     */
    PHALCON_CALL_PARENT(NULL, phalcon_db_adapter_pdo_oracle_ce, this_ptr, "connect", descriptor);

    /**
     * Database session settings initiated with each HTTP request. Oracle behaviour
     * depends on particular NLS* parameter. Check if the developer has defined custom
     * startup or create one from scratch
     */
    if (phalcon_array_isset_string(descriptor, SS("startup"))) {

        PHALCON_OBS_VAR(startup);
        phalcon_array_fetch_string(&startup, descriptor, SL("startup"), PH_NOISY);
        if (Z_TYPE_P(startup) == IS_ARRAY) {

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

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

                PHALCON_GET_HVALUE(value);

                PHALCON_CALL_METHOD(NULL, this_ptr, "execute", value);

                zend_hash_move_forward_ex(ah0, &hp0);
            }

        }
    }

    PHALCON_MM_RESTORE();
}
Пример #25
0
/**
 * 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_Multiple, save){

	zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL;
	zval *backends, *backend = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	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);
	}
	
	PHALCON_OBS_VAR(backends);
	phalcon_read_property(&backends, this_ptr, SL("_backends"), PH_NOISY_CC);
	
	if (!phalcon_is_iterable(backends, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
		return;
	}
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_FOREACH_VALUE(backend);
	
		PHALCON_CALL_METHOD_PARAMS_4_NORETURN(backend, "save", key_name, content, lifetime, stop_buffer);
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	
	PHALCON_MM_RESTORE();
}
Пример #26
0
/**
 * 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;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &index, &placeholders);
	
	if (!placeholders) {
		PHALCON_INIT_VAR(placeholders);
	}
	
	PHALCON_OBS_VAR(translate);
	phalcon_read_property_this(&translate, this_ptr, SL("_translate"), PH_NOISY_CC);
	if (phalcon_array_isset(translate, index)) {
	
		PHALCON_OBS_VAR(translation);
		phalcon_array_fetch(&translation, translate, index, PH_NOISY);
		if (Z_TYPE_P(placeholders) == IS_ARRAY) { 
			if (phalcon_fast_count_ev(placeholders TSRMLS_CC)) {
	
				phalcon_is_iterable(placeholders, &ah0, &hp0, 0, 0);
	
				while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
					PHALCON_GET_HKEY(key, ah0, hp0);
					PHALCON_GET_HVALUE(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);
					PHALCON_CPY_WRT(translation, replaced);
	
					zend_hash_move_forward_ex(ah0, &hp0);
				}
	
			}
		}
	
		RETURN_CCTOR(translation);
	}
	
	RETURN_CCTOR(index);
}
Пример #27
0
/**
 * Rollbacks active transactions within the manager
 * Collect will remove transaction from the manager
 *
 * @param boolean $collect
 */
PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollback){

	zval *collect = NULL, *transactions, *transaction = NULL, *connection = NULL;
	zval *is_under_transaction = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &collect);
	
	if (!collect) {
		PHALCON_INIT_VAR(collect);
		ZVAL_BOOL(collect, 1);
	}
	
	PHALCON_OBS_VAR(transactions);
	phalcon_read_property_this(&transactions, this_ptr, SL("_transactions"), PH_NOISY_CC);
	if (Z_TYPE_P(transactions) == IS_ARRAY) { 
	
		phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HVALUE(transaction);
	
			PHALCON_INIT_NVAR(connection);
			phalcon_call_method(connection, transaction, "getconnection");
	
			PHALCON_INIT_NVAR(is_under_transaction);
			phalcon_call_method(is_under_transaction, connection, "isundertransaction");
			if (zend_is_true(is_under_transaction)) {
				phalcon_call_method_noret(connection, "rollback");
				phalcon_call_method_noret(connection, "close");
			}
	
			if (zend_is_true(collect)) {
				phalcon_call_method_p1_noret(this_ptr, "_collecttransaction", transaction);
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	}
	
	PHALCON_MM_RESTORE();
}
Пример #28
0
/**
 * Removes an access from a resource
 *
 * @param string $resourceName
 * @param mixed $accessList
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, dropResourceAccess){

	zval *resource_name, *access_list, *access_name = NULL;
	zval *t0 = NULL, *t1 = NULL;
	zval *r0 = NULL, *r1 = 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();
	}

	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(t0);
			phalcon_read_property(&t0, this_ptr, SL("_accessList"), PH_NOISY_CC);
			PHALCON_OBS_NVAR(r0);
			phalcon_array_fetch(&r0, t0, resource_name, PH_NOISY_CC);
			phalcon_array_unset(&r0, access_name, PH_SEPARATE);
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	} else {
		if (zend_is_true(access_list)) {
			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);
			phalcon_array_unset(&r1, access_list, PH_SEPARATE);
		}
	}
	PHALCON_CALL_METHOD_NORETURN(this_ptr, "_rebuildaccesslist");
	
	PHALCON_MM_RESTORE();
}
Пример #29
0
/**
 * Returns the translation related to the given key
 *
 * @param string $index
 * @param array $placeholders
 * @param string $domain
 * @return string
 */
PHP_METHOD(Phalcon_Translate_Adapter_Gettext, query){

	zval *index, *placeholders = NULL, *domain = NULL;
	zval *translation, *key = NULL, *value = NULL, *key_placeholder = NULL, *replaced = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	char *msgstr;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 2, &index, &placeholders, &domain);
	
	if (!domain) {
		msgstr = gettext(Z_STRVAL_P(index));
	} else {
		msgstr = dgettext(Z_STRVAL_P(domain), Z_STRVAL_P(index));
	}

	PHALCON_INIT_VAR(translation);
	ZVAL_STRING(translation, msgstr, 1);

	if (placeholders && Z_TYPE_P(placeholders) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(placeholders))) {
		phalcon_is_iterable(placeholders, &ah0, &hp0, 0, 0);
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
			PHALCON_GET_HKEY(key, ah0, hp0);
			PHALCON_GET_HVALUE(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);

			PHALCON_CPY_WRT(translation, replaced);

			zend_hash_move_forward_ex(ah0, &hp0);
		}
	}

	RETURN_CTOR(translation);
}
Пример #30
0
/**
 * Gets a list of columns with escaped identifiers
 *
 *<code>
 * echo $dialect->getColumnList(array('column1', 'column'));
 *</code>
 *
 * @param array $columnList
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect, getColumnList){

	zval *column_list, *str_list, *escape_char, *column = NULL;
	zval *column_quoted = NULL, *joined_list;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

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

	PHALCON_INIT_VAR(str_list);
	array_init(str_list);
	
	PHALCON_OBS_VAR(escape_char);
	phalcon_read_property(&escape_char, this_ptr, SL("_escapeChar"), PH_NOISY_CC);
	
	if (!phalcon_is_iterable(column_list, &ah0, &hp0, 0, 0 TSRMLS_CC)) {
		return;
	}
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_FOREACH_VALUE(column);
	
		PHALCON_INIT_NVAR(column_quoted);
		PHALCON_CONCAT_VVV(column_quoted, escape_char, column, escape_char);
		phalcon_array_append(&str_list, column_quoted, PH_SEPARATE TSRMLS_CC);
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	PHALCON_INIT_VAR(joined_list);
	phalcon_fast_join_str(joined_list, SL(", "), str_list TSRMLS_CC);
	
	RETURN_CTOR(joined_list);
}