Beispiel #1
0
/**
 * Creates a password hash using bcrypt with a pseudo random salt
 *
 * @param string $password
 * @param int $workFactor
 * @return string
 */
PHP_METHOD(Phalcon_Security, hash){

	zval *password, *work_factor = NULL, *format, *factor;
	zval *salt_bytes, *salt;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &password, &work_factor);
	
	if (!work_factor) {
		PHALCON_INIT_VAR(work_factor);
	} else {
		PHALCON_SEPARATE_PARAM(work_factor);
	}
	
	if (Z_TYPE_P(work_factor) == IS_NULL) {
		PHALCON_OBS_NVAR(work_factor);
		phalcon_read_property_this(&work_factor, this_ptr, SL("_workFactor"), PH_NOISY_CC);
	}
	
	PHALCON_INIT_VAR(format);
	ZVAL_STRING(format, "%02s", 1);
	
	PHALCON_INIT_VAR(factor);
	phalcon_call_func_p2(factor, "sprintf", format, work_factor);
	
	PHALCON_INIT_VAR(salt_bytes);
	phalcon_call_method(salt_bytes, this_ptr, "getsaltbytes");
	
	PHALCON_INIT_VAR(salt);
	PHALCON_CONCAT_SVSV(salt, "$2a$", factor, "$", salt_bytes);
	phalcon_call_func_p2(return_value, "crypt", password, salt);
	RETURN_MM();
}
Beispiel #2
0
/**
 * 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();
}
Beispiel #3
0
/**
 * Opens the internal file handler after unserialization
 *
 */
PHP_METHOD(Phalcon_Logger_Adapter_File, __wakeup){

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

	PHALCON_MM_GROW();

	PHALCON_OBS_VAR(path);
	phalcon_read_property_this(&path, this_ptr, SL("_path"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(options);
	phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC);
	if (phalcon_array_isset_string(options, SS("mode"))) {
		PHALCON_OBS_VAR(mode);
		phalcon_array_fetch_string(&mode, options, SL("mode"), PH_NOISY);
	} else {
		PHALCON_INIT_NVAR(mode);
		ZVAL_STRING(mode, "ab", 1);
	}
	
	/** 
	 * Re-open the file handler if the logger was serialized
	 */
	PHALCON_INIT_VAR(file_handler);
	phalcon_call_func_p2(file_handler, "fopen", path, mode);
	phalcon_update_property_this(this_ptr, SL("_fileHandler"), file_handler TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Beispiel #4
0
/**
 * Executes the validator
 *
 * @param Phalcon\Mvc\ModelInterface $record
 * @return boolean
 */
PHP_METHOD(Phalcon_Mvc_Model_Validator_Url, validate){

	zval *record, *option = NULL, *field, *value, *flag, *is_valid;
	zval *message = NULL, *type;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &record);
	
	PHALCON_INIT_VAR(option);
	ZVAL_STRING(option, "field", 1);
	
	PHALCON_INIT_VAR(field);
	phalcon_call_method_p1(field, this_ptr, "getoption", option);
	if (Z_TYPE_P(field) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string");
		return;
	}
	
	PHALCON_INIT_VAR(value);
	phalcon_call_method_p1(value, record, "readattribute", field);
	
	PHALCON_INIT_VAR(flag);
	ZVAL_LONG(flag, 273);
	
	/** 
	 * Filters the format using FILTER_VALIDATE_URL
	 */
	PHALCON_INIT_VAR(is_valid);
	phalcon_call_func_p2(is_valid, "filter_var", value, flag);
	if (!zend_is_true(is_valid)) {
	
		/** 
		 * Check if the developer has defined a custom message
		 */
		PHALCON_INIT_NVAR(option);
		ZVAL_STRING(option, "message", 1);
	
		PHALCON_INIT_VAR(message);
		phalcon_call_method_p1(message, this_ptr, "getoption", option);
		if (!zend_is_true(message)) {
			PHALCON_INIT_NVAR(message);
			PHALCON_CONCAT_SVS(message, "'", field, "' does not have a valid url format");
		}
	
		PHALCON_INIT_VAR(type);
		ZVAL_STRING(type, "Url", 1);
		phalcon_call_method_p3_noret(this_ptr, "appendmessage", message, field, type);
		RETURN_MM_FALSE;
	}
	
	RETURN_MM_TRUE;
}
Beispiel #5
0
/**
 * Returns the numeric active version
 *
 * <code>
 * echo Phalcon\Version::getId();
 * </code>
 *
 * @return int
 */
PHP_METHOD(Phalcon_Version, getId){

	zval *version, *major, *medium, *minor, *special, *special_number;
	zval *format, *real_medium, *real_minor;

	PHALCON_MM_GROW();

	PHALCON_INIT_VAR(version);
	PHALCON_CALL_SELF(version, this_ptr, "_getversion");

	PHALCON_OBS_VAR(major);
	phalcon_array_fetch_long(&major, version, 0, PH_NOISY);

	PHALCON_OBS_VAR(medium);
	phalcon_array_fetch_long(&medium, version, 1, PH_NOISY);

	PHALCON_OBS_VAR(minor);
	phalcon_array_fetch_long(&minor, version, 2, PH_NOISY);

	PHALCON_OBS_VAR(special);
	phalcon_array_fetch_long(&special, version, 3, PH_NOISY);

	PHALCON_OBS_VAR(special_number);
	phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY);

	PHALCON_INIT_VAR(format);
	ZVAL_STRING(format, "%02s", 1);

	PHALCON_INIT_VAR(real_medium);
	phalcon_call_func_p2(real_medium, "sprintf", format, medium);

	PHALCON_INIT_VAR(real_minor);
	phalcon_call_func_p2(real_minor, "sprintf", format, minor);
	PHALCON_CONCAT_VVVVV(return_value, major, real_medium, real_minor, special, special_number);
	RETURN_MM();
}
Beispiel #6
0
/**
 * Phalcon\Logger\Adapter\File constructor
 *
 * @param string $name
 * @param array $options
 */
PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){

	zval *name, *options = NULL, *mode = NULL, *handler, *exception_message;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &name, &options);
	
	if (!options) {
		PHALCON_INIT_VAR(options);
	}
	
	if (phalcon_array_isset_string(options, SS("mode"))) {
	
		PHALCON_OBS_VAR(mode);
		phalcon_array_fetch_string(&mode, options, SL("mode"), PH_NOISY);
		if (phalcon_memnstr_str(mode, SL("r"))) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Logger must be opened in append or write mode");
			return;
		}
	} else {
		PHALCON_INIT_NVAR(mode);
		ZVAL_STRING(mode, "ab", 1);
	}
	
	/** 
	 * We use 'fopen' to respect to open-basedir directive
	 */
	PHALCON_INIT_VAR(handler);
	phalcon_call_func_p2(handler, "fopen", name, mode);
	if (!zend_is_true(handler)) {
		PHALCON_INIT_VAR(exception_message);
		PHALCON_CONCAT_SVS(exception_message, "Can't open log file at '", name, "'");
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_logger_exception_ce, exception_message);
		return;
	}
	
	phalcon_update_property_this(this_ptr, SL("_path"), name TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_options"), options TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_fileHandler"), handler TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Beispiel #7
0
/**
 * Phalcon\Config\Adapter\Ini constructor
 *
 * @param string $filePath
 */
PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){

	zval *file_path, *process_sections, *ini_config;
	zval *exception_message, *config, *directives = NULL;
	zval *section = NULL, *value = NULL, *key = NULL, *directive_parts = NULL, *left_part = NULL;
	zval *right_part = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &file_path);
	
	PHALCON_INIT_VAR(process_sections);
	ZVAL_BOOL(process_sections, 1);
	
	/** 
	 * Use the standard parse_ini_file
	 */
	PHALCON_INIT_VAR(ini_config);
	phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, process_sections);
	
	/** 
	 * Check if the file had errors
	 */
	if (PHALCON_IS_FALSE(ini_config)) {
		PHALCON_INIT_VAR(exception_message);
		PHALCON_CONCAT_SVS(exception_message, "Configuration file ", file_path, " can't be loaded");
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_config_exception_ce, exception_message);
		return;
	}
	
	PHALCON_INIT_VAR(config);
	array_init(config);
	
	phalcon_is_iterable(ini_config, &ah0, &hp0, 0, 0);
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_HKEY(section, ah0, hp0);
		PHALCON_GET_HVALUE(directives);
	
		if (unlikely(Z_TYPE_P(directives) != IS_ARRAY)) {
			Z_ADDREF_P(directives);
			if (phalcon_array_update_zval(&config, section, &directives, 0 TSRMLS_CC) != SUCCESS) {
				Z_DELREF_P(directives);
			}
			zend_hash_move_forward_ex(ah0, &hp0);
			continue;
	}
	
		phalcon_is_iterable(directives, &ah1, &hp1, 0, 0);
	
		if (zend_hash_num_elements(ah1) == 0) {
			phalcon_array_update_zval(&config, section, &directives, 0 TSRMLS_CC);
			zend_hash_move_forward_ex(ah0, &hp0);
			continue;
		}
	
		while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
	
			PHALCON_GET_HKEY(key, ah1, hp1);
			PHALCON_GET_HVALUE(value);
	
			if (phalcon_memnstr_str(key, SL(".") TSRMLS_CC)) {
				PHALCON_INIT_NVAR(directive_parts);
				phalcon_fast_explode_str(directive_parts, SL("."), key TSRMLS_CC);
	
				PHALCON_OBS_NVAR(left_part);
				phalcon_array_fetch_long(&left_part, directive_parts, 0, PH_NOISY_CC);
	
				PHALCON_OBS_NVAR(right_part);
				phalcon_array_fetch_long(&right_part, directive_parts, 1, PH_NOISY_CC);
				phalcon_array_update_zval_zval_zval_multi_3(&config, section, left_part, right_part, &value, 0 TSRMLS_CC);
			} else {
				phalcon_array_update_multi_2(&config, section, key, &value, 0 TSRMLS_CC);
			}
	
			zend_hash_move_forward_ex(ah1, &hp1);
		}
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	/** 
	 * Calls the Phalcon\Config constructor
	 */
	PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Config\\Adapter\\Ini", "__construct", config);
	
	PHALCON_MM_RESTORE();
}
Beispiel #8
0
/**
 * Shows a backtrace item
 *
 * @param int $n
 * @param array $trace
 */
PHP_METHOD(Phalcon_Debug, showTraceItem){

	zval *n, *trace, *space, *two_spaces, *underscore;
	zval *minus, *html, *class_name, *pattern, *is_phalcon_class;
	zval *namespace_separator, *prepare_uri_class;
	zval *class_reflection, *is_internal = NULL, *lower_class_name;
	zval *prepare_internal_class, *type, *function_name = NULL;
	zval *function_reflection, *prepared_function_name;
	zval *trace_args, *arguments, *argument = NULL, *dumped_argument = NULL;
	zval *span_argument = NULL, *joined_arguments, *one;
	zval *file, *line, *show_files, *lines, *number_lines;
	zval *show_file_fragment, *seven, *before_line;
	zval *first_line = NULL, *five, *after_line, *last_line = NULL;
	zval *comment_pattern, *utf8, *ent_compat, *tab;
	zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL;
	zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL;
	zval *escaped_line = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;
	zend_class_entry *ce0, *ce1;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &n, &trace);
	
	PHALCON_INIT_VAR(space);
	ZVAL_STRING(space, " ", 1);
	
	PHALCON_INIT_VAR(two_spaces);
	ZVAL_STRING(two_spaces, "  ", 1);
	
	PHALCON_INIT_VAR(underscore);
	ZVAL_STRING(underscore, "_", 1);
	
	PHALCON_INIT_VAR(minus);
	ZVAL_STRING(minus, "-", 1);
	
	/** 
	 * Every trace in the backtrace have a unique number
	 */
	PHALCON_INIT_VAR(html);
	PHALCON_CONCAT_SVS(html, "<tr><td align=\"right\" valign=\"top\" class=\"error-number\">#", n, "</td><td>");
	if (phalcon_array_isset_string(trace, SS("class"))) {
	
		PHALCON_OBS_VAR(class_name);
		phalcon_array_fetch_string(&class_name, trace, SL("class"), PH_NOISY_CC);
	
		PHALCON_INIT_VAR(pattern);
		ZVAL_STRING(pattern, "/^Phalcon/", 1);
	
		PHALCON_INIT_VAR(is_phalcon_class);
	
		#if HAVE_BUNDLED_PCRE
		phalcon_preg_match(is_phalcon_class, pattern, class_name, NULL TSRMLS_CC);
		#else
		phalcon_call_func_p2(is_phalcon_class, "preg_match", pattern, class_name);
		#endif
	
		/** 
		 * We assume that classes starting by Phalcon are framework's classes
		 */
		if (zend_is_true(is_phalcon_class)) {
			PHALCON_INIT_VAR(namespace_separator);
			ZVAL_STRING(namespace_separator, "\\", 1);
	
			/** 
			 * Prepare the class name according to the Phalcon's conventions
			 */
			PHALCON_INIT_VAR(prepare_uri_class);
			phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name TSRMLS_CC);
	
			/** 
			 * Generate a link to the official docs
			 */
			PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://docs.phalconphp.com/en/latest/api/", prepare_uri_class, ".html\">", class_name, "</a></span>");
		} else {
			ce0 = zend_fetch_class(SL("ReflectionClass"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
			PHALCON_INIT_VAR(class_reflection);
			object_init_ex(class_reflection, ce0);
			if (phalcon_has_constructor(class_reflection TSRMLS_CC)) {
				phalcon_call_method_p1_noret(class_reflection, "__construct", class_name);
			}
	
			/** 
			 * Check if classes are PHP's classes
			 */
			PHALCON_INIT_VAR(is_internal);
			phalcon_call_method(is_internal, class_reflection, "isinternal");
			if (zend_is_true(is_internal)) {
				PHALCON_INIT_VAR(lower_class_name);
				phalcon_fast_strtolower(lower_class_name, class_name);
	
				PHALCON_INIT_VAR(prepare_internal_class);
				phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name TSRMLS_CC);
	
				/** 
				 * Generate a link to the official docs
				 */
				PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://php.net/manual/en/class.", prepare_internal_class, ".php\">", class_name, "</a></span>");
			} else {
				PHALCON_SCONCAT_SVS(html, "<span class=\"error-class\">", class_name, "</span>");
			}
		}
	
		/** 
		 * Object access operator: static/instance
		 */
		PHALCON_OBS_VAR(type);
		phalcon_array_fetch_string(&type, trace, SL("type"), PH_NOISY_CC);
		phalcon_concat_self(&html, type TSRMLS_CC);
	}
	
	/** 
	 * Normally the backtrace contains only classes
	 */
	if (phalcon_array_isset_string(trace, SS("class"))) {
		PHALCON_OBS_VAR(function_name);
		phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY_CC);
		PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
	} else {
		PHALCON_OBS_NVAR(function_name);
		phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY_CC);
	
		/** 
		 * Check if the function exists
		 */
		if (phalcon_function_exists(function_name TSRMLS_CC) == SUCCESS) {
			ce1 = zend_fetch_class(SL("ReflectionFunction"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
			PHALCON_INIT_VAR(function_reflection);
			object_init_ex(function_reflection, ce1);
			if (phalcon_has_constructor(function_reflection TSRMLS_CC)) {
				phalcon_call_method_p1_noret(function_reflection, "__construct", function_name);
			}
	
			PHALCON_INIT_NVAR(is_internal);
			phalcon_call_method(is_internal, function_reflection, "isinternal");
	
			/** 
			 * Internal functions links to the PHP documentation
			 */
			if (zend_is_true(is_internal)) {
				/** 
				 * Prepare function's name according to the conventions in the docs
				 */
				PHALCON_INIT_VAR(prepared_function_name);
				phalcon_fast_str_replace(prepared_function_name, underscore, minus, function_name TSRMLS_CC);
				PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-function\"><a target=\"_new\" href=\"http://php.net/manual/en/function.", prepared_function_name, ".php\">", function_name, "</a></span>");
			} else {
				PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
			}
		} else {
			PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
		}
	}
	
	/** 
	 * Check for arguments in the function
	 */
	if (phalcon_array_isset_string(trace, SS("args"))) {
	
		PHALCON_OBS_VAR(trace_args);
		phalcon_array_fetch_string(&trace_args, trace, SL("args"), PH_NOISY_CC);
		if (phalcon_fast_count_ev(trace_args TSRMLS_CC)) {
	
			PHALCON_INIT_VAR(arguments);
			array_init(arguments);
	
			phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0);
	
			while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
				PHALCON_GET_HVALUE(argument);
	
				/** 
				 * Every argument is generated using _getVarDump
				 */
				PHALCON_INIT_NVAR(dumped_argument);
				phalcon_call_method_p1(dumped_argument, this_ptr, "_getvardump", argument);
	
				PHALCON_INIT_NVAR(span_argument);
				PHALCON_CONCAT_SVS(span_argument, "<span class=\"error-parameter\">", dumped_argument, "</span>");
	
				/** 
				 * Append the HTML generated to the argument's list
				 */
				phalcon_array_append(&arguments, span_argument, PH_SEPARATE TSRMLS_CC);
	
				zend_hash_move_forward_ex(ah0, &hp0);
			}
	
			/** 
			 * Join all the arguments
			 */
			PHALCON_INIT_VAR(joined_arguments);
			phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC);
			PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")");
		} else {
			phalcon_concat_self_str(&html, SL("()") TSRMLS_CC);
		}
	}
	
	/** 
	 * When 'file' is present, it usually means the function is provided by the user
	 */
	if (phalcon_array_isset_string(trace, SS("file"))) {
	
		PHALCON_INIT_VAR(one);
		ZVAL_LONG(one, 1);
	
		PHALCON_OBS_VAR(file);
		phalcon_array_fetch_string(&file, trace, SL("file"), PH_NOISY_CC);
	
		PHALCON_OBS_VAR(line);
		phalcon_array_fetch_string(&line, trace, SL("line"), PH_NOISY_CC);
	
		/** 
		 * Realpath to the file and its line using a special header
		 */
		PHALCON_SCONCAT_SVSVS(html, "<br/><div class=\"error-file\">", file, " (", line, ")</div>");
	
		PHALCON_OBS_VAR(show_files);
		phalcon_read_property_this(&show_files, this_ptr, SL("_showFiles"), PH_NOISY_CC);
	
		/** 
		 * The developer can change if the files must be opened or not
		 */
		if (zend_is_true(show_files)) {
	
			/** 
			 * Open the file to an array using 'file', this respects the openbase-dir directive
			 */
			PHALCON_INIT_VAR(lines);
			phalcon_call_func_p1(lines, "file", file);
	
			PHALCON_INIT_VAR(number_lines);
			phalcon_fast_count(number_lines, lines TSRMLS_CC);
	
			PHALCON_OBS_VAR(show_file_fragment);
			phalcon_read_property_this(&show_file_fragment, this_ptr, SL("_showFileFragment"), PH_NOISY_CC);
	
			/** 
			 * File fragments just show a piece of the file where the exception is located
			 */
			if (zend_is_true(show_file_fragment)) {
	
				/** 
				 * Take seven lines back to the current exception's line, @TODO add an option for
				 * this
				 */
				PHALCON_INIT_VAR(seven);
				ZVAL_LONG(seven, 7);
	
				PHALCON_INIT_VAR(before_line);
				sub_function(before_line, line, seven TSRMLS_CC);
	
				/** 
				 * Check for overflows
				 */
				if (PHALCON_LT_LONG(before_line, 1)) {
					PHALCON_CPY_WRT(first_line, one);
				} else {
					PHALCON_CPY_WRT(first_line, before_line);
				}
	
				/** 
				 * Take five lines after the current exception's line, @TODO add an option for this
				 */
				PHALCON_INIT_VAR(five);
				ZVAL_LONG(five, 5);
	
				PHALCON_INIT_VAR(after_line);
				phalcon_add_function(after_line, line, five TSRMLS_CC);
	
				/** 
				 * Check for overflows
				 */
				if (PHALCON_GT(after_line, number_lines)) {
					PHALCON_CPY_WRT(last_line, number_lines);
				} else {
					PHALCON_CPY_WRT(last_line, after_line);
				}
	
				PHALCON_SCONCAT_SVSVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums:", first_line, "'>");
			} else {
				PHALCON_CPY_WRT(first_line, one);
				PHALCON_CPY_WRT(last_line, number_lines);
				PHALCON_SCONCAT_SVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums error-scroll'>");
			}
	
			PHALCON_INIT_VAR(comment_pattern);
			ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1);
	
			/** 
			 * We assume the file is utf-8 encoded, @TODO add an option for this
			 */
			PHALCON_INIT_VAR(utf8);
			ZVAL_STRING(utf8, "UTF-8", 1);
	
			/** 
			 * Don't escape quotes
			 */
			PHALCON_INIT_VAR(ent_compat);
			ZVAL_LONG(ent_compat, 2);
	
			PHALCON_INIT_VAR(tab);
			ZVAL_STRING(tab, "\t", 1);
	
			PHALCON_INIT_VAR(comment);
			ZVAL_STRING(comment, "* /", 1);
			PHALCON_CPY_WRT(i, first_line);
	
			while (1) {
	
				if (PHALCON_LE(i, last_line)) {
				} else {
					break;
				}
	
				/** 
				 * Current line in the file
				 */
				PHALCON_INIT_NVAR(line_position);
				sub_function(line_position, i, one TSRMLS_CC);
	
				/** 
				 * Current line content in the piece of file
				 */
				PHALCON_OBS_NVAR(current_line);
				phalcon_array_fetch(&current_line, lines, line_position, PH_NOISY_CC);
	
				/** 
				 * File fragments are cleaned, removing tabs and comments
				 */
				if (zend_is_true(show_file_fragment)) {
					if (PHALCON_IS_EQUAL(i, first_line)) {
	
						PHALCON_INIT_NVAR(trimmed);
						phalcon_fast_trim(trimmed, current_line, PHALCON_TRIM_RIGHT TSRMLS_CC);
	
						PHALCON_INIT_NVAR(is_comment);
	
						#if HAVE_BUNDLED_PCRE
						phalcon_preg_match(is_comment, comment_pattern, current_line, NULL TSRMLS_CC);
						#else
						phalcon_call_func_p2(is_comment, "preg_match", comment_pattern, current_line);
						#endif
	
						if (zend_is_true(is_comment)) {
							PHALCON_INIT_NVAR(spaced_current_line);
							phalcon_fast_str_replace(spaced_current_line, comment, space, current_line TSRMLS_CC);
							PHALCON_CPY_WRT(current_line, spaced_current_line);
						}
					}
				}
	
				/** 
				 * Print a non break space if the current line is a line break, this allows to show
				 * the html zebra properly
				 */
				if (PHALCON_IS_STRING(current_line, "\n")) {
					phalcon_concat_self_str(&html, SL("&nbsp;\n") TSRMLS_CC);
				} else {
					if (PHALCON_IS_STRING(current_line, "\r\n")) {
						phalcon_concat_self_str(&html, SL("&nbsp;\n") TSRMLS_CC);
					} else {
						PHALCON_INIT_NVAR(spaced_current_line);
						phalcon_fast_str_replace(spaced_current_line, tab, two_spaces, current_line TSRMLS_CC);
	
						PHALCON_INIT_NVAR(escaped_line);
						phalcon_call_func_p3(escaped_line, "htmlentities", spaced_current_line, ent_compat, utf8);
						phalcon_concat_self(&html, escaped_line TSRMLS_CC);
					}
				}
	
				PHALCON_SEPARATE(i);
				phalcon_increment(i);
			}
			phalcon_concat_self_str(&html, SL("</pre>") TSRMLS_CC);
		}
	}
	
	phalcon_concat_self_str(&html, SL("</td></tr>") TSRMLS_CC);
	
	RETURN_CTOR(html);
}