日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

config.class.php,Config.class.php

發(fā)布時(shí)間:2023/12/2 php 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 config.class.php,Config.class.php 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

defined('IN_MY_PHP') || die(0);

/**

* 配置文件,內(nèi)容如下

* return [

* 'jfzt'=>[

* // 方式一(推薦)

* ['val'=>0, 'label'=>'xxx0', 'style'=>'txt-danger'],

* ['val'=>1, 'label'=>'xxx1', 'style'=>'txt-success'],

* // 方式二(簡(jiǎn)化,不支持樣式)

* 0=>xxx0,

* 1=>xxx1,

* ...

* ],

* ];

* @author netmou

*/

class Config

{

private static $container = array();

/** 加載配置 */

public static function load($name, $path = null)

{

if (!isset(self::$container[$name])) {

$fileName = $name.'.cfg.php';

if ($path == null) {

$path = dirname($_SERVER['SCRIPT_FILENAME']);

}

$file = rtrim(preg_replace('/[\\\\\\/]/', DS, $path), DS) . DS . $fileName;

if (file_exists($file) && is_readable($file)) {

self::$container[$name] = include $file; // the method must be include

if(!is_array(self::$container[$name])){

trigger_error('配置文件錯(cuò)誤!', E_USER_ERROR);

}

}else{

trigger_error("配置文件:'{$file}' 未找到.", E_USER_ERROR);

}

}

return self::$container[$name];

}

/** 獲取標(biāo)簽 */

public static function getLabel($name, $val, $style = false, $mod = null){

if($mod == null){

$mod = basename(dirname($_SERVER['SCRIPT_FILENAME']));

}

$context = self::load($mod, null);

if($context[$name] == null){

trigger_error('未找到配置項(xiàng)!', E_USER_ERROR);

}

if(is_array($val)){

$val = $val[$name];

}

foreach($context[$name] as $cVal => &$cLabel){

if(is_scalar($cLabel) && $cVal == $val){

return $cLabel;

}

if(is_array($cLabel) && $cLabel['val'] == $val){

return ($style == false)?$cLabel['label']:''.$cLabel['label'].'';

}

}

return '';

}

/** 獲取內(nèi)容 */

public static function getData($name, $mod = null){

if($mod == null){

$mod = basename(dirname($_SERVER['SCRIPT_FILENAME']));

}

$context = self::load($mod, null);

if($context[$name] == null){

trigger_error("未找到配置項(xiàng),在{$mod}.cfg.php中!", E_USER_ERROR);

}

$retData = array();

foreach($context[$name] as $cVal => &$cLabel){

if(is_scalar($cLabel)){

$retData[$cVal] = $cLabel;

}

if(is_array($cLabel)){

$retData[$cLabel['val']] = $cLabel['label'];

}

}

return $retData;

}

}

一鍵復(fù)制

編輯

Web IDE

原始數(shù)據(jù)

按行查看

歷史

總結(jié)

以上是生活随笔為你收集整理的config.class.php,Config.class.php的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。