/** * 刪除 cache 資料 * @access public * @return boolean * @since 2011-09-05 */ public function delete($key) { if ($key == '') { log::errorLog('$key is empty'); return false; } if (!$this->_memcache->delete($key, 0)) { log::errorLog('memcacheLayer delete() failed'); return false; } log::accessLog('memcacheLayer delete() successful'); log::returnLog(true); return true; }
/** * set config * @access public * @static * @param string $name * @param mixed $value * @example * <p> * $name = 'database.params'; * $value = array('host'=>'localhost', 'password'=>'xxx'); * config::set($name, $value); * </p> */ public static function set($name, $value) { $segments = explode('.', $name); if (1 < count($segments)) { $config =& self::$_config; for ($i = 0, $n = count($segments); $i < $n; $i++) { $segment =& $segments[$i]; if ($i === $n - 1) { $config[$segment] = $value; } else { $config[$segment] = array(); } $config =& $config[$segment]; } } else { self::$_config[$name] = $value; } log::accessLog('config set[' . $name . '] success'); }
/** * 取得資料表裡的其中一個欄位的所有內容. * @access public * @link find() * @return array * @example $obj->findCol() ; */ public function findCol($table, $field, $conditions = null, $limit = null, $limitStart = 0, $sorts = null) { if (!$field) { log::errorLog('$field is empty'); return false; } $colArr = array(); $arr = $this->find($table, $field, $conditions, $limit, $limitStart, $sorts); if ($arr === false) { log::errorLog('execute $this->find() fail'); return false; } else { foreach ($arr as $ak => $av) { $colArr[] = $av[$field]; } } log::accessLog('execute findCol success'); log::returnLog($colArr); return $colArr; }
/** * 刪除 cache 資料 * @access public * @return string * @since 2011-09-08 */ public function delete($key) { if (!$key) { log::errorLog('$key is empty'); return false; } //convert key to file. sha1 has 1/2^51 collision possibility. $fileSeed = sha1($key); $dir1 = substr($fileSeed, 0, 2); $dir2 = substr($fileSeed, 2, 2); $cacheFile = $this->_cacheFileTopDirectory . "{$dir1}/{$dir2}/{$fileSeed}"; $cacheExpirationFile = "{$cacheFile}_expirationTime"; if (!file_exists($cacheFile)) { return false; } if (unlink($cacheFile) && unlink($cacheExpirationFile)) { log::accessLog('fileCache delete() success'); log::returnLog($str); return true; } else { log::errorLog('fileCache delete() failed'); return false; } }
/** * 检查变量是否存在 * @access public * @static * @link _isset * @param $key String 变量名 * @return Boolean * @example registry::_isset('foo'); */ public static function _isset($key) { $flag = false; if (isset(self::$_var[$key])) { $flag = true; } if (self::$_enableLog) { if ($flag) { log::accessLog('access object of registry'); log::returnLog('isset(' . $key . ') return true'); } else { log::returnLog('isset(' . $key . ') return false'); } } return $flag; }
/** * 载入视图文件 */ protected function _include($___filename, array $___vars = null) { $this->_extname = pathinfo($___filename, PATHINFO_EXTENSION); extract($this->_vars); if (is_array($___vars)) { extract($___vars); } include $___filename; log::accessLog('include a file success'); }
/** * cacheLayer析构函数 */ public function __destruct() { $this->_close(); log::accessLog('cacheLayer is destructed'); }
/** * 路由转换处理 * @access public */ public function route() { $path = trim(urldecode($this->getPathInfo()), '/'); $routeMatched = false; $routes = $this->_getRoutes(); if (is_array($routes) && count($routes)) { foreach ($routes as $module => $rules) { if (is_array($rules) && count($rules)) { foreach ($rules as $rule) { if (isset($rule['rule']) && is_string($rule['rule'])) { $pattern = '#^' . $rule['rule'] . '$#i'; $routeMatched = preg_match($pattern, $path, $matches); if ($routeMatched) { array_shift($matches); if (isset($rule['matches']['controller'])) { $classFile = sprintf('%s/app/%s/%scontroller.php', PROJECT_ROOT, $module, $rule['matches']['controller']); if (!is_file($classFile)) { throw new Exception('Error controller file!(' . $rule['matches']['controller'] . ')'); return false; } require_once $classFile; $className = sprintf('%s%sController', strtolower($module), ucfirst($rule['matches']['controller'])); if (!class_exists($className, false)) { throw new Exception('Error controller name!(' . $className . ')'); return false; } $action = 'index'; if (isset($rule['matches']['action'])) { $action = $rule['matches']['action']; } $action = strtolower($action) . 'Action'; $controllerObject = new $className(); if (method_exists($controllerObject, 'init')) { $controllerObject->init(); } if (!method_exists($controllerObject, $action)) { throw new Exception('Error action name(' . $className . '->' . $action . ')'); return false; } call_user_func_array(array($controllerObject, $action), $matches); $routeMatched = true; break 2; } } } } } } } log::accessLog('Execute route() sucessful'); log::returnLog($routeMatched); return $routeMatched; }
public function __destruct() { if (!empty($this->_con)) { $this->close(); } log::accessLog('access __destruct() success!'); }
public function __destruct() { if (!$this->close()) { log::errorLog('__destruct fail'); } log::accessLog('access close() success!'); //log::returnLog(true); //return true ; }
/** * 直接放置查询 * @access public * @static * @param String $query * @return mixed * @example * <p> * accessLayer::query("SELECT * FROM sg_application"); * </p> */ public static function query($query, $accessType = self::MONGO_NS) { $result = self::_getInstance($accessType)->_connect()->query($query); log::accessLog('Access query() success'); log::returnLog($result); return $result; }