配置文件调整

控制器类的ajaxReturn方法调整
This commit is contained in:
thinkphp
2015-02-23 15:38:12 +08:00
parent 1a4a102b49
commit b8344fa91a
8 changed files with 78 additions and 65 deletions

View File

@@ -26,17 +26,17 @@ class App {
static public function run($config) { static public function run($config) {
// 日志初始化 // 日志初始化
Log::init(['type'=>$config['log_type'],'log_path'=> $config['log_path']]); Log::init($config['log']);
// 缓存初始化 // 缓存初始化
Cache::connect(['type'=>$config['cache_type'],'temp'=> $config['cache_path']]); Cache::connect($config['cache']);
// 加载框架底层语言包 // 加载框架底层语言包
is_file(THINK_PATH.'Lang/'.strtolower(Config::get('default_lang')).EXT) && Lang::set(include THINK_PATH.'Lang/'.strtolower(Config::get('default_lang')).EXT); is_file(THINK_PATH.'Lang/'.strtolower(Config::get('default_lang')).EXT) && Lang::set(include THINK_PATH.'Lang/'.strtolower(Config::get('default_lang')).EXT);
// 启动session // 启动session
if(!IS_CLI) { if(!IS_CLI) {
Session::init(['prefix'=>$config['session_prefix'],'auto_start'=>$config['session_auto_start']]); Session::init($config['session']);
} }
if(is_file(APP_PATH.'build.php')) { // 自动化创建脚本 if(is_file(APP_PATH.'build.php')) { // 自动化创建脚本
Create::build(include APP_PATH.'build.php'); Create::build(include APP_PATH.'build.php');
@@ -274,7 +274,7 @@ class App {
unset($_GET[$config['var_action']], $_GET[$config['var_controller']], $_GET[$config['var_module']]); unset($_GET[$config['var_action']], $_GET[$config['var_controller']], $_GET[$config['var_module']]);
//保证$_REQUEST正常取值 //保证$_REQUEST正常取值
$_REQUEST = array_merge($_POST, $_GET); $_REQUEST = array_merge($_POST, $_GET , $_COOKIE);
} }
static private function getModule($config){ static private function getModule($config){

View File

@@ -23,7 +23,7 @@ class File {
'path_level' => 1, 'path_level' => 1,
'prefix' => '', 'prefix' => '',
'length' => 0, 'length' => 0,
'temp' => '', 'path' => '',
'data_compress' => false, 'data_compress' => false,
]; ];
@@ -35,7 +35,7 @@ class File {
if(!empty($options)) { if(!empty($options)) {
$this->options = array_merge($this->options,$options); $this->options = array_merge($this->options,$options);
} }
if(substr($this->options['temp'], -1) != '/') $this->options['temp'] .= '/'; if(substr($this->options['path'], -1) != '/') $this->options['path'] .= '/';
$this->init(); $this->init();
} }
@@ -46,8 +46,8 @@ class File {
*/ */
private function init() { private function init() {
// 创建项目缓存目录 // 创建项目缓存目录
if (!is_dir($this->options['temp'])) { if (!is_dir($this->options['path'])) {
if (! mkdir($this->options['temp'],0755)) if (! mkdir($this->options['path'],0755))
return false; return false;
} }
} }
@@ -67,14 +67,14 @@ class File {
for($i=0;$i<$len;$i++) { for($i=0;$i<$len;$i++) {
$dir .= $name{$i}.'/'; $dir .= $name{$i}.'/';
} }
if(!is_dir($this->options['temp'].$dir)) { if(!is_dir($this->options['path'].$dir)) {
mkdir($this->options['temp'].$dir,0755,true); mkdir($this->options['path'].$dir,0755,true);
} }
$filename = $dir.$this->options['prefix'].$name.'.php'; $filename = $dir.$this->options['prefix'].$name.'.php';
}else{ }else{
$filename = $this->options['prefix'].$name.'.php'; $filename = $this->options['prefix'].$name.'.php';
} }
return $this->options['temp'].$filename; return $this->options['path'].$filename;
} }
/** /**

View File

@@ -20,7 +20,7 @@ class Secache {
protected $handler = null; protected $handler = null;
protected $options = [ protected $options = [
'project' => '', 'project' => '',
'temp' => '', 'path' => '',
'expire' => 0, 'expire' => 0,
'prefix' => '', 'prefix' => '',
'length' => 0, 'length' => 0,
@@ -35,9 +35,9 @@ class Secache {
if(!empty($options)) { if(!empty($options)) {
$this->options = array_merge($this->options,$options); $this->options = array_merge($this->options,$options);
} }
if(substr($this->options['temp'], -1) != '/') $this->options['temp'] .= '/'; if(substr($this->options['path'], -1) != '/') $this->options['path'] .= '/';
$this->handler = new SecacheClient; $this->handler = new SecacheClient;
$this->handler->workat($this->options['temp'].$this->options['project']); $this->handler->workat($this->options['path'].$this->options['project']);
} }
/** /**

View File

@@ -19,7 +19,7 @@ class Simple {
protected $options = [ protected $options = [
'prefix' => '', 'prefix' => '',
'temp' => '', 'path' => '',
]; ];
/** /**
@@ -30,7 +30,7 @@ class Simple {
if(!empty($options)) { if(!empty($options)) {
$this->options = array_merge($this->options,$options); $this->options = array_merge($this->options,$options);
} }
if(substr($this->options['temp'], -1) != '/') $this->options['temp'] .= '/'; if(substr($this->options['path'], -1) != '/') $this->options['path'] .= '/';
} }
/** /**
@@ -40,7 +40,7 @@ class Simple {
* @return string * @return string
*/ */
private function filename($name) { private function filename($name) {
return $this->options['temp'].$this->options['prefix'].md5($name).'.php'; return $this->options['path'].$this->options['prefix'].md5($name).'.php';
} }
/** /**

View File

@@ -50,7 +50,7 @@ class Config {
// 获取配置参数 为空则获取所有配置 // 获取配置参数 为空则获取所有配置
static public function get($name=null,$range='') { static public function get($name=null,$range='') {
$range = $range?$range:self::$_range; $range = $range ? $range : self::$_range;
// 无参数时获取所有 // 无参数时获取所有
if (empty($name)) { if (empty($name)) {
return self::$_config[$range]; return self::$_config[$range];
@@ -67,7 +67,7 @@ class Config {
// 设置配置参数 name为数组则为批量设置 // 设置配置参数 name为数组则为批量设置
static public function set($name, $value=null,$range='') { static public function set($name, $value=null,$range='') {
$range = $range?$range:self::$_range; $range = $range ? $range : self::$_range;
if(!isset(self::$_config[$range])) { if(!isset(self::$_config[$range])) {
self::$_config[$range] = []; self::$_config[$range] = [];
} }

View File

@@ -73,42 +73,43 @@ class Controller {
* @access protected * @access protected
* @param mixed $data 要返回的数据 * @param mixed $data 要返回的数据
* @param String $type AJAX返回数据格式 * @param String $type AJAX返回数据格式
* @param mixed $fun 数据处理方法
* @return void * @return void
*/ */
protected function ajaxReturn($data, $type='') { protected function ajaxReturn($data, $type='',$fun='') {
if(empty($type)) $type = Config::get('default_ajax_return'); if(empty($type)) {
switch (strtoupper($type)){ $type = Config::get('default_ajax_return');
case 'JSON': }
// 返回JSON数据格式到客户端 包含状态信息 $headers = [
header('Content-Type:application/json; charset=utf-8'); 'json' => 'application/json',
$data = Transform::jsonEncode($data); 'xml' => 'text/xml',
break; 'jsonp' => 'application/javascript',
case 'XML': 'script'=> 'application/javascript',
// 返回xml格式数据 'html' => 'text/html',
header('Content-Type:text/xml; charset=utf-8'); 'text' => 'text/plain',
$data = Transform::xmlEncode($data); ];
break; $type = strtolower($type);
case 'JSONP': if(isset($headers[$type])){
// 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:'.$headers[$type].'; charset=utf-8');
header('Content-Type:application/javascript; charset=utf-8'); }
$handler = isset($_GET[C('var_jsonp_handler')]) ? $_GET[C('var_jsonp_handler')] : C('default_jsonp_handler'); if($fun && is_callable($fun)){
$data = $handler . '(' . Transform::jsonEncode($data) . ');'; $data = call_user_func($fun,$data);
break; }else{
case 'SCRIPT': switch ($type){
// 返回可执行的js脚本 case 'json':
header('Content-Type:application/javascript; charset=utf-8'); // 返回JSON数据格式到客户端 包含状态信息
break; $data = Transform::jsonEncode($data);
case 'HTML': break;
// 返回html片段 case 'xml':
header('Content-Type:text/html; charset=utf-8'); // 返回xml格式数据
break; $data = Transform::xmlEncode($data);
case 'TEXT': break;
// 返回一段纯文本 case 'jsonp':
header('Content-Type:text/plain; charset=utf-8'); // 返回JSON数据格式到客户端 包含状态信息
break; $handler = isset($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler');
default: $data = $handler . '(' . Transform::jsonEncode($data) . ');';
// 用于扩展其他返回格式数据 break;
$data = Hook::listen('ajax_return', $data); }
} }
exit($data); exit($data);
} }

View File

@@ -14,9 +14,9 @@ namespace think\log\driver;
class File { class File {
protected $config = [ protected $config = [
'log_time_format' => ' c ', 'time_format' => ' c ',
'log_file_size' => 2097152, 'file_size' => 2097152,
'log_path' => '', 'path' => '',
]; ];
// 实例化并传入参数 // 实例化并传入参数
@@ -32,11 +32,11 @@ class File {
* @return void * @return void
*/ */
public function write($log,$destination='') { public function write($log,$destination='') {
$now = date($this->config['log_time_format']); $now = date($this->config['time_format']);
if(empty($destination)) if(empty($destination))
$destination = $this->config['log_path'].date('y_m_d').'.log'; $destination = $this->config['path'].date('y_m_d').'.log';
//检测日志文件大小,超过配置大小则备份日志文件重新生成 //检测日志文件大小,超过配置大小则备份日志文件重新生成
if(is_file($destination) && floor($this->config['log_file_size']) <= filesize($destination) ) if(is_file($destination) && floor($this->config['file_size']) <= filesize($destination) )
rename($destination,dirname($destination).'/'.time().'-'.basename($destination)); rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination); error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination);
} }

View File

@@ -41,12 +41,6 @@ return [
'var_jsonp_handler' => 'callback', 'var_jsonp_handler' => 'callback',
'template_engine' => 'think', 'template_engine' => 'think',
'common_module' => 'Common', 'common_module' => 'Common',
'log_path' => LOG_PATH,
'log_type' => 'File',
'cache_type' => 'File',
'caceh_path' => CACHE_PATH,
'session_prefix' => 'think',
'session_auto_start' => true,
'action_bind_class' => false, 'action_bind_class' => false,
'url_module_map' => [], 'url_module_map' => [],
@@ -55,6 +49,24 @@ return [
'error_page' => '', // 错误定向页面 'error_page' => '', // 错误定向页面
'show_error_msg' => false, // 显示错误信息 'show_error_msg' => false, // 显示错误信息
'log' => [
'type' => 'File',
'path' => LOG_PATH,
]
'cache' => [
'type' => 'File',
'path' => CACHE_PATH,
'prefix' => '',
'expire' => 0,
]
'session' => [
'prefix' => 'think',
'type' => '',
'auto_start' => true,
]
/* 数据库设置 */ /* 数据库设置 */
'database' => [ 'database' => [
'type' => 'mysql', // 数据库类型 'type' => 'mysql', // 数据库类型