<?php
namespace Run;

use Illuminate\Database\Capsule\Manager as DB;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\FirePHPHandler;
class Init
{
	function __construct()
	{
	}
	/**
	 * 框架初始化
	 */
	public static function RunInit()
	{
		self::AutoLoadInit();
		self::DBInit();
		self::RouteInit();
		// self::AutoLogWanningInit();
		// self::AutoLogErrorInit();
	}
	/**
	 * 初始化数据库驱动
	 */
	private static function DBInit()
	{
		$DB = new DB();
		$DB->addConnection(require ROOT_PATH . "/Config/DBConfig.php");
		$DB->bootEloquent();
		$DB->getConnection()->enableQueryLog();
		//是否开启日志记录
		$GLOBALS['DB'] = $DB->getConnection();
	}
	/**
	 * 初始化路由
	 */
	private static function RouteInit()
	{
		require ROOT_PATH . '/_Route/routes.php';
		\Route::dispatch();
	}
	/**
	 * 初始化自动加载机制
	 */
	private static function AutoLoadInit()
	{
		require ROOT_PATH . '/vendor/autoload.php';
	}
	private static function AutoLogWanningInit($logName = "Default")
	{
		$log = new Logger($logName);
		$logURI = ROOT_PATH . "/Cache/log/" . date("Y-m-d-H-i") . "log";
		$log->pushHandler(new StreamHandler($logURI, Logger::WARNING));
		$log->addWarning('Foo');
		$log->addError('Bar');
	}
	private static function AutoLogErrorInit($logName = "Default")
	{
		$log = new Logger($logName);
		$logURI = ROOT_PATH . "/Cache/log/" . date("Y-m-d-H-i") . "log";
		$log->pushHandler(new StreamHandler($logURI, Logger::ERROR));
		$log->addWarning('Foo');
		$log->addError('Bar');
	}
}