本文整理匯總了PHP中think\Config類的典型用法代碼示例。如果您正苦於以下問題:PHP Config類的具體用法?PHP Config怎麽用?PHP Config使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Config類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testFill
public function testFill()
{
$model = new Model('', $this->getConfig());
$data = ['username' => '', 'nickname' => 'nickname', 'phone' => ' 123456', 'hobby' => ['1', '2'], 'cityid' => '1', 'a' => 'a', 'b' => 'b'];
$auto = ['user' => ['__option__' => ['value_fill' => 'username,password,phone', 'exists_fill' => 'nickname'], 'username' => ['strtolower', 'callback'], 'password' => ['md5', 'callback'], 'nickname' => [[&$this, 'fillName'], 'callback', 'cn_'], 'phone' => function ($value, $data) {
return trim($value);
}, 'hobby' => ['', 'serialize'], 'cityid' => ['1', 'ignore'], 'address' => ['address'], 'integral' => 0, ['reg_time', 'time', 'callback'], ['login_time', function ($value, $data) {
return $data['reg_time'];
}], 'ab' => ['a,b', 'serialize']]];
\think\Config::set('auto', $auto);
$result = $model->auto('user')->create($data);
$data['nickname'] = 'cn_nickname';
$data['phone'] = '123456';
$data['hobby'] = serialize($data['hobby']);
$data['address'] = 'address';
$data['integral'] = 0;
$data['reg_time'] = time();
$data['login_time'] = $data['reg_time'];
$data['ab'] = serialize(['a' => 'a', 'b' => 'b']);
unset($data['cityid'], $data['a'], $data['b']);
$this->assertEquals($data, $result);
// 測試帶.和*的鍵名
$data = ['name' => ['a' => 'a', 'b' => 'b'], 'goods' => [0 => [0 => ['item' => 'item', 'price' => ''], 1 => ['item' => 'item2', 'price' => '']]]];
$test = ['name.*' => 'name', 'goods.*.*.price' => 100];
$result = $model->auto($test)->create($data);
$data['name']['a'] = $data['name']['b'] = 'name';
$data['goods'][0][0]['price'] = 100;
$data['goods'][0][1]['price'] = 100;
$this->assertEquals($data, $result);
}
示例2: checkAuth
/**
* 檢查菜單權限
* @return boolean
*/
public static function checkAuth($uid, $node)
{
$adminUsers = \think\Config::get('administrator');
// 當前用戶不是超級用戶,要做權限驗證
if (!in_array($uid, $adminUsers)) {
// 根據控製器 去驗證
$nodeId = Db::name('Menu')->where('url', $node)->value('id');
if ($nodeId) {
$nodes = session('user_auth_nodes');
if (!$nodes) {
// 獲取當前用戶的授權節點
$gIds = self::getGroupIds($uid);
if ($gIds) {
$nodes = Db::name('Auth')->where('id', 'in', $gIds)->column('rules');
$nodes = implode($nodes, ',');
$nodes = trim($nodes, ',');
$nodes = explode(',', $nodes);
session('user_auth_nodes', $nodes);
} else {
return false;
}
}
if (in_array($nodeId, $nodes)) {
return true;
} else {
return false;
}
} else {
// 不存在的節點 不驗證
return true;
}
} else {
return true;
}
}
示例3: init
/**
* 自動初始化緩存
* @access public
* @return void
*/
public static function init()
{
if (is_null(self::$handler)) {
// 自動初始化緩存
self::connect(Config::get('cache'));
}
}
示例4: buildCacheContent
protected function buildCacheContent($module)
{
$content = '';
$path = realpath(APP_PATH . $module) . DS;
// 加載模塊配置
$config = \think\Config::load(CONF_PATH . $module . 'config' . CONF_EXT);
// 加載應用狀態配置
if ($module && $config['app_status']) {
$config = \think\Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
}
// 讀取擴展配置文件
if ($module && $config['extra_config_list']) {
foreach ($config['extra_config_list'] as $name => $file) {
$filename = CONF_PATH . $module . $file . CONF_EXT;
\think\Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
}
}
// 加載別名文件
if (is_file(CONF_PATH . $module . 'alias' . EXT)) {
$content .= '\\think\\Loader::addClassMap(' . var_export(include CONF_PATH . $module . 'alias' . EXT, true) . ');' . PHP_EOL;
}
// 加載行為擴展文件
if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
$content .= '\\think\\Hook::import(' . var_export(include CONF_PATH . $module . 'tags' . EXT, true) . ');' . PHP_EOL;
}
// 加載公共文件
if (is_file($path . 'common' . EXT)) {
$content .= substr(php_strip_whitespace($path . 'common' . EXT), 5) . PHP_EOL;
}
$content .= '\\think\\Config::set(' . var_export(\think\Config::get(), true) . ');';
return $content;
}
示例5: store
/**
* 切換緩存類型 需要配置 cache.type 為 complex
* @access public
* @param string $name 緩存標識
* @return \think\cache\Driver
*/
public static function store($name)
{
if ('complex' == Config::get('cache.type')) {
self::connect(Config::get('cache.' . $name), strtolower($name));
}
return self::$handler;
}
示例6: fetch
/**
* 被調用接口
* 載入Smarty模板引擎,獲得相關內容
*/
public function fetch($templateFile, $var)
{
// 載入Smarty文件
include_once CORE_PATH . 'Views/Smarty/Smarty.class.php';
// 實例化
$tpl = new SmartyEngine();
// 是否開啟緩存, 模板目錄, 編譯目錄, 緩存目錄
$tpl->caching = Config::get('TMPL_CACHE_ON');
$tpl->template_dir = THEME_PATH;
$tpl->compile_dir = CACHE_PATH;
$tpl->cache_dir = TEMP_PATH;
$tpl->debugging = false;
$tpl->left_delimiter = '{{';
$tpl->right_delimiter = '}}';
// 自定義配置
if (C('TMPL_ENGINE_CONFIG')) {
$config = C('TMPL_ENGINE_CONFIG');
foreach ($config as $key => $val) {
$tpl->{$key} = $val;
}
}
// 輸出
$tpl->assign($var);
$tpl->display($templateFile);
}
示例7: send
/**
* 發送數據到客戶端
* @access public
* @param mixed $data 數據
* @param string $type 返回類型
* @param bool $return 是否返回數據
* @return mixed
*/
public function send($data = [], $type = '', $return = false)
{
if ('' == $type) {
$type = $this->type ?: (IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'));
}
$type = strtolower($type);
$data = $data ?: $this->data;
if (!headers_sent() && isset($this->contentType[$type])) {
header('Content-Type:' . $this->contentType[$type] . '; charset=utf-8');
}
if (is_callable($this->transform)) {
$data = call_user_func_array($this->transform, [$data]);
} else {
switch ($type) {
case 'json':
// 返回JSON數據格式到客戶端 包含狀態信息
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
break;
case 'jsonp':
// 返回JSON數據格式到客戶端 包含狀態信息
$handler = !empty($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler');
$data = $handler . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');';
break;
}
}
APP_HOOK && Hook::listen('return_data', $data);
if ($return) {
return $data;
}
echo $data;
$this->isExit() && exit;
}
示例8: C
function C($name = '', $value = null, $range = '')
{
if (is_null($value) && is_string($name)) {
return \think\Config::get($name, $range);
} else {
return \think\Config::set($name, $value, $range);
}
}
示例9: __construct
public function __construct($config = [])
{
$this->config = ['tpl_path' => App::$modulePath . 'view' . DS, 'tpl_suffix' => Config::get('view.engine_config.suffix') ?: '.html', 'tpl_cache_path' => CACHE_PATH, 'tpl_cache_suffix' => Config::get('view.engine_config.cache') ?: '.php', 'attr' => 'php-'];
$this->template = new \Angular($this->config);
// 初始化模板編譯存儲器
$storage = Config::get('compile_type') ?: '\\think\\template\\driver\\File';
$this->storage = new $storage();
}
示例10: initView
/**
* 架構函數 初始化視圖類 並采用內置模板引擎
* @access public
*/
public function initView()
{
// 模板引擎參數
if (is_null($this->view)) {
$this->view = \think\View::instance(Config::get());
// 隻能這樣寫,不然view會衝突
}
}
示例11: init
/**
* session初始化
* @param array $config
* @return void
* @throws \think\Exception
*/
public static function init(array $config = [])
{
if (empty($config)) {
$config = Config::get('session');
}
// 記錄初始化信息
App::$debug && Log::record('[ SESSION ] INIT ' . var_export($config, true), 'info');
$isDoStart = false;
if (isset($config['use_trans_sid'])) {
ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0);
}
// 啟動session
if (!empty($config['auto_start']) && PHP_SESSION_ACTIVE != session_status()) {
ini_set('session.auto_start', 0);
$isDoStart = true;
}
if (isset($config['prefix'])) {
self::$prefix = $config['prefix'];
}
if (isset($config['var_session_id']) && isset($_REQUEST[$config['var_session_id']])) {
session_id($_REQUEST[$config['var_session_id']]);
} elseif (isset($config['id']) && !empty($config['id'])) {
session_id($config['id']);
}
if (isset($config['name'])) {
session_name($config['name']);
}
if (isset($config['path'])) {
session_save_path($config['path']);
}
if (isset($config['domain'])) {
ini_set('session.cookie_domain', $config['domain']);
}
if (isset($config['expire'])) {
ini_set('session.gc_maxlifetime', $config['expire']);
ini_set('session.cookie_lifetime', $config['expire']);
}
if (isset($config['use_cookies'])) {
ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0);
}
if (isset($config['cache_limiter'])) {
session_cache_limiter($config['cache_limiter']);
}
if (isset($config['cache_expire'])) {
session_cache_expire($config['cache_expire']);
}
if (!empty($config['type'])) {
// 讀取session驅動
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']);
// 檢查驅動類
if (!class_exists($class) || !session_set_save_handler(new $class($config))) {
throw new ClassNotFoundException('error session handler:' . $class, $class);
}
}
if ($isDoStart) {
session_start();
}
}
示例12: output
/**
* 調試輸出接口
* @access public
* @param Response $response Response對象
* @param array $log 日誌信息
* @return bool
*/
public function output(Response $response, array $log = [])
{
$request = Request::instance();
$contentType = $response->getHeader('Content-Type');
$accept = $request->header('accept');
if (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
return false;
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
return false;
}
// 獲取基本信息
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / $runtime, 2);
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
// 頁麵Trace信息
if (isset($_SERVER['HTTP_HOST'])) {
$uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} else {
$uri = 'cmd:' . implode(' ', $_SERVER['argv']);
}
$base = ['請求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $uri, '運行時間' => number_format($runtime, 6) . 's [ 吞吐率:' . $reqs . 'req/s ] 內存消耗:' . $mem . 'kb 文件加載:' . count(get_included_files()), '查詢信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ', '緩存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes', '配置加載' => count(Config::get())];
if (session_id()) {
$base['會話信息'] = 'SESSION_ID=' . session_id();
}
$info = Debug::getFile(true);
// 頁麵Trace信息
$trace = [];
foreach ($this->config['trace_tabs'] as $name => $title) {
$name = strtolower($name);
switch ($name) {
case 'base':
// 基本信息
$trace[$title] = $base;
break;
case 'file':
// 文件信息
$trace[$title] = $info;
break;
default:
// 調試信息
if (strpos($name, '|')) {
// 多組信息
$names = explode('|', $name);
$result = [];
foreach ($names as $name) {
$result = array_merge($result, isset($log[$name]) ? $log[$name] : []);
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($log[$name]) ? $log[$name] : '';
}
}
}
// 調用Trace頁麵模板
ob_start();
include $this->config['trace_file'];
return ob_get_clean();
}
示例13: result
/**
* 返回封裝後的API數據到客戶端
* @access protected
* @param mixed $data 要返回的數據
* @param string $msg 提示信息
* @param integer $code 返回的code
* @param string $url 重定向地址
* @param integer $wait 跳轉等待時間
* @return void
*/
public function result($data = '', $msg = '', $code = 0, $url = '', $wait = 0)
{
$result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'url' => $url, 'wait' => $wait];
if ('html' == Config::get('default_return_type')) {
return $this->fetch(Config::get('dispatch_jump_tmpl'), $result);
} else {
return $result;
}
}
示例14: save
/**
* 日誌寫入接口
* @access public
* @param array $log 日誌信息
* @return bool
*/
public function save(array $log = [])
{
if (IS_AJAX || IS_CLI || IS_API || 'html' != Config::get('default_return_type')) {
// ajax cli api方式下不輸出
return false;
}
// 獲取基本信息
$runtime = microtime(true) - START_TIME;
$reqs = number_format(1 / $runtime, 2);
$runtime = number_format($runtime, 6);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
// 頁麵Trace信息
$base = ['請求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '運行時間' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 內存消耗:{$mem}kb 文件加載:" . count(get_included_files()), '查詢信息' => \think\Db::$queryTimes . ' queries ' . \think\Db::$executeTimes . ' writes ', '緩存信息' => \think\Cache::$readTimes . ' reads,' . \think\Cache::$writeTimes . ' writes', '配置加載' => count(Config::get())];
if (session_id()) {
$base['會話信息'] = 'SESSION_ID=' . session_id();
}
$info = Debug::getFile(true);
// 獲取調試日誌
$debug = [];
foreach ($log as $line) {
$debug[$line['type']][] = $line['msg'];
}
// 頁麵Trace信息
$trace = [];
foreach ($this->config['trace_tabs'] as $name => $title) {
$name = strtolower($name);
switch ($name) {
case 'base':
// 基本信息
$trace[$title] = $base;
break;
case 'file':
// 文件信息
$trace[$title] = $info;
break;
default:
// 調試信息
if (strpos($name, '|')) {
// 多組信息
$names = explode('|', $name);
$result = [];
foreach ($names as $name) {
$result = array_merge($result, isset($debug[$name]) ? $debug[$name] : []);
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($debug[$name]) ? $debug[$name] : '';
}
}
}
// 調用Trace頁麵模板
ob_start();
include $this->config['trace_file'];
echo ob_get_clean();
return true;
}
示例15: getKey
/**
* Fetch the encryption key
*
* Returns it as MD5 in order to have an exact-length 128 bit key.
* Mcrypt is sensitive to keys that are not the correct length
*
* @access public
* @param string
* @return string
*/
public function getKey($key = '')
{
if ($key == '') {
if ($this->encryption_key != '') {
return $this->encryption_key;
}
$key = \think\Config::get('encryption_key');
}
return md5($key);
}