/** * 单态模式,取得全局单一实例 * * @return unknown */ public static function getInstance() { if (is_null(self::$_theInstance)) { self::$_theInstance = new KISS_Framework_Context(); } return self::$_theInstance; }
/** * 命令行入口函数 * * @return mix */ public function run() { $context = KISS_Framework_Context::getInstance(); $class_name = $context->mClassName; if (class_exists($class_name)) { if (!isset($_REQUEST['method'])) { $this->_genJS(); die; } else { try { $old_error_handler = set_error_handler(array('KISS_Controller_JSON', "myErrorHandler")); $this->_instance = new $class_name(); } catch (Exception $error) { $this->showMessage($error->getMessage()); } } } else { $this->showMessage("文件不存在!\\r" . $_SERVER['SCRIPT_URI']); } if (isset($_REQUEST['method'])) { $return = array(); try { $old_error_handler = set_error_handler(array('KISS_Controller_JSON', "myErrorHandler")); if (get_magic_quotes_gpc() === 1) { $_REQUEST['parameters'] = stripslashes($_REQUEST['parameters']); } $return = array('data' => call_user_func_array(array(&$this->_instance, $_REQUEST['method']), json_decode($_REQUEST['parameters']))); } catch (Exception $error) { $return = array('message' => $error->getMessage()); } echo json_encode($return); } }
/** * 前置过滤方法 * * @return void */ public function doPreProcessing() { $cache_time = KISS_Framework_Context::getInstance()->mCacheTime; if ($cache_time > 0) { $this->_mCacheHandle = new KISS_Util_FileCache($_SERVER['REQUEST_URI'], $cache_time); if ($this->_mCacheHandle->checkCacheStatus()) { echo $this->_mCacheHandle->getCacheContent(); exit; } } if (0 == ob_get_level()) { ob_start(); } }
/** * 后置过滤方法 * * @param KISS_Framework_Context $context 上下文对象 * * @return void */ public function doPostProcessing(KISS_Framework_Context $context) { $str_array = str_split($context->toString(), KISS_Filter_StorageCookie::COOKIE_PART_MAX_LENGTH); array_walk($str_array, array(&$this, '_setPartCookie')); setcookie($this->_mCookieName, count($str_array)); }
/** * 构造函数 * */ function __construct() { $this->mGET = $_GET; $this->mPOST = $_POST; $type_hash['string'] = FILTER_SANITIZE_STRING; $type_hash['int'] = FILTER_VALIDATE_INT; $type_hash['email'] = FILTER_VALIDATE_EMAIL; parent::__construct(); $this->mContext = KISS_Framework_Context::getInstance(); $this->mCurrentUser =& $this->mContext->mCurrentUser; $this->mCurrentTime = time(); $class = get_class($this); if (isset(KISS_Framework_Config::$annotation['class_var'][$class]) && count(KISS_Framework_Config::$annotation['class_var'][$class]) > 0) { foreach (KISS_Framework_Config::$annotation['class_var'][$class] as $key => $value) { if (isset($value['source'])) { $source_code = "if(isset({$value['source']}))return {$value['source']};"; $source = eval($source_code); switch ($value['type']) { case 'string': $var = filter_var($source, $type_hash[$value['type']]); if (isset($value['min']) || isset($value['max'])) { $strlen = KISS_Util_String::strlen($source); } if (!is_null($var) && $var != '' && (!isset($value['min']) || $strlen >= $value['min']) && (!isset($value['max']) || $strlen <= $value['max'])) { $this->{$key} = $var; } break; case 'int': $var = filter_var($source, $type_hash[$value['type']]); if ($var !== false && (!isset($value['min']) || $var >= $value['min']) && (!isset($value['max']) || $var <= $value['max'])) { if (isset($value['class'])) { $this->{$key} = eval(sprintf('return new %s(%d);', $value['class'], $var)); } else { $this->{$key} = $var; } } elseif (isset($value['require'])) { throw new Exception($value['require']); } break; case 'email': $var = filter_var($source, $type_hash[$value['type']]); if ($var !== false) { $this->{$key} = $var; } break; case 'timestamp': $var = @strtotime($source); if ($var !== false) { $this->{$key} = $var; } break; case 'mix': $this->{$key} = $source; break; default: break; } } } } }
/** * 执行入口 * * @return void */ public function run() { $context = KISS_Framework_Context::getInstance(); if (count($this->mFilters) > 0) { $filter = array_shift($this->mFilters); $filter = new $filter(); $filter->doFilter($context, $this); } else { $page = new $context->mClassName(); $page->run(); } }