<?php

use KIF\String\String;

if (PHP_VERSION < '5.3.0') {
	echo 'PHP VERSION MUST > 5.3.0';
	exit;
}

if (!defined('DS')) {
	define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('KIF_PATH')) {
	define('KIF_PATH', dirname(__FILE__));
}
if (!defined('KIF_DEBUG_PASS')) {
	define('KIF_DEBUG_PASS', 'rabin');
}
if (!defined('KIF_ERROR_LEVEL'))	{
	define('KIF_ERROR_LEVEL', E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING);
}
/**
 *
 * 获取用于标识主库写入成功的cookie key
 * # 定义常量,用于标识主数据库有写入操作。值为MASTER_DB_HAS_WRITE md5 16位后的值,避免明文被有心人猜测
 * # 使用场景,MySQLite类执行写入语句成功时,会给该常量为key写一个cookie。当php页面读到该cookie时,会把查询的sql强制走主库
 * # 使用场景2,当varnish获取到该key的cookies时,强制将用户请求pass到后端
 * @return string
 */
if (!defined('KIF_MASTER_DB_HAS_WRITE_COOKIE_KEY')) {
	define('KIF_MASTER_DB_HAS_WRITE_COOKIE_KEY', '17439a6561e7666b');
}

require_once KIF_PATH . DS . 'Core/Core.class.php';
spl_autoload_register(array('KIF\Core\Core', 'autoload'));

# 包含定义的框架级常量
require_once KIF_PATH . DS . 'global_constants.php';

# 默认将显示错误关闭
ini_set('display_errors', false);

# 设置默认时区
date_default_timezone_set('PRC');

#############################################
if (get_magic_quotes_runtime()) {//表示系统自动将数据库读入或文件读入的数据添加转义
    set_magic_quotes_runtime(0);//不做这步,由应用来管理
}
# 外部输入的数据,不需要转义。由应用自行处理即可!
if (get_magic_quotes_gpc()) {//系统开启了进站数据转义
    foreach (array('_GET', '_POST', '_FILES', '_COOKIE', '_REQUEST') as $_v) {
        $$_v = String::stripslashes($$_v);
    }   
}
#############################################

if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == KIF_DEBUG_PASS) {
	# Debug模式将错误打开
	ini_set('display_errors', true);
	# 设置错误级别
	error_reporting(KIF_ERROR_LEVEL);
	//开启ob函数
	ob_start();
	
	KIF\Debug\Debug::start();
	register_shutdown_function(array('KIF\Debug\Debug', 'show'));
}