diff --git a/system/engine/controller.php b/system/engine/controller.php index c32d5e1..b3a7853 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -3,6 +3,7 @@ class HF_Controller { protected $config; protected $tpl; + /** @var HF_Core */ protected $core; public function __construct($config, $core, $tpl = null) @@ -10,6 +11,26 @@ class HF_Controller $this->config = $config; $this->tpl = $tpl; $this->core = $core; + $this->initdb(); + } + + protected function initdb() + { + if (isvarset($this->config["MYSQL_DBNAME"]) && isvarset($this->config["MYSQL_USER"])) + { + $pdo = new PDO( + "mysql:dbname={$this->config['MYSQL_DBNAME']};host={$this->config['MYSQL_HOST']}", + $this->config['MYSQL_USER'], + $this->config['MYSQL_PASS'], + array( + PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION + ) + ); + + DB::$c = $pdo; + } } public function loadRender($template, $parameters=array()) diff --git a/system/engine/core.php b/system/engine/core.php index 2d0668c..7472b90 100644 --- a/system/engine/core.php +++ b/system/engine/core.php @@ -12,9 +12,11 @@ class HF_Core private $args = array(); private $config = array(); private $tpl; + private $starttime; public function __construct() { + $this->starttime = microtime(true); $config = include("system/engine/config-default.php"); if (is_file("application/config.php")) { @@ -31,6 +33,11 @@ class HF_Core $this->findController(); } + public function getRuntime() + { + return $this->starttime - microtime(true); + } + public function siteURL() { if (isvarset($this->config["SITE_URL"]))