Exemple #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);
}
Exemple #2
0
/**
 * Escapes a string with htmlentities
 *
 * @param string $value
 * @return string
 */
PHP_METHOD(Phalcon_Debug, _escapeString) {

    zval *value, *charset, *replaced_value;

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

    if (Z_TYPE_P(value) == IS_STRING) {
        zval line_break;
        zval escaped_line_break;

        charset = phalcon_read_static_property_ce(phalcon_debug_ce, SL("_charset"));

        ZVAL_STRING(&line_break, "\n");
        ZVAL_STRING(&escaped_line_break, "\\n");

        PHALCON_STR_REPLACE(&replaced_value, &line_break, &escaped_line_break, value);
        phalcon_htmlentities(return_value, replaced_value, NULL, charset);
        zval_ptr_dtor(replaced_value);
        return;
    }

    RETURN_ZVAL(value, 1, 0);
}