Exemple #1
0
/**
 * Phalcon\Cache\Backend\Mongo constructor
 *
 * @param Phalcon\Cache\FrontendInterface $frontend
 * @param array $options
 */
PHP_METHOD(Phalcon_Cache_Backend_Mongo, __construct){

	zval *frontend, *options = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &frontend, &options);
	
	if (!options) {
		PHALCON_INIT_VAR(options);
	}
	
	if (!phalcon_array_isset_string(options, SS("mongo"))) {
		if (!phalcon_array_isset_string(options, SS("server"))) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'server' is required");
			return;
		}
	}
	if (!phalcon_array_isset_string(options, SS("db"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'db' is required");
		return;
	}
	
	if (!phalcon_array_isset_string(options, SS("collection"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'collection' is required");
		return;
	}
	
	PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Mongo", "__construct", frontend, options);
	
	PHALCON_MM_RESTORE();
}
Exemple #2
0
/**
 * Gets most possibly client IPv4 Address
 *
 * @return string
 */
PHP_METHOD(Phalcon_Request, getClientAddress){

	zval *address = NULL;
	zval *g0 = NULL;
	zval *r0 = NULL, *r1 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_INIT_VAR(address);
	ZVAL_STRING(address, "", 1);
	phalcon_get_global(&g0, "_SERVER", sizeof("_SERVER") TSRMLS_CC);
	eval_int = phalcon_array_isset_string(g0, "HTTP_X_FORWARDED_FOR", strlen("HTTP_X_FORWARDED_FOR")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r0);
		phalcon_array_fetch_string(&r0, g0, "HTTP_X_FORWARDED_FOR", strlen("HTTP_X_FORWARDED_FOR"), PHALCON_NOISY TSRMLS_CC);
		PHALCON_CPY_WRT(address, r0);
	} else {
		eval_int = phalcon_array_isset_string(g0, "REMOTE_ADDR", strlen("REMOTE_ADDR")+1);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(r1);
			phalcon_array_fetch_string(&r1, g0, "REMOTE_ADDR", strlen("REMOTE_ADDR"), PHALCON_NOISY TSRMLS_CC);
			PHALCON_CPY_WRT(address, r1);
		}
	}
	
	
	PHALCON_RETURN_CHECK_CTOR(address);
}
Exemple #3
0
/**
 * Checks whether request has been made using SOAP
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request, isSoapRequested) {

    zval *server = NULL, *content_type;
    zval *g0 = NULL;
    int eval_int;

    PHALCON_MM_GROW();

    phalcon_get_global(&g0, SL("_SERVER")+1 TSRMLS_CC);
    PHALCON_CPY_WRT(server, g0);
    eval_int = phalcon_array_isset_string(server, SS("HTTP_SOAPACTION"));
    if (eval_int) {
        PHALCON_MM_RESTORE();
        RETURN_TRUE;
    } else {
        eval_int = phalcon_array_isset_string(server, SS("CONTENT_TYPE"));
        if (eval_int) {
            PHALCON_INIT_VAR(content_type);
            phalcon_array_fetch_string(&content_type, server, SL("CONTENT_TYPE"), PH_NOISY_CC);
            if (phalcon_memnstr_str(content_type, SL("application/soap+xml") TSRMLS_CC)) {
                PHALCON_MM_RESTORE();
                RETURN_TRUE;
            }
        }
    }

    PHALCON_MM_RESTORE();
    RETURN_FALSE;
}
Exemple #4
0
/**
 * Checks whether request has been made using SOAP
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Request, isSoapRequested){

	zval *g0 = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL;
	zval *c0 = NULL;
	zval *t0 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	phalcon_get_global(&g0, "_SERVER", sizeof("_SERVER") TSRMLS_CC);
	eval_int = phalcon_array_isset_string(g0, "HTTP_SOAPACTION", strlen("HTTP_SOAPACTION")+1);
	if (eval_int) {
		PHALCON_MM_RESTORE();
		RETURN_TRUE;
	} else {
		eval_int = phalcon_array_isset_string(g0, "CONTENT_TYPE", strlen("CONTENT_TYPE")+1);
		if (eval_int) {
			PHALCON_ALLOC_ZVAL_MM(r0);
			PHALCON_ALLOC_ZVAL_MM(r1);
			phalcon_array_fetch_string(&r1, g0, "CONTENT_TYPE", strlen("CONTENT_TYPE"), PHALCON_NOISY TSRMLS_CC);
			PHALCON_INIT_VAR(c0);
			ZVAL_STRING(c0, "application/soap+xml", 1);
			PHALCON_CALL_FUNC_PARAMS_2(r0, "strpos", r1, c0, 0x00E);
			PHALCON_INIT_VAR(t0);
			ZVAL_BOOL(t0, 0);
			PHALCON_INIT_VAR(r2);
			is_not_identical_function(r2, t0, r0 TSRMLS_CC);
			
			PHALCON_RETURN_NCTOR(r2);
		}
	}
	PHALCON_MM_RESTORE();
	RETURN_FALSE;
}
Exemple #5
0
/**
 * Phalcon\Mvc\Model\MetaData\Apc constructor
 *
 * @param array $options
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, __construct){

	zval *options = NULL, *prefix, *ttl, *empty_array;

	PHALCON_MM_GROW();

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

	if (!options) {
		PHALCON_INIT_VAR(options);
	}
	
	if (Z_TYPE_P(options) == IS_ARRAY) { 
		if (phalcon_array_isset_string(options, SS("prefix"))) {
			PHALCON_OBS_VAR(prefix);
			phalcon_array_fetch_string(&prefix, options, SL("prefix"), PH_NOISY_CC);
			phalcon_update_property_this(this_ptr, SL("_prefix"), prefix TSRMLS_CC);
		}
		if (phalcon_array_isset_string(options, SS("lifetime"))) {
			PHALCON_OBS_VAR(ttl);
			phalcon_array_fetch_string(&ttl, options, SL("lifetime"), PH_NOISY_CC);
			phalcon_update_property_this(this_ptr, SL("_ttl"), ttl TSRMLS_CC);
		}
	}
	
	PHALCON_INIT_VAR(empty_array);
	array_init(empty_array);
	phalcon_update_property_this(this_ptr, SL("_metaData"), empty_array TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #6
0
/**
 * Phalcon\Mvc\Model\MetaData\Xcache constructor
 *
 * @param array $options
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Xcache, __construct){

	zval *options = NULL, *prefix, *ttl, *empty_array;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &options);
	
	if (!options) {
		PHALCON_INIT_VAR(options);
	}
	
	if (Z_TYPE_P(options) == IS_ARRAY) { 
		if (phalcon_array_isset_string(options, SS("prefix"))) {
			PHALCON_OBS_VAR(prefix);
			phalcon_array_fetch_string(&prefix, options, SL("prefix"), PH_NOISY);
			phalcon_update_property_this(this_ptr, SL("_prefix"), prefix TSRMLS_CC);
		}
		if (phalcon_array_isset_string(options, SS("lifetime"))) {
			PHALCON_OBS_VAR(ttl);
			phalcon_array_fetch_string(&ttl, options, SL("lifetime"), PH_NOISY);
			phalcon_update_property_this(this_ptr, SL("_ttl"), ttl TSRMLS_CC);
		}
	}
	
	PHALCON_INIT_VAR(empty_array);
	array_init(empty_array);
	phalcon_update_property_this(this_ptr, SL("_metaData"), empty_array TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #7
0
/**
 * Gets most possibly client IPv4 Address. This methods search in $_SERVER['HTTP_X_FORWARDED_FOR'] and $_SERVER['REMOTE_ADDR']
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getClientAddress){

	zval *address = NULL, *server = NULL;
	zval *g0 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_INIT_VAR(address);
	ZVAL_STRING(address, "", 1);
	phalcon_get_global(&g0, SL("_SERVER")+1 TSRMLS_CC);
	PHALCON_CPY_WRT(server, g0);
	eval_int = phalcon_array_isset_string(server, SL("HTTP_X_FORWARDED_FOR")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(address);
		phalcon_array_fetch_string(&address, server, SL("HTTP_X_FORWARDED_FOR"), PH_NOISY_CC);
	} else {
		eval_int = phalcon_array_isset_string(server, SL("REMOTE_ADDR")+1);
		if (eval_int) {
			PHALCON_INIT_VAR(address);
			phalcon_array_fetch_string(&address, server, SL("REMOTE_ADDR"), PH_NOISY_CC);
		}
	}
	
	
	RETURN_CCTOR(address);
}
Exemple #8
0
/**
 * Restore a Phalcon\Db\Index object from export
 *
 * @param array $data
 * @return Phalcon\Db\IndexInterface
 */
PHP_METHOD(Phalcon_Db_Index, __set_state){

	zval *data, *index_name, *columns, *index;

	PHALCON_MM_GROW();

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

	if (!phalcon_array_isset_string(data, SS("_indexName"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_indexName parameter is required");
		return;
	}
	if (!phalcon_array_isset_string(data, SS("_columns"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_columns parameter is required");
		return;
	}
	
	PHALCON_OBS_VAR(index_name);
	phalcon_array_fetch_string(&index_name, data, SL("_indexName"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(columns);
	phalcon_array_fetch_string(&columns, data, SL("_columns"), PH_NOISY_CC);
	
	/** 
	 * Return a Phalcon\Db\Index as part of the returning state
	 */
	PHALCON_INIT_VAR(index);
	object_init_ex(index, phalcon_db_index_ce);
	PHALCON_CALL_METHOD_PARAMS_2_NORETURN(index, "__construct", index_name, columns);
	
	
	RETURN_CTOR(index);
}
Exemple #9
0
/**
 * Phalcon\Http\Request\File constructor
 *
 * @param array $file
 */
PHP_METHOD(Phalcon_Http_Request_File, __construct){

	zval *file, *name, *temp_name, *size, *type, *error, *key = NULL;
	zval *constant, *extension = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &file, &key);
	
	if (Z_TYPE_P(file) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "Phalcon\\Http\\Request\\File requires a valid uploaded file");
		return;
	}
	if (phalcon_array_isset_string(file, SS("name"))) {
		PHALCON_OBS_VAR(name);
		phalcon_array_fetch_string(&name, file, SL("name"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC);

		PHALCON_INIT_VAR(constant);
		if (zend_get_constant(SL("PATHINFO_EXTENSION"), constant TSRMLS_CC)) {
			PHALCON_CALL_FUNCTION(&extension, "pathinfo", name, constant);
			phalcon_update_property_this(this_ptr, SL("_extension"), extension TSRMLS_CC);
		}
	}
	
	if (phalcon_array_isset_string(file, SS("tmp_name"))) {
		PHALCON_OBS_VAR(temp_name);
		phalcon_array_fetch_string(&temp_name, file, SL("tmp_name"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_tmp"), temp_name TSRMLS_CC);
	} else {
		PHALCON_INIT_VAR(temp_name);
		ZVAL_NULL(temp_name);
 	}
	
	if (phalcon_array_isset_string(file, SS("size"))) {
		PHALCON_OBS_VAR(size);
		phalcon_array_fetch_string(&size, file, SL("size"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_size"), size TSRMLS_CC);
	}
	
	if (phalcon_array_isset_string(file, SS("type"))) {
		PHALCON_OBS_VAR(type);
		phalcon_array_fetch_string(&type, file, SL("type"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_type"), type TSRMLS_CC);
	}

	if (phalcon_array_isset_string(file, SS("error"))) {
		PHALCON_OBS_VAR(error);
		phalcon_array_fetch_string(&error, file, SL("error"), PH_NOISY);
		phalcon_update_property_this(this_ptr, SL("_error"), error TSRMLS_CC);
	}

	if (key) {
		phalcon_update_property_this(this_ptr, SL("_key"), key TSRMLS_CC);
	}

	PHALCON_CALL_PARENT(NULL, phalcon_http_request_file_ce, this_ptr, "__construct", temp_name);

	PHALCON_MM_RESTORE();
}
Exemple #10
0
/**
 * Phalcon\Cache\Backend\Mongo constructor
 *
 * @param Phalcon\Cache\FrontendInterface $frontend
 * @param array $options
 */
PHP_METHOD(Phalcon_Cache_Backend_Mongo, __construct){

	zval *frontend, *options = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &frontend, &options);

	if (!options) {
		options = PHALCON_GLOBAL(z_null);
	}
	
	if (!phalcon_array_isset_string(options, SS("mongo"))) {
		if (!phalcon_array_isset_string(options, SS("server"))) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'server' is required");
			return;
		}
	}

	if (!phalcon_array_isset_string(options, SS("db"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'db' is required");
		return;
	}

	if (!phalcon_array_isset_string(options, SS("collection"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'collection' is required");
		return;
	}

	PHALCON_CALL_PARENT(NULL, phalcon_cache_backend_mongo_ce, this_ptr, "__construct", frontend, options);

	PHALCON_MM_RESTORE();
}
Exemple #11
0
/**
 * Phalcon_Paginator_Adapter_Model constructor
 *
 * @param array $config
 */
PHP_METHOD(Phalcon_Paginator_Adapter_Model, __construct){

	zval *v0 = NULL;
	zval *r0 = NULL, *r1 = NULL;
	int eval_int;

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

	
	phalcon_update_property_zval(this_ptr, "_config", strlen("_config"), v0 TSRMLS_CC);
	eval_int = phalcon_array_isset_string(v0, "limit", strlen("limit")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r0);
		phalcon_array_fetch_string(&r0, v0, "limit", strlen("limit"), PHALCON_NOISY_FETCH TSRMLS_CC);
		phalcon_update_property_zval(this_ptr, "_limitRows", strlen("_limitRows"), r0 TSRMLS_CC);
	}
	eval_int = phalcon_array_isset_string(v0, "page", strlen("page")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r1);
		phalcon_array_fetch_string(&r1, v0, "page", strlen("page"), PHALCON_NOISY_FETCH TSRMLS_CC);
		phalcon_update_property_zval(this_ptr, "_page", strlen("_page"), r1 TSRMLS_CC);
	}
	PHALCON_MM_RESTORE();
	RETURN_NULL();
}
Exemple #12
0
/**
 * Restore a Phalcon\Db\Index object from export
 *
 * @param array $data
 * @return Phalcon\Db\Index
 */
PHP_METHOD(Phalcon_Db_Index, __set_state){

	zval *data = NULL, *index_name = NULL, *columns = NULL, *index = NULL;
	int eval_int;

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

	eval_int = phalcon_array_isset_string(data, SL("_indexName")+1);
	if (!eval_int) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_indexName parameter is required");
		return;
	}
	eval_int = phalcon_array_isset_string(data, SL("_columns")+1);
	if (!eval_int) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_columns parameter is required");
		return;
	}
	
	PHALCON_INIT_VAR(index_name);
	phalcon_array_fetch_string(&index_name, data, SL("_indexName"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(columns);
	phalcon_array_fetch_string(&columns, data, SL("_columns"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(index);
	object_init_ex(index, phalcon_db_index_ce);
	PHALCON_CALL_METHOD_PARAMS_2_NORETURN(index, "__construct", index_name, columns, PH_CHECK);
	
	RETURN_CTOR(index);
}
Exemple #13
0
/**
 * Phalcon\Paginator\Adapter\Model constructor
 *
 * @param array $config
 */
PHP_METHOD(Phalcon_Paginator_Adapter_Model, __construct){

	zval *config = NULL, *limit = NULL, *page = NULL;
	int eval_int;

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

	phalcon_update_property_zval(this_ptr, SL("_config"), config TSRMLS_CC);
	eval_int = phalcon_array_isset_string(config, SL("limit")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(limit);
		phalcon_array_fetch_string(&limit, config, SL("limit"), PH_NOISY_CC);
		phalcon_update_property_zval(this_ptr, SL("_limitRows"), limit TSRMLS_CC);
	}
	
	eval_int = phalcon_array_isset_string(config, SL("page")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(page);
		phalcon_array_fetch_string(&page, config, SL("page"), PH_NOISY_CC);
		phalcon_update_property_zval(this_ptr, SL("_page"), page TSRMLS_CC);
	}
	
	PHALCON_MM_RESTORE();
}
Exemple #14
0
/**
 * Handles routing information received from command-line arguments
 *
 * @param array $arguments
 */
PHP_METHOD(Phalcon_CLI_Router, handle){

	zval *arguments = NULL, *module_name = NULL, *task_name = NULL, *action_name = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &arguments);
	
	if (!arguments) {
		PHALCON_INIT_VAR(arguments);
		array_init(arguments);
	} else {
		PHALCON_SEPARATE_PARAM(arguments);
	}
	
	if (Z_TYPE_P(arguments) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_cli_router_exception_ce, "Arguments must be an Array");
		return;
	}
	
	PHALCON_INIT_VAR(module_name);
	
	PHALCON_INIT_VAR(task_name);
	
	PHALCON_INIT_VAR(action_name);
	
	/** 
	 * Check for a module
	 */
	if (phalcon_array_isset_string(arguments, SS("module"))) {
		PHALCON_OBS_NVAR(module_name);
		phalcon_array_fetch_string(&module_name, arguments, SL("module"), PH_NOISY);
		phalcon_array_unset_string(&arguments, SS("module"), PH_SEPARATE);
	}
	
	/** 
	 * Check for a task
	 */
	if (phalcon_array_isset_string(arguments, SS("task"))) {
		PHALCON_OBS_NVAR(task_name);
		phalcon_array_fetch_string(&task_name, arguments, SL("task"), PH_NOISY);
		phalcon_array_unset_string(&arguments, SS("task"), PH_SEPARATE);
	}
	
	/** 
	 * Check for an action
	 */
	if (phalcon_array_isset_string(arguments, SS("action"))) {
		PHALCON_OBS_NVAR(action_name);
		phalcon_array_fetch_string(&action_name, arguments, SL("action"), PH_NOISY);
		phalcon_array_unset_string(&arguments, SS("action"), PH_SEPARATE);
	}
	
	phalcon_update_property_this(this_ptr, SL("_module"), module_name TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_task"), task_name TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_action"), action_name TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_params"), arguments TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #15
0
/**
 * Gets most possible client IPv4 Address. This method search in $_SERVER['REMOTE_ADDR'] and optionally in $_SERVER['HTTP_X_FORWARDED_FOR']
 *
 * @param boolean $trustForwardedHeader
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getClientAddress){

	zval *trust_forwarded_header = NULL, *address = NULL, *_SERVER;
	zval *comma, *addresses, *first;

	PHALCON_MM_GROW();

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

	if (!trust_forwarded_header) {
		PHALCON_INIT_VAR(trust_forwarded_header);
		ZVAL_BOOL(trust_forwarded_header, 0);
	}
	
	PHALCON_INIT_VAR(address);
	
	/** 
	 * Proxies uses this IP
	 */
	phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC);
	if (phalcon_array_isset_string(_SERVER, SS("HTTP_X_FORWARDED_FOR"))) {
		if (zend_is_true(trust_forwarded_header)) {
			PHALCON_OBS_NVAR(address);
			phalcon_array_fetch_string(&address, _SERVER, SL("HTTP_X_FORWARDED_FOR"), PH_NOISY_CC);
		}
	}
	
	if (Z_TYPE_P(address) == IS_NULL) {
		if (phalcon_array_isset_string(_SERVER, SS("REMOTE_ADDR"))) {
			PHALCON_OBS_NVAR(address);
			phalcon_array_fetch_string(&address, _SERVER, SL("REMOTE_ADDR"), PH_NOISY_CC);
		}
	}
	
	if (Z_TYPE_P(address) == IS_STRING) {
		if (phalcon_memnstr_str(address, SL(",") TSRMLS_CC)) {
			/** 
			 * The client address has multiples parts, only return the first part
			 */
			PHALCON_INIT_VAR(comma);
			ZVAL_STRING(comma, ",", 1);
	
			PHALCON_INIT_VAR(addresses);
			phalcon_fast_explode(addresses, comma, address TSRMLS_CC);
	
			PHALCON_OBS_VAR(first);
			phalcon_array_fetch_long(&first, addresses, 0, PH_NOISY_CC);
			RETURN_CCTOR(first);
		}
	
		RETURN_CCTOR(address);
	}
	
	RETURN_MM_FALSE;
}
Exemple #16
0
/**
 * Restore a Phalcon\Db\Reference object from export
 *
 * @param array $data
 * @return Phalcon\Db\Reference
 */
PHP_METHOD(Phalcon_Db_Reference, __set_state){

	zval *data, *constraint_name, *referenced_schema = NULL;
	zval *referenced_table = NULL, *columns = NULL, *referenced_columns = NULL;
	zval *definition;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &data);
	
	if (!phalcon_array_isset_string(data, SS("_referenceName"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_referenceName parameter is required");
		return;
	} else {
		PHALCON_OBS_VAR(constraint_name);
		phalcon_array_fetch_string(&constraint_name, data, SL("_referenceName"), PH_NOISY);
	}
	if (phalcon_array_isset_string(data, SS("_referencedSchema"))) {
		PHALCON_OBS_VAR(referenced_schema);
		phalcon_array_fetch_string(&referenced_schema, data, SL("_referencedSchema"), PH_NOISY);
	} else {
		PHALCON_INIT_NVAR(referenced_schema);
	}
	
	if (phalcon_array_isset_string(data, SS("_referencedTable"))) {
		PHALCON_OBS_VAR(referenced_table);
		phalcon_array_fetch_string(&referenced_table, data, SL("_referencedTable"), PH_NOISY);
	} else {
		PHALCON_INIT_NVAR(referenced_table);
	}
	
	if (phalcon_array_isset_string(data, SS("_columns"))) {
		PHALCON_OBS_VAR(columns);
		phalcon_array_fetch_string(&columns, data, SL("_columns"), PH_NOISY);
	} else {
		PHALCON_INIT_NVAR(columns);
	}
	
	if (phalcon_array_isset_string(data, SS("_referencedColumns"))) {
		PHALCON_OBS_VAR(referenced_columns);
		phalcon_array_fetch_string(&referenced_columns, data, SL("_referencedColumns"), PH_NOISY);
	} else {
		PHALCON_INIT_NVAR(referenced_columns);
	}
	
	PHALCON_INIT_VAR(definition);
	array_init_size(definition, 4);
	phalcon_array_update_string(&definition, SL("referencedSchema"), &referenced_schema, PH_COPY | PH_SEPARATE);
	phalcon_array_update_string(&definition, SL("referencedTable"), &referenced_table, PH_COPY | PH_SEPARATE);
	phalcon_array_update_string(&definition, SL("columns"), &columns, PH_COPY | PH_SEPARATE);
	phalcon_array_update_string(&definition, SL("referencedColumns"), &referenced_columns, PH_COPY | PH_SEPARATE);
	object_init_ex(return_value, phalcon_db_reference_ce);
	phalcon_call_method_p2_noret(return_value, "__construct", constraint_name, definition);
	
	RETURN_MM();
}
Exemple #17
0
/**
 * Phalcon\Translate\Adapter\NativeArray constructor
 *
 * @param array $data
 */
PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, __construct){

	zval *options = NULL, *data = NULL;
	int eval_int;

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

	eval_int = phalcon_array_isset_string(options, SL("content")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(data);
		phalcon_array_fetch_string(&data, options, SL("content"), PH_NOISY_CC);
		if (Z_TYPE_P(data) != IS_ARRAY) { 
			PHALCON_THROW_EXCEPTION_STR(phalcon_translate_exception_ce, "Translation data must be an array");
			return;
		}
	} else {
		PHALCON_THROW_EXCEPTION_STR(phalcon_translate_exception_ce, "Translation content was not provided");
		return;
	}
	phalcon_update_property_zval(this_ptr, SL("_translate"), data TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #18
0
/**
 * Phalcon_Cache_Backend constructor
 *
 * @param mixed $frontendObject
 * @param array $backendOptions
 */
PHP_METHOD(Phalcon_Cache_Backend, __construct){

	zval *frontend_object = NULL, *backend_options = NULL;
	zval *a0 = NULL;
	zval *r0 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	
	PHALCON_INIT_VAR(a0);
	array_init(a0);
	zend_update_property(phalcon_cache_backend_ce, this_ptr, SL("_backendOptions"), a0 TSRMLS_CC);
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &frontend_object, &backend_options) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	eval_int = phalcon_array_isset_string(backend_options, SL("prefix")+1);
	if (eval_int) {
		PHALCON_ALLOC_ZVAL_MM(r0);
		phalcon_array_fetch_string(&r0, backend_options, SL("prefix"), PHALCON_NOISY TSRMLS_CC);
		phalcon_update_property_zval(this_ptr, SL("_prefix"), r0 TSRMLS_CC);
	}
	phalcon_update_property_zval(this_ptr, SL("_frontendObject"), frontend_object TSRMLS_CC);
	phalcon_update_property_zval(this_ptr, SL("_backendOptions"), backend_options TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #19
0
/**
 * Phalcon\Translate\Adapter\NativeArray constructor
 *
 * @param array $options
 */
PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, __construct){

	zval *options, *data;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &options);
	
	if (Z_TYPE_P(options) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_translate_exception_ce, "Invalid options");
		return;
	}
	if (!phalcon_array_isset_string(options, SS("content"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_translate_exception_ce, "Translation content was not provided");
		return;
	}
	
	PHALCON_OBS_VAR(data);
	phalcon_array_fetch_string(&data, options, SL("content"), PH_NOISY);
	if (Z_TYPE_P(data) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_translate_exception_ce, "Translation data must be an array");
		return;
	}
	
	phalcon_update_property_this(this_ptr, SL("_translate"), data TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #20
0
/**
 * Phalcon\Cache\Backend constructor
 *
 * @param Phalcon\Cache\FrontendInterface $frontend
 * @param array $options
 */
PHP_METHOD(Phalcon_Cache_Backend, __construct){

	zval *frontend, *options = NULL, *prefix;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &frontend, &options);
	
	if (!options) {
		PHALCON_INIT_VAR(options);
	}
	
	if (Z_TYPE_P(frontend) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Frontend must be an Object");
		return;
	}
	
	/** 
	 * A common option is the prefix
	 */
	if (phalcon_array_isset_string(options, SS("prefix"))) {
		PHALCON_OBS_VAR(prefix);
		phalcon_array_fetch_string(&prefix, options, SL("prefix"), PH_NOISY_CC);
		phalcon_update_property_this(this_ptr, SL("_prefix"), prefix TSRMLS_CC);
	}
	
	phalcon_update_property_this(this_ptr, SL("_frontend"), frontend TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_options"), options TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #21
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);
}
Exemple #22
0
/**
 * Restores the state of a Phalcon\Annotations\Reflection variable export
 *
 * @return array $data
 */
PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){

	zval *data, *reflection_data, *reflection = NULL;

	PHALCON_MM_GROW();

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

	if (Z_TYPE_P(data) == IS_ARRAY) { 
	
		/** 
		 * Check for a '_reflectionData' in the array to build the Reflection
		 */
		if (phalcon_array_isset_string(data, SS("_reflectionData"))) {
			PHALCON_OBS_VAR(reflection_data);
			phalcon_array_fetch_string(&reflection_data, data, SL("_reflectionData"), PH_NOISY_CC);
	
			PHALCON_INIT_VAR(reflection);
			object_init_ex(reflection, phalcon_annotations_reflection_ce);
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(reflection, "__construct", reflection_data);
	
			RETURN_CTOR(reflection);
		}
	}
	
	PHALCON_INIT_NVAR(reflection);
	object_init_ex(reflection, phalcon_annotations_reflection_ce);
	PHALCON_CALL_METHOD_NORETURN(reflection, "__construct");
	
	
	RETURN_CTOR(reflection);
}
Exemple #23
0
/**
 * Returns the annotations found in the class docblock
 *
 * @return Phalcon\Annotations\Collection
 */
PHP_METHOD(Phalcon_Annotations_Reflection, getClassAnnotations){

	zval *annotations, *reflection_data, *reflection_class;
	zval *collection;

	PHALCON_MM_GROW();

	PHALCON_OBS_VAR(annotations);
	phalcon_read_property(&annotations, this_ptr, SL("_classAnnotations"), 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("class"))) {
			PHALCON_OBS_VAR(reflection_class);
			phalcon_array_fetch_string(&reflection_class, reflection_data, SL("class"), PH_NOISY_CC);
	
			PHALCON_INIT_VAR(collection);
			object_init_ex(collection, phalcon_annotations_collection_ce);
			PHALCON_CALL_METHOD_PARAMS_1_NORETURN(collection, "__construct", reflection_class);
	
			phalcon_update_property_zval(this_ptr, SL("_classAnnotations"), collection TSRMLS_CC);
			RETURN_CTOR(collection);
		}
	
		phalcon_update_property_bool(this_ptr, SL("_classAnnotations"), 0 TSRMLS_CC);
		RETURN_MM_FALSE;
	}
	
	
	RETURN_CCTOR(annotations);
}
Exemple #24
0
/**
 * Sets session options
 *
 * @param array $options
 */
PHP_METHOD(Phalcon_Session, setOptions){

	zval *options, *unique_id;
	int eval_int;

	PHALCON_MM_GROW();

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

	if (Z_TYPE_P(options) == IS_ARRAY) { 
		eval_int = phalcon_array_isset_string(options, SS("uniqueId"));
		if (eval_int) {
			PHALCON_INIT_VAR(unique_id);
			phalcon_array_fetch_string(&unique_id, options, SL("uniqueId"), PH_NOISY_CC);
			phalcon_update_property_zval(this_ptr, SL("_uniqueId"), unique_id TSRMLS_CC);
		}
		phalcon_update_property_zval(this_ptr, SL("_options"), options TSRMLS_CC);
	} else {
		PHALCON_THROW_EXCEPTION_STR(phalcon_session_exception_ce, "Options must be an Array");
		return;
	}
	
	PHALCON_MM_RESTORE();
}
Exemple #25
0
/**
 * Restores the state of a Phalcon\Annotations\Reflection variable export
 *
 * @return array $data
 */
PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){

	zval *data, *reflection_data, *reflection = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &data);
	
	if (Z_TYPE_P(data) == IS_ARRAY) { 
	
		/** 
		 * Check for a '_reflectionData' in the array to build the Reflection
		 */
		if (phalcon_array_isset_string(data, SS("_reflectionData"))) {
			PHALCON_OBS_VAR(reflection_data);
			phalcon_array_fetch_string(&reflection_data, data, SL("_reflectionData"), PH_NOISY_CC);
	
			PHALCON_INIT_VAR(reflection);
			object_init_ex(reflection, phalcon_annotations_reflection_ce);
			phalcon_call_method_p1_noret(reflection, "__construct", reflection_data);
	
			RETURN_CTOR(reflection);
		}
	}
	
	PHALCON_INIT_NVAR(reflection);
	object_init_ex(reflection, phalcon_annotations_reflection_ce);
	phalcon_call_method_noret(reflection, "__construct");
	
	RETURN_CTOR(reflection);
}
Exemple #26
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_Sqlite, connect){

	zval *descriptor = NULL, *dbname;

	PHALCON_MM_GROW();

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

	if (!descriptor) {
		PHALCON_INIT_VAR(descriptor);
	} else {
		PHALCON_SEPARATE_PARAM(descriptor);
	}
	
	if (!zend_is_true(descriptor)) {
		PHALCON_OBS_NVAR(descriptor);
		phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC);
	}
	if (!phalcon_array_isset_string(descriptor, SS("dbname"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "dbname must be specified");
		return;
	} else {
		PHALCON_OBS_VAR(dbname);
		phalcon_array_fetch_string(&dbname, descriptor, SL("dbname"), PH_NOISY_CC);
		phalcon_array_update_string(&descriptor, SL("dsn"), &dbname, PH_COPY | PH_SEPARATE TSRMLS_CC);
	}
	
	PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Sqlite", "connect", descriptor);
	
	PHALCON_MM_RESTORE();
}
Exemple #27
0
/**
 * Opens the internal file handler after unserialization
 *
 */
PHP_METHOD(Phalcon_Logger_Adapter_File, __wakeup){

	zval *path = NULL, *options = NULL, *mode = NULL, *file_handler = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_INIT_VAR(path);
	phalcon_read_property(&path, this_ptr, SL("_path"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(options);
	phalcon_read_property(&options, this_ptr, SL("_options"), PH_NOISY_CC);
	eval_int = phalcon_array_isset_string(options, SL("mode")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(mode);
		phalcon_array_fetch_string(&mode, options, SL("mode"), PH_NOISY_CC);
	} else {
		PHALCON_INIT_VAR(mode);
		ZVAL_STRING(mode, "ab", 1);
	}
	
	PHALCON_INIT_VAR(file_handler);
	PHALCON_CALL_FUNC_PARAMS_2(file_handler, "fopen", path, mode);
	phalcon_update_property_zval(this_ptr, SL("_fileHandler"), file_handler TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #28
0
/**
 * Phalcon\Cache\Backend\Xcache constructor
 *
 * @param Phalcon\Cache\FrontendInterface $frontend
 * @param array $options
 */
PHP_METHOD(Phalcon_Cache_Backend_Xcache, __construct){

	zval *frontend, *options = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &frontend, &options);
	
	if (!options) {
		PHALCON_INIT_VAR(options);
	} else {
		PHALCON_SEPARATE_PARAM(options);
	}
	
	if (Z_TYPE_P(options) != IS_ARRAY) { 
		PHALCON_INIT_NVAR(options);
		array_init(options);
	}
	if (!phalcon_array_isset_string(options, SS("statsKey"))) {
		phalcon_array_update_string_string(&options, SL("statsKey"), SL("_PHCX"), PH_SEPARATE TSRMLS_CC);
	}
	
	PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Xcache", "__construct", frontend, options);
	
	PHALCON_MM_RESTORE();
}
Exemple #29
0
/**
 * Generates SQL to create a view
 *
 * @param string $viewName
 * @param array $definition
 * @param string $schemaName
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){

	zval *view_name, *definition, *schema_name, *view_sql;
	zval *view = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name);
	
	if (!phalcon_array_isset_string(definition, SS("sql"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array");
		return;
	}
	
	PHALCON_OBS_VAR(view_sql);
	phalcon_array_fetch_string(&view_sql, definition, SL("sql"), PH_NOISY);
	if (zend_is_true(schema_name)) {
		PHALCON_INIT_VAR(view);
		PHALCON_CONCAT_VSV(view, view_name, ".", schema_name);
	} else {
		PHALCON_CPY_WRT(view, view_name);
	}
	
	PHALCON_CONCAT_SVSV(return_value, "CREATE VIEW ", view, " AS ", view_sql);
	
	PHALCON_MM_RESTORE();
}
Exemple #30
0
/**
 * Gets active server address IP
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getServerAddress){

	zval *server = NULL, *server_addr = NULL, *localhost = NULL;
	zval *g0 = NULL;
	int eval_int;

	PHALCON_MM_GROW();
	phalcon_get_global(&g0, SL("_SERVER")+1 TSRMLS_CC);
	PHALCON_CPY_WRT(server, g0);
	eval_int = phalcon_array_isset_string(server, SL("SERVER_ADDR")+1);
	if (eval_int) {
		PHALCON_INIT_VAR(server_addr);
		phalcon_array_fetch_string(&server_addr, server, SL("SERVER_ADDR"), PH_NOISY_CC);
		
		RETURN_CCTOR(server_addr);
	}
	
	PHALCON_INIT_VAR(localhost);
	ZVAL_STRING(localhost, "localhost", 1);
	
	PHALCON_INIT_VAR(server_addr);
	PHALCON_CALL_FUNC_PARAMS_1(server_addr, "gethostbyname", localhost);
	
	RETURN_CCTOR(server_addr);
}