phpccma經常使用函數記錄

    /**
     * 加載類文件函數
     * @param string $classname 類名
     * @param string $path 擴展地址
     * @param intger $initialize 是否初始化
     */
    private static function _load_class($classname, $path = '', $initialize = 1) {
     //$path 爲空則爲 load_sys_class
     //$path 爲'model'則爲 load_model
    //$path 爲'modules'+DIRECTORY_SEPARATOR+$m+DIRECTORY_SEPARATOR+'classes'則爲load_app_class
static $classes = array(); if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'classes'; $key = md5($path.$classname); if (isset($classes[$key])) { if (!empty($classes[$key])) { return $classes[$key]; } else { return true; } } if (file_exists(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) { include PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php'; $name = $classname; if ($my_path = self::my_path(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) { include $my_path; $name = 'MY_'.$classname; } if ($initialize) { $classes[$key] = new $name; } else { $classes[$key] = true; } return $classes[$key]; } else { return false; } } /** * 加載函數庫 * @param string $func 函數庫名 * @param string $path 地址 */ private static function _load_func($func, $path = '') {
    //$path 爲空該函數則成了load_sys_func
    //$path 爲'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.'functions'則爲load_app_func
    
static $funcs = array(); if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'functions'; $path .= DIRECTORY_SEPARATOR.$func.'.func.php'; $key = md5($path); if (isset($funcs[$key])) return true; if (file_exists(PC_PATH.$path)) { include PC_PATH.$path; } else { $funcs[$key] = false; return false; } $funcs[$key] = true; return true; } /** * 加載配置文件 * @param string $file 配置文件 * @param string $key 要獲取的配置薦 * @param string $default 默認配置。當獲取配置項目失敗時該值發生做用。 * @param boolean $reload 強制從新加載。 */ public static function load_config($file, $key = '', $default = '', $reload = false) {
    //返回 "cache/$file"->key 對應的值
static $configs = array(); if (!$reload && isset($configs[$file])) { if (empty($key)) { return $configs[$file]; } elseif (isset($configs[$file][$key])) { return $configs[$file][$key]; } else { return $default; } } $path = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$file.'.php'; if (file_exists($path)) { $configs[$file] = include $path; } if (empty($key)) { return $configs[$file]; } elseif (isset($configs[$file][$key])) { return $configs[$file][$key]; } else { return $default; } }
相關文章
相關標籤/搜索