コード例 #1
0
ファイル: url.c プロジェクト: Myleft/cphalcon7
/**
 * Generates a URL for a static resource
 *
 * @param string|array $uri
 * @param array $args
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_Url, getStatic){

	zval *uri = NULL, *args = NULL, *static_base_uri, *base_uri = NULL;
	zval *matched, *pattern, *query_string;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 2, &uri, &args);

	if (!uri) {
		uri = &PHALCON_GLOBAL(z_null);
	} else {
		PHALCON_ENSURE_IS_STRING(uri);

		if (strstr(Z_STRVAL_P(uri), "://")) {
			PHALCON_INIT_VAR(matched);
			PHALCON_INIT_VAR(pattern);
			ZVAL_STRING(pattern, "/^[^:\\/?#]++:/");
			RETURN_MM_ON_FAILURE(phalcon_preg_match(matched, pattern, uri, NULL));
			if (zend_is_true(matched)) {
				RETURN_CTOR(uri);
			}
		}
	}

	static_base_uri = phalcon_read_property(getThis(), SL("_staticBaseUri"), PH_NOISY);
	if (Z_TYPE_P(static_base_uri) != IS_NULL) {
		PHALCON_CONCAT_VV(return_value, static_base_uri, uri);
	} else {	
		PHALCON_CALL_METHOD(&base_uri, getThis(), "getbaseuri");
		PHALCON_CONCAT_VV(return_value, base_uri, uri);
	}

	if (args) {
		PHALCON_INIT_VAR(query_string);
		phalcon_http_build_query(query_string, args, "&");
		if (Z_TYPE_P(query_string) == IS_STRING && Z_STRLEN_P(query_string)) {
			if (phalcon_memnstr_str(return_value, "?", 1)) {
				PHALCON_SCONCAT_SV(return_value, "&", query_string);
			}
			else {
				PHALCON_SCONCAT_SV(return_value, "?", query_string);
			}
		}
	}

	RETURN_MM();
}
コード例 #2
0
ファイル: memcache.c プロジェクト: Myleft/cphalcon
/**
 * Returns a cached content
 *
 * @param int|string $keyName
 * @param   long $lifetime
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){

	zval *key_name, *lifetime = NULL, *memcache, *frontend;
	zval *prefix, *prefixed_key, *cached_content = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &key_name, &lifetime);
	
	memcache = phalcon_fetch_nproperty_this(this_ptr, SL("_memcache"), PH_NOISY TSRMLS_CC);
	if (Z_TYPE_P(memcache) != IS_OBJECT) {
		memcache = NULL;
		PHALCON_CALL_METHOD(&memcache, this_ptr, "_connect");
	}
	
	frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC);
	prefix   = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC);
	
	PHALCON_INIT_VAR(prefixed_key);
	PHALCON_CONCAT_VV(prefixed_key, prefix, key_name);
	phalcon_update_property_this(this_ptr, SL("_lastKey"), prefixed_key TSRMLS_CC);
	
	PHALCON_CALL_METHOD(&cached_content, memcache, "get", prefixed_key);
	if (PHALCON_IS_FALSE(cached_content)) {
		RETURN_MM_NULL();
	}

	if (phalcon_is_numeric(cached_content)) {
		RETURN_CCTOR(cached_content);
	}
	
	PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content);
	RETURN_MM();
}
コード例 #3
0
ファイル: memcache.c プロジェクト: dreamsxin/cphalcon7
/**
 * Returns a cached content
 *
 * @param int|string $keyName
 * @param   long $lifetime
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){

	zval *key_name, *lifetime = NULL, memcache = {}, frontend = {}, prefix = {}, prefixed_key = {}, cached_content = {};

	phalcon_fetch_params(0, 1, 1, &key_name, &lifetime);

	phalcon_return_property(&memcache, getThis(), SL("_memcache"));
	if (Z_TYPE(memcache) != IS_OBJECT) {
		PHALCON_CALL_METHODW(&memcache, getThis(), "_connect");
	}

	phalcon_return_property(&frontend, getThis(), SL("_frontend"));
	phalcon_return_property(&prefix, getThis(), SL("_prefix"));

	PHALCON_CONCAT_VV(&prefixed_key, &prefix, key_name);
	phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key);

	PHALCON_CALL_METHODW(&cached_content, &memcache, "get", &prefixed_key);
	if (PHALCON_IS_FALSE(&cached_content)) {
		RETURN_NULL();
	}

	if (phalcon_is_numeric(&cached_content)) {
		RETURN_CTORW(&cached_content);
	}

	PHALCON_RETURN_CALL_METHOD(&frontend, "afterretrieve", &cached_content);
}
コード例 #4
0
ファイル: session.c プロジェクト: meibk/cphalcon
/**
 * Check whether a session variable is set in an application context
 *
 * @param string $index
 */
PHP_METHOD(Phalcon_Session, has){

	zval *index = NULL, *unique_id = NULL, *key = NULL;
	zval *g0 = NULL;
	int eval_int;

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

	PHALCON_INIT_VAR(unique_id);
	phalcon_read_property(&unique_id, this_ptr, SL("_uniqueId"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(key);
	PHALCON_CONCAT_VV(key, unique_id, index);
	phalcon_get_global(&g0, SL("_SESSION")+1 TSRMLS_CC);
	eval_int = phalcon_array_isset(g0, key);
	if (eval_int) {
		PHALCON_MM_RESTORE();
		RETURN_TRUE;
	}
	
	PHALCON_MM_RESTORE();
	RETURN_FALSE;
}
コード例 #5
0
ファイル: collection.c プロジェクト: googlle/cphalcon7
/**
 * Returns the complete location where the joined/filtered collection must be written
 *
 * @param string $basePath
 * @return string
 */
PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){

	zval *base_path = NULL, *target_path, complete_path = {};

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

	if (!base_path) {
		base_path = &PHALCON_GLOBAL(z_null);
	}

	target_path = phalcon_read_property(getThis(), SL("_targetPath"), PH_NOISY);

	/** 
	 * A base path for resources can be set in the assets manager
	 */
	PHALCON_CONCAT_VV(&complete_path, base_path, target_path);

	/** 
	 * Get the real template path, the target path can optionally don't exist
	 */
	if (phalcon_file_exists(&complete_path) == SUCCESS) {
		phalcon_file_realpath(return_value, &complete_path);
		return;
	}

	RETURN_CTORW(&complete_path);
}
コード例 #6
0
ファイル: memory.c プロジェクト: 100851766/cphalcon
/**
 * Returns a cached content
 *
 * @param 	string $keyName
 * @param   long $lifetime
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Memory, get){

	zval *key_name, *lifetime = NULL;
	zval *data, *cached_content, *frontend, *last_key;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &key_name, &lifetime);
	
	if (Z_TYPE_P(key_name) == IS_NULL) {
		last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY TSRMLS_CC);
	} else {
		zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC);
	
		PHALCON_INIT_VAR(last_key);
		PHALCON_CONCAT_VV(last_key, prefix, key_name);
		phalcon_update_property_this(this_ptr, SL("_lastKey"), last_key TSRMLS_CC);
	}
	
	data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC);
	if (phalcon_array_isset_fetch(&cached_content, data, last_key)) {
		if (Z_TYPE_P(cached_content) != IS_NULL) {
			if (phalcon_is_numeric(cached_content)) {
				RETVAL_ZVAL(cached_content, 1, 0);
			} else {
				frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC);
				PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content);
			}
		}
	}

	PHALCON_MM_RESTORE();
}
コード例 #7
0
ファイル: adapter.c プロジェクト: BlueShark/cphalcon
/**
 * Gets a session variable from an application context
 *
 * @param string $index
 * @param mixed $defaultValue
 * @return mixed
 */
PHP_METHOD(Phalcon_Session_Adapter, get){

	zval *index, *default_value = NULL, *unique_id, *key, *_SESSION;
	zval *value;

	PHALCON_MM_GROW();

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

	if (!default_value) {
		PHALCON_INIT_VAR(default_value);
	}
	
	PHALCON_OBS_VAR(unique_id);
	phalcon_read_property(&unique_id, this_ptr, SL("_uniqueId"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(key);
	PHALCON_CONCAT_VV(key, unique_id, index);
	phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC);
	if (phalcon_array_isset(_SESSION, key)) {
	
		PHALCON_OBS_VAR(value);
		phalcon_array_fetch(&value, _SESSION, key, PH_NOISY_CC);
		if (PHALCON_IS_NOT_EMPTY(value)) {
			RETURN_CCTOR(value);
		}
	}
	
	
	RETURN_CCTOR(default_value);
}
コード例 #8
0
ファイル: metadata.c プロジェクト: fatihzkaratana/cphalcon
/**
 * Returns the name of identity field (if one is present)
 *
 * @param  Phalcon\Mvc\Model $model
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData, getIdentityField){

	zval *model = NULL, *table = NULL, *schema = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL;
	zval *t0 = NULL;

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

	PHALCON_INIT_VAR(table);
	PHALCON_CALL_METHOD(table, model, "getsource", PH_NO_CHECK);
	
	PHALCON_INIT_VAR(schema);
	PHALCON_CALL_METHOD(schema, model, "getschema", PH_NO_CHECK);
	PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "_initializemetadata", model, table, schema, PH_NO_CHECK);
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	PHALCON_CONCAT_VV(r0, schema, table);
	
	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, SL("_metaData"), PH_NOISY_CC);
	
	PHALCON_ALLOC_ZVAL_MM(r1);
	phalcon_array_fetch(&r1, t0, r0, PH_NOISY_CC);
	
	PHALCON_ALLOC_ZVAL_MM(r2);
	phalcon_array_fetch_long(&r2, r1, 8, PH_NOISY_CC);
	
	RETURN_CCTOR(r2);
}
コード例 #9
0
ファイル: yaml.c プロジェクト: dreamsxin/cphalcon7
/**
 * Load config file
 *
 * @param string $filePath
 */
PHP_METHOD(Phalcon_Config_Adapter_Yaml, read){

	zval *file_path, *absolute_path = NULL, config_dir_path = {}, *base_path = NULL, config = {};

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

	if (absolute_path == NULL) {
		absolute_path = &PHALCON_GLOBAL(z_false);
	}

	if (zend_is_true(absolute_path)) {
		PHALCON_CPY_WRT_CTOR(&config_dir_path, file_path);
	} else {
		base_path = phalcon_read_static_property_ce(phalcon_config_adapter_ce, SL("_basePath"));

		PHALCON_CONCAT_VV(&config_dir_path, base_path, file_path);
	}

	PHALCON_CALL_FUNCTIONW(&config, "yaml_parse_file", &config_dir_path);

	if (Z_TYPE(config) == IS_ARRAY) {
		PHALCON_CALL_METHODW(NULL, getThis(), "val", &config);
	}

	RETURN_THISW();
}
コード例 #10
0
ファイル: utils.c プロジェクト: rcpsec/cphalcon
/**
 * Gets public URL to phalcon instance
 *
 * @param string $uri
 * @return string
 */
PHP_METHOD(Phalcon_Utils, getUrl){

	zval *uri = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL;

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

	if (!uri) {
		PHALCON_INIT_VAR(uri);
		ZVAL_NULL(uri);
	}
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	PHALCON_ALLOC_ZVAL_MM(r1);
	PHALCON_ALLOC_ZVAL_MM(r2);
	PHALCON_CALL_STATIC(r2, "phalcon_controller_front", "getinstance");
	PHALCON_CALL_METHOD(r1, r2, "getbaseuri", PHALCON_NO_CHECK);
	PHALCON_CONCAT_VV(r0, r1, uri);
	
	RETURN_CTOR(r0);
}
コード例 #11
0
ファイル: line.c プロジェクト: golovanov/cphalcon
/**
 * Applies a format to a message before sent it to the internal log
 *
 * @param string $message
 * @param int $type
 * @param int $timestamp
 * @return string
 */
PHP_METHOD(Phalcon_Logger_Formatter_Line, format) {

    zval *message, *type, *timestamp, *format = NULL, *date_format;
    zval *date, *date_wildcard, *new_format = NULL, *type_string;
    zval *type_wildcard, *message_wildcard, *eol;

    PHALCON_MM_GROW();

    phalcon_fetch_params(1, 3, 0, &message, &type, &timestamp);

    PHALCON_OBS_VAR(format);
    phalcon_read_property_this(&format, this_ptr, SL("_format"), PH_NOISY_CC);

    /**
     * Check if the format has the %date% placeholder
     */
    if (phalcon_memnstr_str(format, SL("%date%"))) {
        PHALCON_OBS_VAR(date_format);
        phalcon_read_property_this(&date_format, this_ptr, SL("_dateFormat"), PH_NOISY_CC);

        PHALCON_INIT_VAR(date);
        phalcon_call_func_p2(date, "date", date_format, timestamp);

        PHALCON_INIT_VAR(date_wildcard);
        ZVAL_STRING(date_wildcard, "%date%", 1);

        PHALCON_INIT_VAR(new_format);
        phalcon_fast_str_replace(new_format, date_wildcard, date, format);
    } else {
        PHALCON_CPY_WRT(new_format, format);
    }

    /**
     * Check if the format has the %type% placeholder
     */
    if (phalcon_memnstr_str(format, SL("%type%"))) {
        PHALCON_INIT_VAR(type_string);
        phalcon_call_method_p1(type_string, this_ptr, "gettypestring", type);

        PHALCON_INIT_VAR(type_wildcard);
        ZVAL_STRING(type_wildcard, "%type%", 1);

        PHALCON_INIT_NVAR(format);
        phalcon_fast_str_replace(format, type_wildcard, type_string, new_format);
    } else {
        PHALCON_CPY_WRT(format, new_format);
    }

    PHALCON_INIT_VAR(message_wildcard);
    ZVAL_STRING(message_wildcard, "%message%", 1);

    PHALCON_INIT_NVAR(new_format);
    phalcon_fast_str_replace(new_format, message_wildcard, message, format);

    PHALCON_INIT_VAR(eol);
    ZVAL_STRING(eol, PHP_EOL, 1);
    PHALCON_CONCAT_VV(return_value, new_format, eol);

    RETURN_MM();
}
コード例 #12
0
ファイル: php.c プロジェクト: googlle/cphalcon7
/**
 * Load config file
 *
 * @param string $filePath
 */
PHP_METHOD(Phalcon_Config_Adapter_Php, read){

	zval *file_path, *absolute_path = NULL, config_dir_path = {}, *base_path, config = {};

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

	if (absolute_path == NULL) {
		absolute_path = &PHALCON_GLOBAL(z_false);
	}

	if (zend_is_true(absolute_path)) {
		PHALCON_CPY_WRT(&config_dir_path, file_path);
	} else {
		base_path = phalcon_read_static_property_ce(phalcon_config_adapter_ce, SL("_basePath"));

		PHALCON_CONCAT_VV(&config_dir_path, base_path, file_path);
	}

	if (phalcon_require_ret(&config, Z_STRVAL(config_dir_path)) == FAILURE) {
		zend_throw_exception_ex(phalcon_config_exception_ce, 0, "Configuration file '%s' cannot be read", Z_STRVAL(config_dir_path));
		PHALCON_PTR_DTOR(&config_dir_path);
		return;
	}
	PHALCON_PTR_DTOR(&config_dir_path);

	if (Z_TYPE(config) == IS_ARRAY) {
		PHALCON_CALL_METHODW(NULL, getThis(), "val", &config);
	}
	PHALCON_PTR_DTOR(&config);
	RETURN_THISW();
}
コード例 #13
0
ファイル: resource.c プロジェクト: 11mariom/cphalcon
/**
 * Returns the content of the resource as an string
 * Optionally a base path where the resource is located can be set
 *
 * @param string $basePath
 * @return string
 */
PHP_METHOD(Phalcon_Assets_Resource, getContent){

	zval *base_path = NULL, *source_path = NULL, *complete_path;
	zval *local, *exception_message = NULL, *content;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &base_path);
	
	if (!base_path) {
		PHALCON_INIT_VAR(base_path);
	}
	
	PHALCON_OBS_VAR(source_path);
	phalcon_read_property_this(&source_path, this_ptr, SL("_sourcePath"), PH_NOISY_CC);
	if (PHALCON_IS_EMPTY(source_path)) {
		PHALCON_OBS_NVAR(source_path);
		phalcon_read_property_this(&source_path, this_ptr, SL("_path"), PH_NOISY_CC);
	}
	
	/** 
	 * A base path for resources can be set in the assets manager
	 */
	PHALCON_INIT_VAR(complete_path);
	PHALCON_CONCAT_VV(complete_path, base_path, source_path);
	
	PHALCON_OBS_VAR(local);
	phalcon_read_property_this(&local, this_ptr, SL("_local"), PH_NOISY_CC);
	
	/** 
	 * Local resources are loaded from the local disk
	 */
	if (zend_is_true(local)) {
	
		/** 
		 * Check first if the file is readable
		 */
		if (phalcon_file_exists(complete_path TSRMLS_CC) == FAILURE) {
			PHALCON_INIT_VAR(exception_message);
			PHALCON_CONCAT_SVS(exception_message, "Resource's content for \"", complete_path, "\" cannot be loaded");
			PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
			return;
		}
	}
	
	/** 
	 * Use file_get_contents to respect the openbase_dir. Access urls must be enabled
	 */
	PHALCON_INIT_VAR(content);
	phalcon_file_get_contents(content, complete_path TSRMLS_CC);
	if (PHALCON_IS_FALSE(content)) {
		PHALCON_INIT_NVAR(exception_message);
		PHALCON_CONCAT_SVS(exception_message, "Resource's content for \"", complete_path, "\" cannot be read");
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
		return;
	}
	
	RETURN_CCTOR(content);
}
コード例 #14
0
ファイル: group.c プロジェクト: BlueShark/cphalcon
/**
 * Adds a route applying the common attributes
 *
 * @param string $patten
 * @param array $paths
 * @param array $httpMethods
 * @return Phalcon\Mvc\Router\Route
 */
PHP_METHOD(Phalcon_Mvc_Router_Group, _addRoute){

	zval *pattern, *paths = NULL, *http_methods = NULL, *prefix, *prefix_pattern;
	zval *default_paths, *merged_paths = NULL, *route;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zz", &pattern, &paths, &http_methods) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (!paths) {
		PHALCON_INIT_VAR(paths);
	}
	
	if (!http_methods) {
		PHALCON_INIT_VAR(http_methods);
	}
	
	PHALCON_OBS_VAR(prefix);
	phalcon_read_property(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
	
	/** 
	 * Add the prefix to the pattern
	 */
	PHALCON_INIT_VAR(prefix_pattern);
	PHALCON_CONCAT_VV(prefix_pattern, prefix, pattern);
	
	PHALCON_OBS_VAR(default_paths);
	phalcon_read_property(&default_paths, this_ptr, SL("_paths"), PH_NOISY_CC);
	
	/** 
	 * Check if the paths need to be merged with current paths
	 */
	if (Z_TYPE_P(default_paths) == IS_ARRAY) { 
		if (Z_TYPE_P(paths) == IS_ARRAY) { 
			/** 
			 * Merge the paths with the default paths
			 */
			PHALCON_INIT_VAR(merged_paths);
			PHALCON_CALL_FUNC_PARAMS_2(merged_paths, "array_merge", default_paths, paths);
		} else {
			PHALCON_CPY_WRT(merged_paths, default_paths);
		}
	} else {
		PHALCON_CPY_WRT(merged_paths, paths);
	}
	
	/** 
	 * Every route is internally stored as a Phalcon\Mvc\Router\Route
	 */
	PHALCON_INIT_VAR(route);
	object_init_ex(route, phalcon_mvc_router_route_ce);
	PHALCON_CALL_METHOD_PARAMS_3_NORETURN(route, "__construct", prefix_pattern, merged_paths, http_methods);
	
	phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC);
	
	RETURN_CTOR(route);
}
コード例 #15
0
ファイル: file.c プロジェクト: andresgutierrez/cphalcon
/**
 * Sends/Writes messages to the file log
 *
 * @param string $message
 * @param int $type
 */
PHP_METHOD(Phalcon_Logger_Adapter_File, log){

	zval *message = NULL, *type = NULL, *msg = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL;
	zval *c0 = NULL;
	zval *i0 = NULL;

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

	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, "_fileHandler", sizeof("_fileHandler")-1, PHALCON_NOISY TSRMLS_CC);
	if (!zend_is_true(t0)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid");
		return;
	}
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	PHALCON_CALL_FUNC_PARAMS_1(r0, "is_scalar", message, 0x045);
	if (zend_is_true(r0)) {
		PHALCON_ALLOC_ZVAL_MM(r1);
		PHALCON_INIT_VAR(c0);
		ZVAL_BOOL(c0, 1);
		PHALCON_CALL_FUNC_PARAMS_2(r1, "print_r", message, c0, 0x008);
		PHALCON_CPY_WRT(msg, r1);
	}
	
	PHALCON_ALLOC_ZVAL_MM(t1);
	phalcon_read_property(&t1, this_ptr, "_transaction", sizeof("_transaction")-1, PHALCON_NOISY TSRMLS_CC);
	if (zend_is_true(t1)) {
		PHALCON_ALLOC_ZVAL_MM(i0);
		object_init_ex(i0, phalcon_logger_item_ce);
		PHALCON_ALLOC_ZVAL_MM(r2);
		PHALCON_CALL_FUNC(r2, "time", 0x018);
		PHALCON_CALL_METHOD_PARAMS_3_NORETURN(i0, "__construct", message, type, r2, PHALCON_CHECK);
		PHALCON_ALLOC_ZVAL_MM(t2);
		phalcon_read_property(&t2, this_ptr, "_quenue", sizeof("_quenue")-1, PHALCON_NOISY TSRMLS_CC);
		phalcon_array_append(&t2, i0, PHALCON_NO_SEPARATE_THX TSRMLS_CC);
		phalcon_update_property_zval(this_ptr, "_quenue", strlen("_quenue"), t2 TSRMLS_CC);
	} else {
		PHALCON_ALLOC_ZVAL_MM(t3);
		phalcon_read_property(&t3, this_ptr, "_fileHandler", sizeof("_fileHandler")-1, PHALCON_NOISY TSRMLS_CC);
		PHALCON_ALLOC_ZVAL_MM(r3);
		PHALCON_ALLOC_ZVAL_MM(r4);
		PHALCON_CALL_METHOD_PARAMS_2(r4, this_ptr, "_applyformat", message, type, PHALCON_NO_CHECK);
		PHALCON_ALLOC_ZVAL_MM(t4);
		zend_get_constant("PHP_EOL", strlen("PHP_EOL"), t4 TSRMLS_CC);
		PHALCON_CONCAT_VV(r3, r4, t4);
		PHALCON_CALL_FUNC_PARAMS_2_NORETURN("fputs", t3, r3, 0x04F);
	}
	
	PHALCON_MM_RESTORE();
}
コード例 #16
0
ファイル: file.c プロジェクト: fatihzkaratana/cphalcon
/**
  * Commits the internal transaction
  *
  */
PHP_METHOD(Phalcon_Logger_Adapter_File, commit){

	zval *message = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();
	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, SL("_transaction"), PH_NOISY_CC);
	if (!zend_is_true(t0)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "There is no active transaction");
		return;
	}
	phalcon_update_property_bool(this_ptr, SL("_transaction"), 0 TSRMLS_CC);
	
	PHALCON_ALLOC_ZVAL_MM(t1);
	phalcon_read_property(&t1, this_ptr, SL("_quenue"), PH_NOISY_CC);
	if (!phalcon_valid_foreach(t1 TSRMLS_CC)) {
		return;
	}
	
	ah0 = Z_ARRVAL_P(t1);
	zend_hash_internal_pointer_reset_ex(ah0, &hp0);
	fes_654f_1:
		if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
			goto fee_654f_1;
		}
		
		PHALCON_INIT_VAR(message);
		ZVAL_ZVAL(message, *hd, 1, 0);
		PHALCON_INIT_VAR(t2);
		phalcon_read_property(&t2, this_ptr, SL("_fileHandler"), PH_NOISY_CC);
		PHALCON_INIT_VAR(r0);
		PHALCON_CALL_METHOD(r0, message, "getmessage", PH_NO_CHECK);
		PHALCON_INIT_VAR(r1);
		PHALCON_CALL_METHOD(r1, message, "gettype", PH_NO_CHECK);
		PHALCON_INIT_VAR(r2);
		PHALCON_CALL_METHOD(r2, message, "gettime", PH_NO_CHECK);
		PHALCON_INIT_VAR(r3);
		PHALCON_CALL_METHOD_PARAMS_3(r3, this_ptr, "_applyformat", r0, r1, r2, PH_NO_CHECK);
		PHALCON_INIT_VAR(t3);
		zend_get_constant(SL("PHP_EOL"), t3 TSRMLS_CC);
		PHALCON_INIT_VAR(r4);
		PHALCON_CONCAT_VV(r4, r3, t3);
		PHALCON_CALL_FUNC_PARAMS_2_NORETURN("fputs", t2, r4);
		zend_hash_move_forward_ex(ah0, &hp0);
		goto fes_654f_1;
	fee_654f_1:
	if(0){}
	
	
	PHALCON_MM_RESTORE();
}
コード例 #17
0
ファイル: file.c プロジェクト: alantonilopez/cphalcon
/**
 * Sends/Writes messages to the file log
 *
 * @param string $message
 * @param int $type
 */
PHP_METHOD(Phalcon_Logger_Adapter_File, log){

	zval *message, *type = NULL, *file_handler, *transaction;
	zval *time, *quenue_item, *applied_format, *eol;
	zval *applied_eol;
	zval *t0 = NULL;

	PHALCON_MM_GROW();

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

	if (!type) {
		PHALCON_INIT_NVAR(type);
		ZVAL_LONG(type, 7);
	}
	
	PHALCON_INIT_VAR(file_handler);
	phalcon_read_property(&file_handler, this_ptr, SL("_fileHandler"), PH_NOISY_CC);
	if (!zend_is_true(file_handler)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid");
		return;
	}
	
	PHALCON_INIT_VAR(transaction);
	phalcon_read_property(&transaction, this_ptr, SL("_transaction"), PH_NOISY_CC);
	if (zend_is_true(transaction)) {
		PHALCON_INIT_VAR(time);
		PHALCON_CALL_FUNC(time, "time");
		
		PHALCON_INIT_VAR(quenue_item);
		object_init_ex(quenue_item, phalcon_logger_item_ce);
		PHALCON_CALL_METHOD_PARAMS_3_NORETURN(quenue_item, "__construct", message, type, time, PH_CHECK);
		
		PHALCON_INIT_VAR(t0);
		phalcon_read_property(&t0, this_ptr, SL("_quenue"), PH_NOISY_CC);
		phalcon_array_append(&t0, quenue_item, 0 TSRMLS_CC);
		phalcon_update_property_zval(this_ptr, SL("_quenue"), t0 TSRMLS_CC);
	} else {
		PHALCON_INIT_VAR(applied_format);
		PHALCON_CALL_METHOD_PARAMS_2(applied_format, this_ptr, "_applyformat", message, type, PH_NO_CHECK);
		
		PHALCON_INIT_VAR(eol);
		zend_get_constant(SL("PHP_EOL"), eol TSRMLS_CC);
		
		PHALCON_INIT_VAR(applied_eol);
		PHALCON_CONCAT_VV(applied_eol, applied_format, eol);
		PHALCON_CALL_FUNC_PARAMS_2_NORETURN("fwrite", file_handler, applied_eol);
	}
	
	PHALCON_MM_RESTORE();
}
コード例 #18
0
ファイル: metadata.c プロジェクト: Tigerlee1987/cphalcon
/**
 * Writes meta-data for certain model using a MODEL_* constant
 *
 * @param Phalcon\Mvc\ModelInterface $model
 * @param int $index
 * @param mixed $data
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData, writeMetaDataIndex){

	zval *model, *index, *data, *table, *schema, *key, *meta_data = NULL;
	int eval_int;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &model, &index, &data) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	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", PH_NO_CHECK);
	
	PHALCON_INIT_VAR(schema);
	PHALCON_CALL_METHOD(schema, model, "getschema", PH_NO_CHECK);
	
	PHALCON_INIT_VAR(key);
	PHALCON_CONCAT_VV(key, schema, table);
	
	PHALCON_INIT_VAR(meta_data);
	phalcon_read_property(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC);
	eval_int = phalcon_array_isset(meta_data, key);
	if (!eval_int) {
		PHALCON_CALL_METHOD_PARAMS_4_NORETURN(this_ptr, "_initialize", model, key, table, schema, PH_NO_CHECK);
	
		PHALCON_INIT_NVAR(meta_data);
		phalcon_read_property(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC);
	}
	
	phalcon_array_update_multi_2(&meta_data, key, index, &data, 0 TSRMLS_CC);
	phalcon_update_property_zval(this_ptr, SL("_metaData"), meta_data TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
コード例 #19
0
ファイル: memory.c プロジェクト: 100851766/cphalcon
/**
 * Stores cached content into the backend and stops the frontend
 *
 * @param string $keyName
 * @param string $content
 * @param long $lifetime
 * @param boolean $stopBuffer
 */
PHP_METHOD(Phalcon_Cache_Backend_Memory, save){

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

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer);
	
	if (!key_name || Z_TYPE_P(key_name) == IS_NULL) {
		last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY TSRMLS_CC);
	} else {
		zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC);
	
		PHALCON_INIT_VAR(last_key);
		PHALCON_CONCAT_VV(last_key, prefix, key_name);
	}

	if (!zend_is_true(last_key)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first");
		return;
	}
	
	frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC);
	if (!content || Z_TYPE_P(content) == IS_NULL) {
		PHALCON_CALL_METHOD(&cached_content, frontend, "getcontent");
	} else {
		cached_content = content;
	}

	if (phalcon_is_numeric(cached_content))	{
		phalcon_update_property_array(this_ptr, SL("_data"), last_key, cached_content TSRMLS_CC);
	} else {
		PHALCON_CALL_METHOD(&prepared_content, frontend, "beforestore", cached_content);
		phalcon_update_property_array(this_ptr, SL("_data"), last_key, prepared_content TSRMLS_CC);
	}
	
	PHALCON_CALL_METHOD(&is_buffering, frontend, "isbuffering");

	if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) {
		PHALCON_CALL_METHOD(NULL, 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();
}
コード例 #20
0
ファイル: uri.c プロジェクト: Myleft/cphalcon7
/**
 * Returns uri
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Uri, build){

	zval *parts, *uri, *scheme, *host, *user, *pass, *port, *path, *query, *fragment, *tmp = NULL;

	PHALCON_MM_GROW();

	parts = phalcon_read_property(getThis(), SL("_parts"), PH_NOISY);

	PHALCON_INIT_VAR(uri);

	if (phalcon_array_isset_str_fetch(&scheme, parts, SL("scheme")) && PHALCON_IS_NOT_EMPTY(scheme)) {
		if (phalcon_array_isset_str_fetch(&host, parts, SL("host")) && PHALCON_IS_NOT_EMPTY(host)) {
			if (phalcon_array_isset_str_fetch(&user, parts, SL("user")) && PHALCON_IS_NOT_EMPTY(user)) {
				if (phalcon_array_isset_str_fetch(&pass, parts, SL("pass")) && PHALCON_IS_NOT_EMPTY(pass)) {
					PHALCON_CONCAT_VSVSVSV(uri, scheme, "://", user, ":", pass, "@", host);
				} else {
					PHALCON_CONCAT_VSVSV(uri, scheme, "://", user, "@", host);
				}
			} else {
				PHALCON_CONCAT_VSV(uri, scheme, "://", host);
			}
		} else {
			PHALCON_CONCAT_VS(uri, scheme, ":");
		}
	}

	if (phalcon_array_isset_str_fetch(&port, parts, SL("port")) && PHALCON_IS_NOT_EMPTY(port)) {
		PHALCON_SCONCAT_SV(uri, ":", port);
	}

	if (phalcon_array_isset_str_fetch(&path, parts, SL("path")) && PHALCON_IS_NOT_EMPTY(path)) {
		if (!phalcon_start_with_str(path, SL("/"))) {
			PHALCON_SCONCAT_SV(uri, "/", path);
		} else {
			PHALCON_INIT_NVAR(tmp);
			PHALCON_CONCAT_VV(tmp, uri, path);
			PHALCON_CPY_WRT(uri, tmp);
		}
	}

	if (phalcon_array_isset_str_fetch(&query, parts, SL("query")) && PHALCON_IS_NOT_EMPTY(query)) {
		PHALCON_INIT_NVAR(tmp);
		phalcon_http_build_query(tmp, query, "&");
		PHALCON_SCONCAT_SV(uri, "?", tmp);
	}

	if (phalcon_array_isset_str_fetch(&fragment, parts, SL("fragment")) && PHALCON_IS_NOT_EMPTY(fragment)) {
		PHALCON_SCONCAT_SV(uri, "#", fragment);
	}

	RETURN_CTOR(uri);
}
コード例 #21
0
ファイル: backend.c プロジェクト: rcpsec/cphalcon
/**
 * Starts a cache. The $keyname allow to identify the created fragment
 *
 * @param int|string $keyName
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend, start){

	zval *key_name = NULL, *backend = NULL, *front_end = NULL, *prefixed_key = NULL;
	zval *existing_cache = NULL, *fresh = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL;

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

	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, SL("_backendOptions"), PHALCON_NOISY TSRMLS_CC);
	PHALCON_CPY_WRT(backend, t0);
	
	PHALCON_ALLOC_ZVAL_MM(t1);
	phalcon_read_property(&t1, this_ptr, SL("_frontendObject"), PHALCON_NOISY TSRMLS_CC);
	PHALCON_CPY_WRT(front_end, t1);
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	
	PHALCON_ALLOC_ZVAL_MM(t2);
	phalcon_read_property(&t2, this_ptr, SL("_prefix"), PHALCON_NOISY TSRMLS_CC);
	PHALCON_CONCAT_VV(r0, t2, key_name);
	PHALCON_CPY_WRT(prefixed_key, r0);
	
	PHALCON_ALLOC_ZVAL_MM(r1);
	PHALCON_CALL_METHOD_PARAMS_1(r1, this_ptr, "get", prefixed_key, PHALCON_NO_CHECK);
	PHALCON_CPY_WRT(existing_cache, r1);
	
	PHALCON_INIT_VAR(t3);
	ZVAL_NULL(t3);
	
	PHALCON_ALLOC_ZVAL_MM(r2);
	is_equal_function(r2, existing_cache, t3 TSRMLS_CC);
	if (zend_is_true(r2)) {
		PHALCON_INIT_VAR(fresh);
		ZVAL_BOOL(fresh, 1);
		PHALCON_CALL_METHOD_NORETURN(front_end, "start", PHALCON_NO_CHECK);
	} else {
		PHALCON_INIT_VAR(fresh);
		ZVAL_BOOL(fresh, 0);
	}
	
	phalcon_update_property_zval(this_ptr, SL("_fresh"), fresh TSRMLS_CC);
	phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC);
	
	RETURN_CHECK_CTOR(existing_cache);
}
コード例 #22
0
ファイル: url.c プロジェクト: 9466/cphalcon
/**
 * Generates a local path
 *
 * @param string $path
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_Url, path){

	zval *path = NULL, *base_path;

	phalcon_fetch_params(0, 0, 1, &path);
	
	if (!path) {
		path = PHALCON_GLOBAL(z_null);
	}
	
	base_path = phalcon_fetch_nproperty_this(this_ptr, SL("_basePath"), PH_NOISY TSRMLS_CC);
	PHALCON_CONCAT_VV(return_value, base_path, path);
}
コード例 #23
0
ファイル: url.c プロジェクト: Myleft/cphalcon7
/**
 * Generates a local path
 *
 * @param string $path
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_Url, path){

	zval *path = NULL, *base_path;

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

	if (!path) {
		path = &PHALCON_GLOBAL(z_null);
	}

	base_path = phalcon_read_property(getThis(), SL("_basePath"), PH_NOISY);
	PHALCON_CONCAT_VV(return_value, base_path, path);
}
コード例 #24
0
ファイル: metadata.c プロジェクト: alantonilopez/cphalcon
/**
 * Reads meta-data for certain model using a MODEL_* constant
 *
 * @param Phalcon\Mvc\Model $model
 * @param int $index
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData, readMetaDataIndex){

	zval *model, *index, *table, *schema, *key, *meta_data = NULL;
	zval *attributes;
	zval *r0 = NULL;
	int eval_int;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &model, &index) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	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;
	}
	
	PHALCON_INIT_VAR(table);
	PHALCON_CALL_METHOD(table, model, "getsource", PH_NO_CHECK);
	
	PHALCON_INIT_VAR(schema);
	PHALCON_CALL_METHOD(schema, model, "getschema", PH_NO_CHECK);
	
	PHALCON_INIT_VAR(key);
	PHALCON_CONCAT_VV(key, schema, table);
	
	PHALCON_INIT_VAR(meta_data);
	phalcon_read_property(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC);
	eval_int = phalcon_array_isset(meta_data, key);
	if (!eval_int) {
		PHALCON_CALL_METHOD_PARAMS_4_NORETURN(this_ptr, "_initializemetadata", model, key, table, schema, PH_NO_CHECK);
		
		PHALCON_INIT_NVAR(meta_data);
		phalcon_read_property(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC);
	}
	
	PHALCON_INIT_VAR(r0);
	phalcon_array_fetch(&r0, meta_data, key, PH_NOISY_CC);
	
	PHALCON_INIT_VAR(attributes);
	phalcon_array_fetch(&attributes, r0, index, PH_NOISY_CC);
	
	RETURN_CCTOR(attributes);
}
コード例 #25
0
ファイル: url.c プロジェクト: 9466/cphalcon
/**
 * Generates a URL for a static resource
 *
 * @param string|array $uri
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_Url, getStatic){

	zval **uri = NULL, *static_base_uri, *base_uri = NULL;
	zval *matched, *pattern;

	phalcon_fetch_params_ex(0, 1, &uri);

	PHALCON_MM_GROW();

	if (!uri) {
		uri = &PHALCON_GLOBAL(z_null);
	}
	else {
		PHALCON_ENSURE_IS_STRING(uri);

		if (strstr(Z_STRVAL_PP(uri), "://")) {
			PHALCON_INIT_VAR(matched);
			PHALCON_INIT_VAR(pattern);
			ZVAL_STRING(pattern, "/^[^:\\/?#]++:/", 1);
			RETURN_MM_ON_FAILURE(phalcon_preg_match(matched, pattern, *uri, NULL TSRMLS_CC));
			if (zend_is_true(matched)) {
				RETURN_CTOR(*uri);
			}
		}
	}
	
	static_base_uri = phalcon_fetch_nproperty_this(this_ptr, SL("_staticBaseUri"), PH_NOISY TSRMLS_CC);
	if (Z_TYPE_P(static_base_uri) != IS_NULL) {
		PHALCON_CONCAT_VV(return_value, static_base_uri, *uri);
		RETURN_MM();
	}
	
	PHALCON_CALL_METHOD(&base_uri, this_ptr, "getbaseuri");
	PHALCON_CONCAT_VV(return_value, base_uri, *uri);
	
	RETURN_MM();
}
コード例 #26
0
ファイル: mongo.c プロジェクト: banketree/cphalcon
/**
 * Returns a cached content
 *
 * @param int|string $keyName
 * @param   long $lifetime
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Mongo, get){

	zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key;
	zval *collection = NULL, *conditions, *document = NULL, *time_condition;
	zval *cached_content;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &key_name, &lifetime);
	
	frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC);
	prefix   = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC);
	
	PHALCON_INIT_VAR(prefixed_key);
	PHALCON_CONCAT_VV(prefixed_key, prefix, key_name);
	phalcon_update_property_this(this_ptr, SL("_lastKey"), prefixed_key TSRMLS_CC);
	
	PHALCON_CALL_METHOD(&collection, this_ptr, "_getcollection");
	
	PHALCON_INIT_VAR(conditions);
	array_init_size(conditions, 2);
	phalcon_array_update_string(&conditions, SL("key"), prefixed_key, PH_COPY);
	
	MAKE_STD_ZVAL(time_condition);
	array_init_size(time_condition, 1);
	add_assoc_long_ex(time_condition, SS("$gt"), (long int)time(NULL));
	add_assoc_zval_ex(conditions, SS("time"), time_condition);

	PHALCON_CALL_METHOD(&document, collection, "findone", conditions);
	if (Z_TYPE_P(document) == IS_ARRAY) { 
		if (likely(phalcon_array_isset_string_fetch(&cached_content, document, SS("data")))) {
			if (phalcon_is_numeric(cached_content)) {
				RETURN_CCTOR(cached_content);
			} else {
				PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content);
				RETURN_MM();
			}
		} else {
			PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache is corrupt");
			return;
		}
	} else {
		RETURN_MM_NULL();
	}
	
}
コード例 #27
0
ファイル: memcache.c プロジェクト: Gildus/cphalcon
/**
 * Returns a cached content
 *
 * @param int|string $keyName
 * @param   long $lifetime
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){

	zval *key_name, *lifetime = NULL, *memcache = NULL, *frontend;
	zval *prefix, *prefixed_key, *cached_content;
	zval *content;

	PHALCON_MM_GROW();

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

	if (!lifetime) {
		PHALCON_INIT_VAR(lifetime);
	}
	
	PHALCON_OBS_VAR(memcache);
	phalcon_read_property(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC);
	if (Z_TYPE_P(memcache) != IS_OBJECT) {
		PHALCON_CALL_METHOD_NORETURN(this_ptr, "_connect");
	
		PHALCON_OBS_NVAR(memcache);
		phalcon_read_property(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC);
	}
	
	PHALCON_OBS_VAR(frontend);
	phalcon_read_property(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(prefix);
	phalcon_read_property(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(prefixed_key);
	PHALCON_CONCAT_VV(prefixed_key, prefix, key_name);
	phalcon_update_property_zval(this_ptr, SL("_lastKey"), prefixed_key TSRMLS_CC);
	
	PHALCON_INIT_VAR(cached_content);
	PHALCON_CALL_METHOD_PARAMS_1(cached_content, memcache, "get", prefixed_key);
	if (PHALCON_IS_FALSE(cached_content)) {
		RETURN_MM_NULL();
	}
	
	PHALCON_INIT_VAR(content);
	PHALCON_CALL_METHOD_PARAMS_1(content, frontend, "afterretrieve", cached_content);
	
	RETURN_CCTOR(content);
}
コード例 #28
0
ファイル: tag.c プロジェクト: angkatan21/cphalcon
/**
 * Prepends a text to current document title
 *
 * @param string $title
 */
PHP_METHOD(Phalcon_Tag, prependTitle){

	zval *title, *document_title;
	zval *r0 = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &title);
	
	PHALCON_OBS_VAR(document_title);
	phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC);
	
	PHALCON_INIT_VAR(r0);
	PHALCON_CONCAT_VV(r0, title, document_title);
	phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
コード例 #29
0
ファイル: url.c プロジェクト: angkatan21/cphalcon
/**
 * Generates a local path
 *
 * @param string $path
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_Url, path){

	zval *path = NULL, *base_path, *final_path;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &path);
	
	if (!path) {
		PHALCON_INIT_VAR(path);
	}
	
	PHALCON_OBS_VAR(base_path);
	phalcon_read_property_this(&base_path, this_ptr, SL("_basePath"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(final_path);
	PHALCON_CONCAT_VV(final_path, base_path, path);
	RETURN_CTOR(final_path);
}
コード例 #30
0
ファイル: resource.c プロジェクト: 11mariom/cphalcon
/**
 * Returns the complete location where the resource must be written
 *
 * @param string $basePath
 * @return string
 */
PHP_METHOD(Phalcon_Assets_Resource, getRealTargetPath){

	zval *base_path = NULL, *target_path = NULL, *local, *complete_path;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &base_path);
	
	if (!base_path) {
		PHALCON_INIT_VAR(base_path);
	}
	
	PHALCON_OBS_VAR(target_path);
	phalcon_read_property_this(&target_path, this_ptr, SL("_targetPath"), PH_NOISY_CC);
	if (PHALCON_IS_EMPTY(target_path)) {
		PHALCON_OBS_NVAR(target_path);
		phalcon_read_property_this(&target_path, this_ptr, SL("_path"), PH_NOISY_CC);
	}
	
	PHALCON_OBS_VAR(local);
	phalcon_read_property_this(&local, this_ptr, SL("_local"), PH_NOISY_CC);
	if (zend_is_true(local)) {
	
		/** 
		 * A base path for resources can be set in the assets manager
		 */
		PHALCON_INIT_VAR(complete_path);
		PHALCON_CONCAT_VV(complete_path, base_path, target_path);
	
		/** 
		 * Get the real template path, the target path can optionally don't exist
		 */
		if (phalcon_file_exists(complete_path TSRMLS_CC) == SUCCESS) {
			phalcon_call_func_p1(return_value, "realpath", complete_path);
			RETURN_MM();
		}
	
		RETURN_CTOR(complete_path);
	}
	
	RETURN_CCTOR(target_path);
}