我的介面架構---架構函數檔案common.php

來源:互聯網
上載者:User

標籤:

<?php defined(‘JDHU‘) OR die(‘no allow access‘);/** * 載入設定檔 */function &get_config($replace = array()){    static $config;    if (empty($config)) {        $file_path = APPPATH . ‘config/config.php‘;        //如果不存存在正式配置,載入環境配置        if (!file_exists($file_path)) {            $file_path = APPPATH . ‘config/‘.ENVIRONMENT.‘config.php‘;        }        require($file_path);    }    //替換設定檔中    foreach ($replace as $key => $value) {        $config[$key] = $value;    }    return $config;}/** * 載入架構/應用類庫 */function &load_class($class, $directory = ‘libraries‘, $param = NULL){    static $_classes = array();    //如果類載入過了,返回類    if (isset($_classes[$class])) {        return $_classes[$class];    }    $name = FALSE;    //引入核心類    //首先尋找應用,其次尋找架構    //覆蓋架構類檔案:如果應用存在JDHU類,則不引入架構類    foreach (array(APPPATH, JDHU) as $path) {        if (file_exists($path.$directory.‘/‘.$class.‘.php‘)) {            //核心類名            $name = ‘JDHU_‘.$class;            //備忘:class_exists 第二個參數預設true,調用__autoload()函數            if (class_exists($name, FALSE) === FALSE) {                require_once($path.$directory.‘/‘.$class.‘.php‘);            }            break;        }    }    //引入繼承類:繼承架構類或覆蓋類    if (file_exists(APPPATH.$directory.‘/‘.config_item(‘subclass_prefix‘).$class.‘.php‘)) {        //繼承類名        $name = config_item(‘subclass_prefix‘).$class;        require_once(APPPATH.$directory.‘/‘.$name.‘.php‘);    }    //擷取被載入的類,記錄已被載入    is_loaded($class);    //如果有參數,則帶參數初始化類    $_classes[$class] = isset($param) ? new $name($param) : new $name();    return $_classes[$class];}/** * 擷取配置項 */function config_item($item){    static $_config;    if (empty($_config)) {                // 引用不能直接賦值給靜態變數,可以賦值給靜態變數數組        $_config[0] =& get_config();    }    return $_config[0][$item];}/** * 擷取被載入的類,如果有類名,記錄已被載入 */function &is_loaded($class=‘‘){    static $_is_loaded = array();    if ($class) {        //類名        $_is_loaded[strtolower($class)] = $class;    }    return $_is_loaded;}/** * 輸出json錯誤並退出 */function die_error($message){    static $_response;    if ($_response === NULL) {        $_response[0] =& load_class(‘Response‘, ‘core‘);    }    log_message(‘error‘, $message);    $_response[0]->die_error($message);}/** * 記錄日誌 */function log_message($level, $message){    static $_log;    if ($_log === NULL) {        $_log[0] =& load_class(‘Log‘, ‘core‘);    }    $_log[0]->write_log($level, $message);}/** * 擷取ip地址 */function ip_address(){    static $_ip_address = ‘‘;    if ($_ip_address) {        return $_ip_address;    }    $_ip_address = $_SERVER(‘REMOTE_ADDR‘);    return $_ip_address;}/** * 備忘:function &xxx() 返回結果的指標地址 */ ?>

我的介面架構---架構函數檔案common.php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.