Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
Archivo: line.c Proyecto: 9466/cphalcon
/**
 * 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 = NULL, *date_format;
	zval *date, *date_wildcard, *new_format = NULL, *type_string = NULL;
	zval *type_wildcard, *message_wildcard;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 4, 0, &message, &type, &timestamp, &context);
	
	PHALCON_OBS_VAR(format);
	phalcon_read_property_this(&format, this_ptr, SL("_format"), PH_NOISY TSRMLS_CC);
	
	/** 
	 * Check if the format has the %date% placeholder
	 */
	if (phalcon_memnstr_str(format, SL("%date%"))) {
		date_format = phalcon_fetch_nproperty_this(this_ptr, SL("_dateFormat"), PH_NOISY TSRMLS_CC);
	
		PHALCON_INIT_VAR(date);
		phalcon_date(date, date_format, timestamp TSRMLS_CC);
	
		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_CALL_METHOD(&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);
	
	if (Z_TYPE_P(context) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(context)) > 0) {
		PHALCON_CALL_METHOD(&format, this_ptr, "interpolate", new_format, context);
	}
	else {
		PHALCON_CPY_WRT(format, new_format);
	}

	PHALCON_CONCAT_VS(return_value, format, PHP_EOL);
	RETURN_MM();
}