Skip to content

Commit 0e3d777

Browse files
author
jasonc
committed
base version
1 parent e7dcb97 commit 0e3d777

18 files changed

+91
-63
lines changed

.gitignore

100644100755
File mode changed.

.settings/com.zend.php.formatter.ui.prefs

100644100755
File mode changed.

.settings/org.eclipse.php.ui.prefs

100644100755
File mode changed.

README

100644100755
File mode changed.

app/application.ini

100644100755
+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
;根路径
22
[/]
3-
controller = list
3+
method = lists
44

5-
;controller action
65
[list/*]
7-
;默认调用
8-
controller = lists
9-
;参数格式
10-
params = int id
6+
method = lists
7+
params = int id ,int page
118

129
[post/*]
13-
controller = post
10+
method = post
1411
params =

app/controllers/list.php

100644100755
File mode changed.

doc/mysql.conf

100644100755
File mode changed.

doc/nginx.conf

100644100755
File mode changed.

ext/script/tools.php

100644100755
File mode changed.

lib/app/controller.php

100644100755
File mode changed.

lib/config.inc.php

100644100755
+21-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
<?php
2-
function_exists('realpath')?'':die('function realpath not exists , cant define ROOT');
3-
realpath(dirname(__FILE__))?'':die('cant find the file realpath');
2+
function_exists('realpath') ? '' : die('function realpath not exists , cant define ROOT');
3+
realpath(dirname(__FILE__)) ? '' : die('cant find the file realpath');
44

5-
//核心库目录路径定义
5+
/* 核心库目录路径定义 */
66
define('DS',DIRECTORY_SEPARATOR);
7-
//框架根目录
7+
/* 框架根目录 */
88
define('ROOT',realpath(dirname(__FILE__) . DS .'..' ));
9-
//核心库路径
9+
/* 核心库路径 */
1010
define('LIB_ROOT',ROOT . DS . 'lib');
11-
//第三方库路径
11+
/* 第三方库路径 */
1212
define('EXT_ROOT',ROOT . DS . 'ext');
13-
//数据路径
13+
/* 数据路径 */
1414
define('DATA_ROOT',ROOT . DS . 'data');
15-
16-
//应用app路径(默认)
15+
/* 应用app路径(默认) */
1716
defined('APP_ROOT') or define('APP_ROOT',ROOT . DS . 'app');
18-
19-
/**
20-
* Constant denoting the error reporting level.
21-
* 0 - Show errors only.
22-
* 1 - Show warnings and errors.
23-
* 2 - Show notices, warnings and errors.
24-
*/
25-
define('DEBUG', 2);
26-
27-
//定义数据库
17+
/* 定义数据库 */
2818
define('DB_HOST','localhost'); //数据库定位
2919
define('DB_USER','root'); //数据库登录名
3020
define('DB_PASS','ubuntu'); //数据库密码
3121
define('DB_NAME','note'); //数据库名称
3222
//define(DB_ENCODE,'UTF8'); //sql数据编码
3323

24+
/* 设置错误级别 */
25+
define('DEBUG', 2);
26+
27+
if (DEBUG == 2) {
28+
error_reporting(E_ALL);
29+
} elseif (DEBUG == 1) {
30+
error_reporting(E_ALL & ~E_NOTICE);
31+
} else {
32+
error_reporting(E_ERROR | E_PARSE | E_USER_ERROR);
33+
}
34+
35+
defined('P4_LOADED') ? exit : define('P4_LOADED',1);
3436
?>

lib/core/controller.php

100644100755
File mode changed.

lib/core/dispatcher.php

100644100755
+59-22
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
define('ROOT_KEY', '/');
33

44
/**
5-
* core dispatcher invoke
5+
* 核心调度调用
66
*/
77
class core_dispatcher {
88
//实例化
99
private static $instance;
1010
//app配置列表,访问规则
1111
private static $applications;
1212
//分发url地址
13-
private static $url;
13+
private static $uri;
1414

1515
public function __construct($inifile = null){
1616
if (is_null($inifile)) {
1717
$inifile = APP_ROOT . DS . 'application.ini';
1818
}
1919

20-
// Get the application configuration.
20+
/* 获取配置文件 */
2121
$this->applications = parse_ini_file($inifile, true);
2222
}
2323

@@ -36,25 +36,76 @@ public function instance (){
3636
*/
3737
public function dispatcher($uri){
3838
$chunks = parse_url($uri);
39-
$this->url = $chunks['path'];
39+
$this->uri = $chunks['path'];
4040

41-
// Step 1. 检查是否默认调用
42-
if ($this->url == ROOT_KEY && array_key_exists(ROOT_KEY, $this->applications)) {
41+
/* 检查是否默认调用 */
42+
if ($this->uri == ROOT_KEY && array_key_exists(ROOT_KEY, $this->applications)) {
4343
$this->invoke(ROOT_KEY, $this->applications[ROOT_KEY]);
4444
exit;
4545
}
4646

47-
// Search for an application to dispatch the request to.
47+
/* 根据配置,转化为正则,验证url传参 */
4848
foreach ($this->applications as $application => $config) {
4949
$regex = "|^/?". str_replace('*', '?.*', $application) . "$|";
50-
if (preg_match($regex, $this->url)) {
50+
/* 正则匹配url */
51+
if (preg_match($regex, $this->uri)) {
5152
$this->invoke($application, $config);
5253
exit;
5354
}
5455
}
56+
/* 如不匹配,返回404 */
5557
$this->error_404();
5658
}
5759

60+
61+
/**
62+
* 调用
63+
*/
64+
private function invoke($application, $config){
65+
/* 检查默认cotroller是否存在 */
66+
if (empty($config['method'])) {
67+
trigger_error("No controller configured for the application "
68+
. $application, E_USER_ERROR);
69+
}
70+
71+
/* 过滤uri,切割 */
72+
$request = split('/',preg_replace('#^/|/$#', '', $this->uri));
73+
$controller = &array_shift($request);
74+
$method = &array_shift($request);
75+
$params = &$request;
76+
77+
if(empty($method)){
78+
$method = $config['method'];
79+
}
80+
81+
$r = $this->_params($config, &$params);
82+
dpx($r);
83+
84+
}
85+
86+
/**
87+
* 参数
88+
*/
89+
function _params($config, &$params) {
90+
if (isset($config['params'])) {
91+
$keys = split(',', $config['params']);
92+
93+
for ($i = 0, $l = count($params); $i < $l; $i++) {
94+
if (!empty($params[$i])) {
95+
list($type, $name) = split(' ', trim($keys[$i]));
96+
$value = urldecode(trim($params[$i]));
97+
dbx($value);
98+
99+
if (!$this->_validate_param(trim($type), $value)) {
100+
$this->error_404();
101+
}
102+
103+
$_GET[trim($name)] = $value;
104+
}
105+
}
106+
}
107+
}
108+
58109
/**
59110
* 验证参数类型
60111
*/
@@ -69,20 +120,6 @@ private function _validate_param($type, $value) {
69120
|| $type == 'array' && is_array($value);
70121
}
71122

72-
/**
73-
* 调用
74-
*/
75-
private function invoke($application, $config){
76-
if (empty($config['controller'])) {
77-
trigger_error("No controller configured for the application "
78-
. $application, E_USER_ERROR);
79-
}
80-
//$this->_params($config, $this->_getValues($application));
81-
82-
83-
dbx($application,$config,$this);
84-
}
85-
86123
/**
87124
* error 404
88125
*/

lib/db/abstract.php

100644100755
File mode changed.

lib/db/mongo.php

100644100755
File mode changed.

lib/ext/smarty.php

100644100755
File mode changed.

lib/index.php

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
<?php
2+
/**
3+
* 框架入口
4+
*/
25
require_once 'config.inc.php';
36

7+
function_exists('spl_autoload_register') ? '' : die('SPL not installed');
8+
49
/* 加载原始autoload */
510
if(function_exists('__autoload')){
611
spl_autoload_register('__autoload');
712
}
13+
814
/* 加载loader */
915
spl_autoload_extensions(".php"); // comma-separated list
1016
spl_autoload_register('classLoader');
1117

12-
// Set level of error reporting
13-
if (DEBUG == 2) {
14-
error_reporting(E_ALL);
15-
} elseif (DEBUG == 1) {
16-
error_reporting(E_ALL & ~E_NOTICE);
17-
} else {
18-
error_reporting(E_ERROR | E_PARSE | E_USER_ERROR);
19-
}
20-
21-
/**
22-
* 路由
23-
*/
2418
function classLoader($class) {
25-
//类名转路径
19+
/* 类名转路径 */
2620
$path = str_replace('_',DS,strtolower($class));
2721
$file = LIB_ROOT . DS . $path . '.php';
2822
if (!file_exists($file)){
2923
die('cant find '.$file);
3024
}
3125
include $file;
3226
}
33-
34-
3527
?>

lib/tmp.php

100644100755
File mode changed.

0 commit comments

Comments
 (0)