-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
优化SinglePHP.class.php兼容性 #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ function C($key,$value=null){ | |
halt('传入参数不正确'); | ||
} | ||
} | ||
return null; | ||
return true; | ||
} | ||
|
||
/** | ||
|
@@ -85,6 +85,8 @@ function M(){ | |
function includeIfExist($path){ | ||
if(file_exists($path)){ | ||
include $path; | ||
} else { | ||
halt('Invalid path:' . $path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处没必要停止程序运行,并不强制要求包含。对于需要强制包含的文件,可以把错误处理放在外围,错误信息可以更明确。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处如果路径不对,应该给一个warn级别的错误,halt确实欠妥~~ |
||
} | ||
} | ||
|
||
|
@@ -137,7 +139,7 @@ public function run(){ | |
if(C('USE_SESSION') == true){ | ||
session_start(); | ||
} | ||
C('APP_FULL_PATH', getcwd().'/'.C('APP_PATH').'/'); | ||
C('APP_FULL_PATH', realpath(getcwd().'/'.C('APP_PATH'))); | ||
includeIfExist( C('APP_FULL_PATH').'/common.php'); | ||
$pathMod = C('PATH_MOD'); | ||
$pathMod = empty($pathMod)?'NORMAL':$pathMod; | ||
|
@@ -149,12 +151,12 @@ public function run(){ | |
$pathInfo = isset($_SERVER['PATH_INFO'])?$_SERVER['PATH_INFO']:''; | ||
$pathInfoArr = explode('/',trim($pathInfo,'/')); | ||
if(isset($pathInfoArr[0]) && $pathInfoArr[0] !== ''){ | ||
$this->c = $pathInfoArr[0]; | ||
$this->c = ucfirst($pathInfoArr[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHP的类名是不区分大小写的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. autoload里面有include文件啊,所以首字母应该大写吧~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 嗯,但是我们这里并没有强制规定首字符要大写,假如开发者就是希望使用小写开头的Controller呢? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你下面都默认给大写的Index了, 还说什么小写啊~~~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里还是要加上ucfirst, 不加的话用小写访问include Controller的时候找不到文件 因为控制器的文件是首字母大写 |
||
}else{ | ||
$this->c = 'Index'; | ||
} | ||
if(isset($pathInfoArr[1])){ | ||
$this->a = $pathInfoArr[1]; | ||
$this->a = ucfirst($pathInfoArr[1]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同样,方法名不区分大小写 |
||
}else{ | ||
$this->a = 'Index'; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处为何要return true?获取不存在的设置应该返回null更合理些吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
理一下,此处返回的是新增配置成功的返回值~~