Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions SinglePHP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function C($key,$value=null){
halt('传入参数不正确');
}
}
return null;
return true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处为何要return true?获取不存在的设置应该返回null更合理些吧

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

理一下,此处返回的是新增配置成功的返回值~~

}

/**
Expand Down Expand Up @@ -85,6 +85,8 @@ function M(){
function includeIfExist($path){
if(file_exists($path)){
include $path;
} else {
halt('Invalid path:' . $path);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处没必要停止程序运行,并不强制要求包含。对于需要强制包含的文件,可以把错误处理放在外围,错误信息可以更明确。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处如果路径不对,应该给一个warn级别的错误,halt确实欠妥~~

}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP的类名是不区分大小写的

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoload里面有include文件啊,所以首字母应该大写吧~

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,但是我们这里并没有强制规定首字符要大写,假如开发者就是希望使用小写开头的Controller呢?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你下面都默认给大写的Index了,  还说什么小写啊~~~

Copy link

Choose a reason for hiding this comment

The 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]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同样,方法名不区分大小写

}else{
$this->a = 'Index';
}
Expand Down