Skip to content

Commit

Permalink
1、将默认模式改为运行状态;
Browse files Browse the repository at this point in the history
2、优化getIpAddr函数;
3、修改File缓存配置问题
  • Loading branch information
steezer committed Mar 17, 2022
1 parent 6ffdcc3 commit 997d3c3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 45 deletions.
7 changes: 5 additions & 2 deletions kernel/Library/Client.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ static function getOS(){

// 获得访客真实ip
static function getIpAddr($isOnline=0){
$ip='127.0.0.1';
if(getenv('HTTP_CLIENT_IP')){
$ip=getenv('HTTP_CLIENT_IP');
}else if(getenv('HTTP_X_FORWARDED_FOR')){
$ip=getenv('HTTP_X_FORWARDED_FOR');
}else if(getenv('REMOTE_ADDR')){
$ip=getenv('REMOTE_ADDR');
}else if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$ip=$_SERVER["HTTP_CLIENT_IP"];
}else if(!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
}else if(!empty($_SERVER['REMOTE_ADDR'])){
$ip=$_SERVER['REMOTE_ADDR'];
}
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ // 获取代理ip
$ips=explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
Expand Down
68 changes: 34 additions & 34 deletions kernel/Library/Model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Model implements ArrayAccess{
protected $db=null;

// 数据库对象池
private $_db=array();
private $_db=[];
// 主键名称
protected $pk='id';
// 主键是否自动增长
Expand All @@ -70,41 +70,41 @@ class Model implements ArrayAccess{
// 最近错误信息
protected $error='';
// 字段信息
protected $fields=array();
protected $fields=[];
// 数据信息
protected $data=array();
protected $data=[];
// 查询表达式参数
protected $options=array();
protected $options=[];

/**
* 自动验证定义
* array(field,rule,message,condition,type,when,params)
*
* @var array
*/
protected $_validate=array(); // 自动验证定义
protected $_validate=[]; // 自动验证定义

/**
* 自动填充内容
* array('field','填充内容','填充条件','附加规则',[额外参数])
*
* @var array
*/
protected $_auto=array(); // 自动完成定义
protected $_auto=[]; // 自动完成定义

/**
* 字段映射定义
*
* @var array
*/
protected $_map=array();
protected $_map=[];

/**
* 命名范围定义
*
* @var array
*/
protected $_scope=array();
protected $_scope=[];

// 是否自动检测数据表字段信息
protected $autoCheckFields=true;
Expand Down Expand Up @@ -398,13 +398,13 @@ protected function _after_change($data, $options, $action){
* @param boolean $replace 是否replace
* @return mixed
*/
public function add($data='',$options=array(),$replace=false){
public function add($data='',$options=[],$replace=false){
if(empty($data)){
// 没有传递数据,获取当前数据对象的值
if(!empty($this->data)){
$data=$this->data;
// 重置数据
$this->data=array();
$this->data=[];
}else{
$this->error=L('data type invalid');
return false;
Expand Down Expand Up @@ -452,7 +452,7 @@ protected function _before_insert(&$data,$options){
protected function _after_insert($data,$options){
}

public function addAll($dataList,$options=array(),$replace=false){
public function addAll($dataList,$options=[],$replace=false){
if(empty($dataList)){
$this->error=L('data type invalid');
return false;
Expand Down Expand Up @@ -484,7 +484,7 @@ public function addAll($dataList,$options=array(),$replace=false){
* @param array $options 表达式
* @return boolean
*/
public function selectAdd($fields='',$table='',$options=array()){
public function selectAdd($fields='',$table='',$options=[]){
// 分析表达式
$options=$this->_parseOptions($options);
// 写入数据到数据库
Expand All @@ -506,13 +506,13 @@ public function selectAdd($fields='',$table='',$options=array()){
* @param array $options 表达式
* @return boolean
*/
public function save($data='',$options=array()){
public function save($data='',$options=[]){
if(empty($data)){
// 没有传递数据,获取当前数据对象的值
if(!empty($this->data)){
$data=$this->data;
// 重置数据
$this->data=array();
$this->data=[];
}else{
$this->error=L('data type invalid');
return false;
Expand Down Expand Up @@ -587,7 +587,7 @@ protected function _after_update($data,$options){
* @param mixed $options 表达式
* @return mixed
*/
public function delete($options=array()){
public function delete($options=[]){
$pk=$this->getPk();
if(empty($options) && empty($this->options['where'])){
// 如果删除条件为空 则删除当前数据对象所对应的记录
Expand All @@ -606,7 +606,7 @@ public function delete($options=array()){
}else{
$where[$pk]=$options;
}
$options=array();
$options=[];
$options['where']=$where;
}
// 根据复合主键删除记录
Expand Down Expand Up @@ -642,7 +642,7 @@ public function delete($options=array()){
}
$result=$this->db->delete($options);
if(false !== $result && is_numeric($result)){
$data=array();
$data=[];
if(isset($pkValue))
$data[$pk]=$pkValue;
$this->_after_delete($data, $options);
Expand All @@ -667,7 +667,7 @@ protected function _after_delete($data,$options){
* @param array $options 表达式参数
* @return mixed
*/
public function select($options=array()){
public function select($options=[]){
$pk=$this->getPk();
if(is_string($options) || is_numeric($options)){
// 根据主键查询
Expand All @@ -679,7 +679,7 @@ public function select($options=array()){
}else{
$where[$pk]=$options;
}
$options=array();
$options=[];
$options['where']=$where;
}elseif(is_array($options) && (count($options) > 0) && is_array($pk)){
// 根据复合主键查询
Expand Down Expand Up @@ -753,7 +753,7 @@ public function buildSql(){
* @param array $options 表达式参数
* @return array
*/
protected function _parseOptions($options=array()){
protected function _parseOptions($options=[]){
if(is_array($options))
$options=array_merge($this->options, $options);

Expand Down Expand Up @@ -791,7 +791,7 @@ protected function _parseOptions($options=array()){
}
}
// 查询过后清空sql表达式组装 避免影响下次查询
$this->options=array();
$this->options=[];
// 表达式过滤
$this->_options_filter($options);
return $options;
Expand Down Expand Up @@ -848,10 +848,10 @@ protected function _read_data($data){
* @param mixed $options 表达式参数
* @return mixed
*/
public function find($options=array()){
public function find($options=[]){
if(is_numeric($options) || is_string($options)){
$where[$this->getPk()]=$options;
$options=array();
$options=[];
$options['where']=$where;
}
// 根据复合主键查找记录
Expand Down Expand Up @@ -1063,7 +1063,7 @@ public function getField($field,$sepa=null){
$field=array_keys($resultSet[0]);
$key1=array_shift($field);
$key2=array_shift($field);
$cols=array();
$cols=[];
$isArray=count($_field)>2 || $_field[1]=='*';
foreach($resultSet as $result){
$name=$result[$key1];
Expand Down Expand Up @@ -1287,7 +1287,7 @@ private function autoOperation(&$data,$type){
switch(trim($auto[3])){
case 'function': // 使用函数进行填充 字段的值作为参数
case 'callback': // 使用回调方法
$args=isset($auto[4]) ? (array)$auto[4] : array();
$args=isset($auto[4]) ? (array)$auto[4] : [];
if(isset($data[$auto[0]])){
array_unshift($args, $data[$auto[0]]);
}
Expand Down Expand Up @@ -1336,7 +1336,7 @@ protected function autoValidation($data,$type){
// 属性验证
if(isset($_validate)){ // 如果设置了数据自动验证则进行数据验证
if($this->patchValidate){ // 重置验证错误信息
$this->error=array();
$this->error=[];
}
foreach($_validate as $key=>$val){
// 验证因子定义格式
Expand Down Expand Up @@ -1405,7 +1405,7 @@ protected function _validationFieldItem($data,$val){
switch(strtolower(trim($val[4]))){
case 'function': // 使用函数进行验证
case 'callback': // 调用方法进行验证
$args=isset($val[6]) ? (array)$val[6] : array();
$args=isset($val[6]) ? (array)$val[6] : [];
if(is_string($val[0]) && strpos($val[0], ','))
$val[0]=explode(',', $val[0]);
if(is_array($val[0])){
Expand All @@ -1429,7 +1429,7 @@ protected function _validationFieldItem($data,$val){
case 'unique': // 验证某个值是否唯一
if(is_string($val[0]) && strpos($val[0], ','))
$val[0]=explode(',', $val[0]);
$map=array();
$map=[];
if(is_array($val[0])){
// 支持多个字段验证
foreach($val[0] as $field)
Expand Down Expand Up @@ -1716,7 +1716,7 @@ public function startTrans(){
* @param array $options
* @return boolean
*/
public function commit($data=array(), $options=array()){
public function commit($data=[], $options=[]){
$this->autoCommit=true;
$result=$this->db->commit();
if($result){
Expand Down Expand Up @@ -1847,7 +1847,7 @@ public function getDbTables($usePrefix=true){
!is_null($this->tablePrefix) &&
$this->tablePrefix!==''
){
$returnTables=array();
$returnTables=[];
$prefixLength=strlen($this->tablePrefix);
foreach($tables as &$val){
if(strpos($val, $this->tablePrefix)===0){
Expand All @@ -1873,7 +1873,7 @@ public function data($data=''){
if(is_object($data)){
$data=get_object_vars($data);
}elseif(is_string($data)){
$param=array();
$param=[];
parse_str($data, $param);
$data=$param;
}elseif(!is_array($data)){
Expand Down Expand Up @@ -2035,7 +2035,7 @@ public function scope($scope='',$args=NULL){
}
}elseif(is_string($scope)){ // 支持多个命名范围调用 用逗号分割
$scopes=explode(',', $scope);
$options=array();
$options=[];
foreach($scopes as $name){
if(!isset($this->_scope[$name]))
continue;
Expand Down Expand Up @@ -2065,7 +2065,7 @@ public function where($where,$parse=null){
if(is_numeric($where)){
$pk=$this->getPk();
$val=$where;
$where=array();
$where=[];
$where[$pk]=$val;
}elseif(!is_null($parse) && is_string($where)){
if(!is_array($parse)){
Expand All @@ -2081,7 +2081,7 @@ public function where($where,$parse=null){
$where=get_object_vars($where);
}
if(is_string($where) && '' != $where){
$map=array();
$map=[];
$map['_string']=$where;
$where=$map;
}
Expand Down
15 changes: 8 additions & 7 deletions kernel/Service/Cache/Drivers/File.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class File extends Cache {
* 架构函数
* @access public
*/
public function __construct($options=array()) {
$options = array_merge(array (
'temp' => C('data_cache_path',env('data_cache_path','')),
'expire' => intval(C('data_cache_time',env('data_cache_time',60))),
'prefix' => C('data_cache_prefix',env('data_cache_prefix','')),
'length' => intval(C('data_cache_length',env('data_cache_length',0))),
),$options);
public function __construct($options=[]) {
$options = array_merge( [
'temp' => C('data_cache_path',env('data_cache_path','')),
'expire' => intval(C('data_cache_time',env('data_cache_time',60))),
'prefix' => C('data_cache_prefix',env('data_cache_prefix','')),
'length' => intval(C('data_cache_length',env('data_cache_length',0))),
], $options);

$this->options=$options;
if(substr($this->options['temp'], -1) != '/'){
$this->options['temp'] .= '/';
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ function_exists('date_default_timezone_set') && date_default_timezone_set('Etc/G
Loader::env();

/**
* 系统默认在调试模式下运行(支持自定义常量或环境变量app_debug),建议在生产系统中配置环境变量为false
* 系统默认在生产模式下运行(支持自定义常量或环境变量app_debug),建议在开发系统中配置环境变量为true
*/
!defined('APP_DEBUG') && define('APP_DEBUG', (bool)env('app_debug', true));
!defined('APP_DEBUG') && define('APP_DEBUG', (bool)env('app_debug', false));

/**
* 系统错误信息显示级别(支持自定义)
Expand Down

0 comments on commit 997d3c3

Please sign in to comment.