/** * Magic call * * @param type $method * @param type $args * @throws KantException */ public function __call($method, $args) { $dispatchInfo = KantRegistry::get('dispatchInfo'); if (0 === strcasecmp($method, strtolower($dispatchInfo[2]) . "Action")) { if (method_exists($this, '_empty')) { $this->_empty($method, $args); } elseif (file_exists($this->view->parseTemplate())) { $this->display(); } else { throw new KantException(sprintf("No action exists:%s", ucfirst($dispatchInfo[2]) . 'Action')); } } else { throw new KantException("Method not exists"); } }
/** * Get Token * @return type */ private function getToken() { $tokenConfig = KantRegistry::get('config')->get("token"); $tokenName = !empty($tokenConfig['name']) ? $tokenConfig['name'] : "__hash__"; $tokenType = !empty($tokenConfig['type']) ? $tokenConfig['type'] : "md5"; $tokenReset = !empty($tokenConfig['reset']) ? $tokenConfig['reset'] : false; if (!isset($_SESSION[$tokenName])) { $_SESSION[$tokenName] = array(); } $tokenKey = md5($_SERVER['REQUEST_URI']); if (isset($_SESSION[$tokenName][$tokenKey])) { $tokenValue = $_SESSION[$tokenName][$tokenKey]; } else { $tokenValue = is_callable($tokenType) ? $tokenType(microtime(true)) : md5(microtime(true)); $_SESSION[$tokenName][$tokenKey] = $tokenValue; if (IS_AJAX && $tokenReset) { header($tokenName . ': ' . $tokenKey . '_' . $tokenValue); } } return array($tokenName, $tokenKey, $tokenValue); }
/** * Include template * * @param type $template * @param type $module * @throws RuntimeException */ public function layout($template, $module = '') { if (empty($template)) { return; } list($ctrl, $act) = explode("/", strtolower($template)); $tpldir = $this->getTplDir($module); $tplfile = $tpldir . $ctrl . DIRECTORY_SEPARATOR . $act . '.php'; if (!file_exists($tplfile)) { $debug = KantRegistry::get('config')->get('debug'); if ($debug) { throw new KantException(sprintf("No template: %s", $tplfile)); } else { $this->redirect($this->lang('system_error'), 'close'); } } include_once $tplfile; }