/** * @return mixed */ public static function getInstance() { if (!isset(self::$Instance)) { $dbh = Factory::getDBH(); if (Input::getVar('TemplateID', 'REQUEST')) { $TemplateID = Input::getVar('TemplateID', 'REQUEST'); } elseif (Factory::getCookie()->get('TemplateID')) { $TemplateID = Factory::getCookie()->get('TemplateID'); } else { $TemplateID = null; } if ($TemplateID) { $stmt = $dbh->prepare('SELECT * FROM Template WHERE TemplateID = :TemplateID AND ApplicationID = :AppID'); try { $stmt->bindValue(':AppID', Factory::getApplication()->getApplicationID(), PDO::PARAM_STR); $stmt->bindValue(':TemplateID', $TemplateID, PDO::PARAM_INT); $stmt->execute(); $rst = $stmt->fetch(PDO::FETCH_OBJ); if (is_object($rst)) { $Class = $rst->Template; self::$Instance = new $Class($dbh, $rst); } else { unset($rst); } } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } } if (!self::$Instance instanceof Template) { $stmt = $dbh->prepare('SELECT * FROM Template WHERE ApplicationID = :AppID AND Root = 1'); $stmt->bindValue(':AppID', Factory::getApplication()->getApplicationID(), PDO::PARAM_STR); try { $stmt->execute(); $rst = $stmt->fetch(PDO::FETCH_OBJ); if (is_object($rst)) { $Class = "Templates\\{$rst->Template}\\{$rst->Template}"; self::$Instance = new $Class($dbh, $rst); } } catch (PDOException $e) { $dbh->catchException($e, $stmt->queryString); } if (!self::$Instance) { Factory::getLogger()->emergency('No Template found in Database exiting...'); } } } return self::$Instance; }