Exemple #1
0
/**
 * 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);
}
Exemple #2
0
/**
 * Gets the column name in MySQL
 *
 * @param Phalcon\Db\ColumnInterface $column
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){

	zval *column, size = {}, column_type = {}, column_sql = {}, type_values = {}, slash = {}, *value, value_cslashes = {}, is_unsigned = {}, scale = {}, name = {};
	int c, i = 0;

	phalcon_fetch_params(0, 1, 0, &column);
	PHALCON_VERIFY_INTERFACE_EX(column, phalcon_db_columninterface_ce, phalcon_db_exception_ce, 0);

	PHALCON_CALL_METHODW(&size, column, "getsize");
	PHALCON_CALL_METHODW(&column_type, column, "gettype");

	if (Z_TYPE(column_type) == IS_STRING) {
		PHALCON_CPY_WRT(&column_sql, &column_type);
		PHALCON_CALL_METHODW(&type_values, column, "gettypevalues");
		if (PHALCON_IS_NOT_EMPTY(&type_values)) {
			ZVAL_STRING(&slash, "\"");
			if (Z_TYPE(type_values) == IS_ARRAY) {
				c = phalcon_fast_count_int(&type_values);
				phalcon_concat_self_str(&column_sql, SL("("));
				ZEND_HASH_FOREACH_VAL(Z_ARRVAL(type_values), value) {
					i++;
					PHALCON_CALL_FUNCTIONW(&value_cslashes, "addcslashes", value, &slash);
					if (i < c) {
						PHALCON_SCONCAT_SVS(&column_sql, "\"", &value_cslashes, "\", ");
					} else {
						PHALCON_SCONCAT_SVS(&column_sql, "\"", &value_cslashes, "\"");
					}
				} ZEND_HASH_FOREACH_END();
Exemple #3
0
/**
 * Create a new Query Builder for Delete
 *
 *
 * @return Phalcon\Mvc\Model\Query\Builder\Delete
 */
PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, createDeleteBuilder){

	zval *params = NULL, *_di = NULL, di = {}, service_name = {};

	phalcon_fetch_params(0, 0, 2, &params, &_di);

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

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

	if (Z_TYPE_P(_di) == IS_OBJECT) {
		PHALCON_VERIFY_INTERFACEW(_di, phalcon_diinterface_ce);
		PHALCON_CPY_WRT(&di, _di);
	} else {
		PHALCON_CALL_CE_STATICW(&di, phalcon_di_ce, "getdefault", _di);
	}

	PHALCON_STR(&service_name, ISV(modelsQueryBuilderForDelete));
	PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, &PHALCON_GLOBAL(z_null), &PHALCON_GLOBAL(z_true));
	if (Z_TYPE_P(return_value) != IS_OBJECT) {
		object_init_ex(return_value, phalcon_mvc_model_query_builder_delete_ce);
		PHALCON_CALL_METHODW(NULL, return_value, "__construct", params);
	}

	PHALCON_VERIFY_INTERFACEW(return_value, phalcon_mvc_model_query_builderinterface_ce);
}
Exemple #4
0
/**
 * Checks whether put has certain index
 *
 * @param string $name
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request, hasPut)
{
	zval *name, is_put = {}, put = {}, raw = {}, new_put = {};
	char *tmp;

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

	PHALCON_CALL_METHODW(&is_put, getThis(), "isput");

	if (!zend_is_true(&is_put)) {
		phalcon_read_global_str(&new_put, SL("_PUT"));
	} else {
		phalcon_read_property(&put, getThis(), SL("_put"), PH_NOISY);
		if (Z_TYPE(put) != IS_ARRAY) {
			PHALCON_CALL_METHODW(&raw, getThis(), "getrawbody");

			array_init(&new_put);

			PHALCON_ENSURE_IS_STRING(&raw);
			tmp = estrndup(Z_STRVAL(raw), Z_STRLEN(raw));
			sapi_module.treat_data(PARSE_STRING, tmp, &new_put);

			phalcon_update_property_zval(getThis(), SL("_put"), &new_put);
		} else {
			PHALCON_CPY_WRT(&new_put, &put);
		}
	}

	RETVAL_BOOL(phalcon_array_isset(&new_put, name));
}
Exemple #5
0
/**
 * Starts the profile of a SQL sentence
 *
 * @param string $sqlStatement
 * @param $sqlVariables
 * @param $sqlBindTypes
 * @return Phalcon\Db\Profiler
 */
PHP_METHOD(Phalcon_Db_Profiler, startProfile){

	zval *sql_statement, *sql_variables = NULL, *sql_bindtypes = NULL, active_profile = {}, time = {};

	phalcon_fetch_params(0, 1, 2, &sql_statement, &sql_variables, &sql_bindtypes);

	object_init_ex(&active_profile, phalcon_db_profiler_item_ce);
	PHALCON_CALL_METHODW(NULL, &active_profile, "setsqlstatement", sql_statement);

	if (sql_variables) {
	    PHALCON_CALL_METHODW(NULL, &active_profile, "setsqlvariables", sql_variables);
	}

	if (sql_bindtypes) {
	    PHALCON_CALL_METHODW(NULL, &active_profile, "setsqlbindtypes", sql_bindtypes);
	}

	PHALCON_CALL_FUNCTIONW(&time, "microtime", &PHALCON_GLOBAL(z_true));
	PHALCON_CALL_METHODW(NULL, &active_profile, "setinitialtime", &time);

	if (phalcon_method_exists_ex(getThis(), SL("beforestartprofile")) == SUCCESS) {
		PHALCON_CALL_METHODW(NULL, getThis(), "beforestartprofile", &active_profile);
	}

	phalcon_update_property_zval(getThis(), SL("_activeProfile"), &active_profile);

	RETURN_THISW();
}
Exemple #6
0
/**
 * Stops the active profile
 *
 * @return Phalcon\Db\Profiler
 */
PHP_METHOD(Phalcon_Db_Profiler, stopProfile){

	zval active_profile = {}, final_time = {}, initial_time = {}, difference = {}, total_seconds = {}, new_total_seconds = {};

	phalcon_read_property(&active_profile, getThis(), SL("_activeProfile"), PH_NOISY);

	PHALCON_CALL_FUNCTIONW(&final_time, "microtime", &PHALCON_GLOBAL(z_true));
	PHALCON_CALL_METHODW(NULL, &active_profile, "setfinaltime", &final_time);

	PHALCON_CALL_METHODW(&initial_time, &active_profile, "getinitialtime");

	phalcon_sub_function(&difference, &final_time, &initial_time);

	phalcon_read_property(&total_seconds, getThis(), SL("_totalSeconds"), PH_NOISY);

	phalcon_add_function(&new_total_seconds, &total_seconds, &difference);

	phalcon_update_property_zval(getThis(), SL("_totalSeconds"), &new_total_seconds);
	phalcon_update_property_array_append(getThis(), SL("_allProfiles"), &active_profile);

	if (phalcon_method_exists_ex(getThis(), SL("afterendprofile")) == SUCCESS) {
		PHALCON_CALL_METHODW(NULL, getThis(), "afterendprofile", &active_profile);
	}

	RETURN_THISW();
}
Exemple #7
0
/**
 * Gets a param by its name or numeric index
 *
 * @param  mixed $param
 * @param  string|array $filters
 * @param  mixed $defaultValue
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, getParam){

	zval *param, *filters = NULL, *default_value = NULL, dependency_injector = {}, service = {}, dispatcher = {};

	phalcon_fetch_params(0, 1, 2, &param, &filters, &default_value);

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

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

	PHALCON_CALL_METHODW(&dependency_injector, getThis(), "getdi");
	if (Z_TYPE(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service");
		return;
	}

	PHALCON_STR(&service, ISV(dispatcher));

	PHALCON_CALL_METHODW(&dispatcher, &dependency_injector, "getshared", &service);

	PHALCON_CALL_METHODW(NULL, &dispatcher, "getparam", param, filters, default_value);
}
Exemple #8
0
/**
 * Phalcon\Mvc\Model\Transaction constructor
 *
 * @param Phalcon\DIInterface $dependencyInjector
 * @param boolean $autoBegin
 * @param string $service
 */
PHP_METHOD(Phalcon_Mvc_Model_Transaction, __construct){

	zval *dependency_injector, *auto_begin = NULL, *s = NULL, service = {}, connection = {};

	phalcon_fetch_params(0, 1, 2, &dependency_injector, &auto_begin, &service);

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

	if (!s || Z_TYPE_P(s) != IS_STRING) {
		ZVAL_STRING(&service, "db");
	} else {
		PHALCON_CPY_WRT(&service, s);
	}

	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM");
		return;
	}

	PHALCON_CALL_METHODW(&connection, dependency_injector, "get", &service);

	phalcon_update_property_zval(getThis(), SL("_connection"), &connection);
	if (zend_is_true(auto_begin)) {
		PHALCON_CALL_METHODW(NULL, &connection, "begin");
	}
}
Exemple #9
0
/**
 * Executes the validation
 *
 * @param Phalcon\Validation $validator
 * @param string $attribute
 * @return boolean
 */
PHP_METHOD(Phalcon_Validation_Validator_Between, validate){

	zval *validator, *attribute, value = {}, allow_empty = {}, minimum = {}, maximum = {}, label = {}, pairs = {}, valid = {}, message_str = {}, code = {}, prepared = {}, message = {};
	zend_class_entry *ce = Z_OBJCE_P(getThis());

	phalcon_fetch_params(0, 2, 0, &validator, &attribute);

	PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 0);

	PHALCON_CALL_METHODW(&value, validator, "getvalue", attribute);

	RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&allow_empty, ce, getThis(), ISV(allowEmpty)));
	if (zend_is_true(&allow_empty) && phalcon_validation_validator_isempty_helper(&value)) {
		RETURN_TRUE;
	}

	RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minimum, ce, getThis(), "minimum"));
	RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maximum, ce, getThis(), "maximum"));

	PHALCON_CALL_SELFW(&valid, "valid", &value, &minimum, &maximum);

	if (PHALCON_IS_FALSE(&valid)) {
		RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&label, ce, getThis(), ISV(label)));
		if (!zend_is_true(&label)) {
			PHALCON_CALL_METHODW(&label, validator, "getlabel", attribute);
			if (!zend_is_true(&label)) {
				PHALCON_CPY_WRT_CTOR(&label, attribute);
			}
		}

		array_init_size(&pairs, 3);
		phalcon_array_update_str(&pairs, SL(":field"), &label, PH_COPY);
		phalcon_array_update_str(&pairs, SL(":min"), &minimum, PH_COPY);
		phalcon_array_update_str(&pairs, SL(":max"), &maximum, PH_COPY);

		RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message)));
		if (!zend_is_true(&message_str)) {
			RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "Between"));
		}

		RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&code, ce, getThis(), ISV(code)));
		if (Z_TYPE_P(&code) == IS_NULL) {
			ZVAL_LONG(&code, 0);
		}

		PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs);

		phalcon_validation_message_construct_helper(&message, &prepared, attribute, "Between", &code);

		PHALCON_CALL_METHODW(NULL, validator, "appendmessage", &message);
		RETURN_FALSE;
	}

	RETURN_TRUE;
}
Exemple #10
0
PHP_METHOD(Phalcon_Http_Uri, resolve)
{
	zval *uri, self = {};

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

	object_init_ex(&self, phalcon_http_uri_ce);
	PHALCON_CALL_METHODW(NULL, &self, "__construct", getThis());
	PHALCON_CALL_METHODW(NULL, &self, "extend", uri);

	RETURN_CTORW(&self);
}
Exemple #11
0
/**
 * Gets a variable from put request
 *
 *<code>
 *	$userEmail = $request->getPut("user_email");
 *
 *	$userEmail = $request->getPut("user_email", "email");
 *</code>
 *
 * @param string $name
 * @param string|array $filters
 * @param mixed $defaultValue
 * @param boolean $notAllowEmpty
 * @param boolean $noRecursive
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, getPut)
{
	zval *name = NULL, *filters = NULL, *default_value = NULL, *not_allow_empty = NULL, *norecursive = NULL, is_put = {}, put = {}, raw = {}, new_put = {};
	char *tmp;

	phalcon_fetch_params(0, 0, 5, &name, &filters, &default_value, &not_allow_empty, &norecursive);

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

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

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

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

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

	PHALCON_CALL_METHODW(&is_put, getThis(), "isput");

	if (!zend_is_true(&is_put)) {
		RETURN_EMPTY_ARRAY();
	} else {
		phalcon_read_property(&put, getThis(), SL("_put"), PH_NOISY);
		if (Z_TYPE(put) != IS_ARRAY) {
			PHALCON_CALL_METHODW(&raw, getThis(), "getrawbody");

			array_init(&new_put);

			PHALCON_ENSURE_IS_STRING(&raw);
			tmp = estrndup(Z_STRVAL(raw), Z_STRLEN(raw));

			sapi_module.treat_data(PARSE_STRING, tmp, &new_put);

			phalcon_update_property_zval(getThis(), SL("_put"), &new_put);
		} else {
			PHALCON_CPY_WRT(&new_put, &put);
		}
	}

	PHALCON_RETURN_CALL_SELFW("_get", &new_put, name, filters, default_value, not_allow_empty, norecursive);
}
Exemple #12
0
/**
 * Applies a format to a message before sent it to the internal log
 *
 * @param string $message
 * @param int $type
 * @param int $timestamp
 * @param array $context
 * @return string
 */
PHP_METHOD(Phalcon_Logger_Formatter_Line, format){

	zval *message, *type, *timestamp, *context, format = {}, date_format = {}, date = {}, date_wildcard = {}, new_format = {}, type_string = {}, type_wildcard = {}, message_wildcard = {};

	phalcon_fetch_params(0, 4, 0, &message, &type, &timestamp, &context);

	phalcon_return_property(&format, getThis(), SL("_format"));

	/** 
	 * Check if the format has the %date% placeholder
	 */
	if (phalcon_memnstr_str(&format, SL("%date%"))) {
		phalcon_return_property(&date_format, getThis(), SL("_dateFormat"));

		phalcon_date(&date, &date_format, timestamp);

		ZVAL_STRING(&date_wildcard, "%date%");

		PHALCON_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_CALL_METHODW(&type_string, getThis(), "gettypestring", type);

		ZVAL_STRING(&type_wildcard, "%type%");

		PHALCON_STR_REPLACE(&format, &type_wildcard, &type_string, &new_format);
	} else {
		PHALCON_CPY_WRT(&format, &new_format);
	}

	ZVAL_STRING(&message_wildcard, "%message%");

	PHALCON_STR_REPLACE(&new_format, &message_wildcard, message, &format);

	if (Z_TYPE_P(context) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(context)) > 0) {
		PHALCON_CALL_METHODW(&format, getThis(), "interpolate", &new_format, context);
	}
	else {
		PHALCON_CPY_WRT(&format, &new_format);
	}

	PHALCON_CONCAT_VS(return_value, &format, PHP_EOL);
}
Exemple #13
0
/**
 * Gets a variable from the $_REQUEST superglobal applying filters if needed.
 * If no parameters are given the $_REQUEST superglobal is returned
 *
 *<code>
 *	//Returns value from $_REQUEST["user_email"] without sanitizing
 *	$userEmail = $request->get("user_email");
 *
 *	//Returns value from $_REQUEST["user_email"] with sanitizing
 *	$userEmail = $request->get("user_email", "email");
 *</code>
 *
 * @param string $name
 * @param string|array $filters
 * @param mixed $defaultValue
 * @param boolean $notAllowEmpty
 * @param boolean $noRecursive
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, get)
{
	zval *name = NULL, *filters = NULL, *default_value = NULL, *not_allow_empty = NULL, *norecursive = NULL, *request;
	zval put = {}, merged = {};

	phalcon_fetch_params(0, 0, 5, &name, &filters, &default_value, &not_allow_empty, &norecursive);

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

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

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

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

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

	request = phalcon_get_global_str(SL("_REQUEST"));

	PHALCON_CALL_METHODW(&put, getThis(), "getput");

	phalcon_fast_array_merge(&merged, request, &put);

	PHALCON_RETURN_CALL_SELFW("_get", &merged, name, filters, default_value, not_allow_empty, norecursive);
}
Exemple #14
0
/**
 * Write hex string to the current position in the file pointer
 * 
 * @return Phalcon\Binary\Writer
 */
PHP_METHOD(Phalcon_Binary_Writer, writeHexString){

	zval *str, *length = NULL, *low_nibble = NULL, len = {}, format = {}, result = {};

	phalcon_fetch_params(0, 1, 2, &str, &length, &low_nibble);

	if (length && Z_TYPE_P(length) != IS_NULL) {
		if (low_nibble && zend_is_true(low_nibble)) {
			PHALCON_CONCAT_SV(&format, "h", length);
		} else {
			PHALCON_CONCAT_SV(&format, "H", length);
		}
	} else {
		if (low_nibble && zend_is_true(low_nibble)) {
			ZVAL_STRING(&format, "h*");
		} else {
			ZVAL_STRING(&format, "H*");
		}
	}
	PHALCON_CALL_FUNCTIONW(&result, "pack", &format, str);

	ZVAL_LONG(&len, Z_STRLEN(result));

	PHALCON_CALL_METHODW(NULL, getThis(), "write", &result, &len);
	RETURN_THISW();
}
Exemple #15
0
/**
 * 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();
}
Exemple #16
0
/**
 * Initializes the internal handler, calling functions on it
 *
 * @param string $method
 * @param array $arguments
 * @return mixed
 */
PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call){

	zval *method, *arguments, handler = {}, definition = {}, call_handler = {};
	zend_class_entry *ce0;

	phalcon_fetch_params(0, 2, 0, &method, &arguments);

	phalcon_return_property(&handler, getThis(), SL("_handler"));
	if (Z_TYPE(handler) != IS_OBJECT) {
		phalcon_read_property(&definition, getThis(), SL("_definition"), PH_NOISY);
		ce0 = phalcon_fetch_class(&definition, ZEND_FETCH_CLASS_DEFAULT);

		PHALCON_OBJECT_INIT(&handler, ce0);
		if (phalcon_has_constructor(&handler)) {
			PHALCON_CALL_METHODW(NULL, &handler, "__construct");
		}
		phalcon_update_property_zval(getThis(), SL("_handler"), &handler);
	}

	array_init_size(&call_handler, 2);
	phalcon_array_append(&call_handler, &handler, PH_COPY);
	phalcon_array_append(&call_handler, method, PH_COPY);

	/** 
	 * Call the handler
	 */
	PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &call_handler, arguments);
}
Exemple #17
0
/**
 * Creates a form registering it in the forms manager
 *
 * @param string $name
 * @param object $entity
 * @return Phalcon\Forms\Form
 */
PHP_METHOD(Phalcon_Forms_Manager, create){

	zval *name = NULL, *entity = NULL, form = {};

	phalcon_fetch_params(0, 0, 2, &name, &entity);

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

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

	if (Z_TYPE_P(name) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The form name must be string");
		return;
	}

	object_init_ex(&form, phalcon_forms_form_ce);
	PHALCON_CALL_METHODW(NULL, &form, "__construct", entity);

	phalcon_update_property_array(getThis(), SL("_forms"), name, &form);

	RETURN_CTORW(&form);
}
Exemple #18
0
/**
 * Decrement of a given key, by number $value
 * 
 * @param  string $keyName
 * @param  long $value
 * @return mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Apc, decrement){

	zval *key_name, *value = NULL, prefix = {}, prefixed_key = {}, cached_content = {};

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

	if (!value || Z_TYPE_P(value) == IS_NULL) {
		value = &PHALCON_GLOBAL(z_one);
	} else {
		PHALCON_ENSURE_IS_LONG(value);
	}

	phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY);

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

	if (SUCCESS == phalcon_function_exists_ex(SL("apc_dec"))) {
		PHALCON_RETURN_CALL_FUNCTIONW("apc_dec", &prefixed_key, value);
	} else {
		PHALCON_CALL_FUNCTIONW(&cached_content, "apc_fetch", &prefixed_key);

		if (Z_TYPE(cached_content) == IS_LONG) {
			phalcon_sub_function(return_value, &cached_content, value);
			PHALCON_CALL_METHODW(NULL, getThis(), "save", key_name, return_value);
		} else {
			RETURN_FALSE;
		}
	}
}
Exemple #19
0
/**
 * Writes the log to the stream itself
 *
 * @param string $message
 * @param int $type
 * @param int $time
 * @param array $context
 */
PHP_METHOD(Phalcon_Logger_Adapter_Stream, logInternal){

	zval *message, *type, *time, *context, *stream, formatter = {}, applied_format = {};

	phalcon_fetch_params(0, 4, 0, &message, &type, &time, &context);

	stream = phalcon_read_property(getThis(), SL("_stream"), PH_NOISY);
	if (Z_TYPE_P(stream) != IS_RESOURCE) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid");
		return;
	}

	PHALCON_CALL_METHODW(&formatter, getThis(), "getformatter");
	PHALCON_CALL_METHODW(&applied_format, &formatter, "format", message, type, time, context);
	PHALCON_CALL_FUNCTIONW(NULL, "fwrite", stream, &applied_format);
}
Exemple #20
0
/**
 * 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();
}
Exemple #21
0
/**
 * Internal get wrapper to filter
 *
 * @param string $name
 * @param string|array $filters
 * @param mixed $defaultValue
 * @param boolean $notAllowEmpty
 * @param boolean $noRecursive
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, _get)
{
	zval *data, *name, *filters, *default_value, *not_allow_empty, *norecursive;
	zval value = {}, dependency_injector = {}, service = {}, filter = {}, filter_value = {};

	phalcon_fetch_params(0, 6, 0, &data, &name, &filters, &default_value, &not_allow_empty, &norecursive);

	if (Z_TYPE_P(name) != IS_NULL) {
		if (!phalcon_array_isset_fetch(&value, data, name, 0)) {
			RETURN_CTORW(default_value);
		}
	} else {
		PHALCON_CPY_WRT_CTOR(&value, data);
	}

	if (Z_TYPE_P(filters) != IS_NULL) {
		phalcon_return_property(&filter, getThis(), SL("_filter"));
		if (Z_TYPE(filter) != IS_OBJECT) {
			PHALCON_CALL_METHODW(&dependency_injector, getThis(), "getdi");
			if (Z_TYPE(dependency_injector) != IS_OBJECT) {
				PHALCON_THROW_EXCEPTION_STRW(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service");
				return;
			}

			PHALCON_STR(&service, ISV(filter));

			PHALCON_CALL_METHODW(&filter, &dependency_injector, "getshared", &service);
			PHALCON_VERIFY_INTERFACEW(&filter, phalcon_filterinterface_ce);

			phalcon_update_property_zval(getThis(), SL("_filter"), &filter);
		}

		PHALCON_CALL_METHODW(&filter_value, &filter, "sanitize", &value, filters, norecursive);

		if ((PHALCON_IS_EMPTY(&filter_value) && zend_is_true(not_allow_empty)) || PHALCON_IS_FALSE(&filter_value)) {
			RETURN_CTORW(default_value);
		}

		RETURN_CTORW(&filter_value);
	}

	if (PHALCON_IS_EMPTY(&value) && zend_is_true(not_allow_empty)) {
		RETURN_CTORW(default_value);
	}

	RETURN_CTORW(&value);
}
Exemple #22
0
/**
 * Composite one image onto another
 *
 * @param Phalcon\Image\Adapter $mask  mask Image instance
 * @return Phalcon\Image\Adapter
 */
PHP_METHOD(Phalcon_Image_Adapter, mask) {

    zval *mask;

    phalcon_fetch_params(0, 1, 0, &mask);
    PHALCON_CALL_METHODW(NULL, this_ptr, "_mask", mask);
    RETURN_THISW();
}
Exemple #23
0
/**
 * Retrieve the URI path
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Client_Adapter, getPath){

	zval base_uri = {};

	phalcon_read_property(&base_uri, getThis(), SL("_base_uri"), PH_NOISY);

	PHALCON_CALL_METHODW(return_value, &base_uri, "getpath");
}
Exemple #24
0
/**
 * Merge modules with the existing ones
 *
 *<code>
 *	$application->addModules(array(
 *		'admin' => array(
 *			'className' => 'Multiple\Admin\Module',
 *			'path' => '../apps/admin/Module.php'
 *		)
 *	));
 *</code>
 *
 * @param array $modules
 */
PHP_METHOD(Phalcon_CLI_Console, addModules){

	zval *modules;

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

	PHALCON_CALL_METHODW(return_value, getThis(), "registermodules", modules, &PHALCON_GLOBAL(z_true));
}
Exemple #25
0
/**
 * Reads the cookie-related info from the SESSION to restore the cookie as it was set
 * This method is automatically called internally so normally you don't need to call it
 *
 * @return Phalcon\Http\Cookie
 */
PHP_METHOD(Phalcon_Http_Cookie, restore)
{
	zval *restored, *dependency_injector, service = {}, session = {}, name = {}, key = {}, definition = {}, expire = {}, domain = {}, path = {}, secure = {}, http_only = {};

	restored = phalcon_read_property(getThis(), SL("_restored"), PH_NOISY);
	if (!zend_is_true(restored)) {
		dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY);
		if (Z_TYPE_P(dependency_injector) == IS_OBJECT) {
			ZVAL_STRING(&service, ISV(session));

			PHALCON_CALL_METHODW(&session, dependency_injector, "getshared", &service);
			PHALCON_VERIFY_INTERFACEW(&session, phalcon_session_adapterinterface_ce);

			phalcon_return_property(&name, getThis(), SL("_name"));

			PHALCON_CONCAT_SV(&key, "_PHCOOKIE_", &name);

			PHALCON_CALL_METHODW(&definition, &session, "get", &key);
			if (Z_TYPE(definition) == IS_ARRAY) { 
				if (phalcon_array_isset_fetch_str(&expire, &definition, SL("expire"))) {
					phalcon_update_property_this(getThis(), SL("_expire"), &expire);
				}
				if (phalcon_array_isset_fetch_str(&domain, &definition, SL("domain"))) {
					phalcon_update_property_this(getThis(), SL("_domain"), &domain);
				}

				if (phalcon_array_isset_fetch_str(&path, &definition, SL("path"))) {
					phalcon_update_property_this(getThis(), SL("_path"), &path);
				}

				if (phalcon_array_isset_fetch_str(&secure, &definition, SL("secure"))) {
					phalcon_update_property_this(getThis(), SL("_secure"), &secure);
				}

				if (phalcon_array_isset_fetch_str(&http_only, &definition, SL("httpOnly"))) {
					phalcon_update_property_this(getThis(), SL("_httpOnly"), &http_only);
				}
			}
		}

		phalcon_update_property_bool(getThis(), SL("_restored"), 1);
	}

	RETURN_THISW();
}
Exemple #26
0
/**
 * Checks whether request has been made using any secure layer
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request, isSecureRequest)
{
	zval scheme = {}, https = {};

	PHALCON_CALL_METHODW(&scheme, getThis(), "getscheme");

	PHALCON_STR(&https, "https");
	is_identical_function(return_value, &https, &scheme);
}
Exemple #27
0
/**
 * Phalcon\Config\Adapter constructor
 *
 * @param string $filePath
 * @param string $absolutePath
 * @param string $scannerMode
 */
PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){

	zval *file_path = NULL, *absolute_path = NULL, *scanner_mode = NULL;

	phalcon_fetch_params(0, 0, 3, &file_path, &absolute_path, &scanner_mode);

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

	if (file_path && Z_TYPE_P(file_path) != IS_NULL) {
		if (scanner_mode) {
			PHALCON_CALL_METHODW(NULL, getThis(), "read", file_path, absolute_path, scanner_mode);
		} else {
			PHALCON_CALL_METHODW(NULL, getThis(), "read", file_path, absolute_path);
		}
	}
}
Exemple #28
0
/**
 * Gets decoded BSON HTTP raw request body
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getBsonRawBody)
{
	zval raw_body = {};

	PHALCON_CALL_METHODW(&raw_body, getThis(), "getrawbody");
	if (Z_TYPE(raw_body) == IS_STRING) {
		PHALCON_RETURN_CALL_FUNCTION("bson_decode", &raw_body);
	}
}
Exemple #29
0
/**
 * Send PUT request
 *
 * @param string $uri
 * @param string $data
 * @return Phalcon\Http\Client\Response
 */
PHP_METHOD(Phalcon_Http_Client_Adapter, put){

	zval *uri = NULL, *data = NULL;

	phalcon_fetch_params(0, 0, 2, &uri, &data);

	if (uri) {
		PHALCON_CALL_METHODW(NULL, getThis(), "seturi", uri);
	}

	if (data) {
		PHALCON_CALL_METHODW(NULL, getThis(), "setdata", data);
	}

	phalcon_update_property_str(getThis(), SL("_method"), SL("PUT"));

	PHALCON_RETURN_CALL_METHODW(getThis(), "send");
}
Exemple #30
0
/**
 * Checks whether offset exists in the resultset
 *
 * @param int $index
 * @return boolean
 */
PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetExists){

	zval *index, *count = NULL;

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

	PHALCON_CALL_METHODW(&count, getThis(), "count");
	is_smaller_function(return_value, index, count);
	zval_ptr_dtor(count);
}