本文整理汇总了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);
}