Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ecf827

Browse files
committedMay 22, 2017
Merge branch 'develop'
2 parents f78f870 + 4ed7253 commit 3ecf827

16 files changed

+354
-69
lines changed
 

‎.env.example

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ dbname = easyphp
88
dbhost = localhost
99
username = easyphp
1010
password = easyphp
11+
slave = 0,1
12+
13+
[database-slave-0]
14+
dbname = easyphp
15+
dbhost = localhost
16+
username = easyphp
17+
password = easyphp
18+
19+
[database-slave-1]
20+
dbname = easyphp
21+
dbhost = localhost
22+
username = easyphp
23+
password = easyphp
1124

1225
[nosql]
1326
support = redis

‎README-CN.md

+41-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<p align="center">
44
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/build-passing-brightgreen.svg" alt="Build Status"></a>
55
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/php-5.4%2B-blue.svg" alt="PHP Version"></a>
6-
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/version-0.6.7-green.svg" alt="Version"></a>
7-
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework-148KB-orange.svg" alt="Framework Size"></a>
6+
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/version-0.6.9-green.svg" alt="Version"></a>
7+
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework-152KB-orange.svg" alt="Framework Size"></a>
88
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework--phar-76KB-red.svg" alt="Framework Phar Size"></a>
99
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/cocoapods/l/AFNetworking.svg" alt="License"></a>
1010
</p>
@@ -115,7 +115,7 @@ vendor [composer目录]
115115
├── pre-commit [git pre-commit预commit钩子示例文件]
116116
├── commit-msg [git commit-msg示例文件]
117117
.babelrc [babel配置文件]
118-
.env [环境变量文件]
118+
.env.example [环境变量示例文件]
119119
.gitignore [git忽略文件配置]
120120
build [php打包脚本]
121121
cli [框架cli模式运行脚本]
@@ -171,6 +171,31 @@ require('../framework/run.php');
171171

172172
加载框架自定义和用户自定义的配置文件。
173173

174+
例如,数据库主从配置.env文件参数示例:
175+
176+
```
177+
[database]
178+
dbtype = mysqldb
179+
dbprefix = easy
180+
dbname = easyphp
181+
dbhost = localhost
182+
username = easyphp
183+
password = easyphp
184+
slave = 0,1
185+
186+
[database-slave-0]
187+
dbname = easyphp
188+
dbhost = localhost
189+
username = easyphp
190+
password = easyphp
191+
192+
[database-slave-1]
193+
dbname = easyphp
194+
dbhost = localhost
195+
username = easyphp
196+
password = easyphp
197+
```
198+
174199
[[file: framework/hanles/ConfigHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/ConfigHandle.php)]
175200

176201
## 输入和输出
@@ -180,6 +205,14 @@ require('../framework/run.php');
180205

181206
框架中所有的异常输出和控制器输出都是json格式,因为我认为在前后端完全分离的今天,这是很友善的,目前我们不需要再去考虑别的东西。
182207

208+
##### 请求参数校验,目前提供必传,长度,数字类型校验,使用如下
209+
```
210+
$request = App::$container->getSingle('request');
211+
$request->check('username', 'require');
212+
$request->check('password', 'length', 12);
213+
$request->check('code', 'number');
214+
```
215+
183216
[[file: framework/Request.php](https://github.com/TIGERB/easy-php/blob/master/framework/Request.php)]
184217

185218
[[file: framework/Response.php](https://github.com/TIGERB/easy-php/blob/master/framework/Response.php)]
@@ -669,3 +702,8 @@ cp ./.git-hooks/* ./git/hooks
669702
- 懒加载优化框架加载流程
670703
- 变更Helper助手类的成员方法为框架函数,简化使用提高生产效率
671704
- 性能测试和优化
705+
706+
- v0.6.9(2017/05/21)
707+
- 提供更友善的开发api帮助
708+
+ 请求参数校验:require/length/number
709+
- 支持mysql主从配置

‎README.md

+42-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<p align="center">
44
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/build-passing-brightgreen.svg" alt="Build Status"></a>
55
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/php-5.4%2B-blue.svg" alt="PHP Version"></a>
6-
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/version-0.6.7-green.svg" alt="Version"></a>
7-
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework-148KB-orange.svg" alt="Framework Size"></a>
6+
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/version-0.6.9-green.svg" alt="Version"></a>
7+
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework-152KB-orange.svg" alt="Framework Size"></a>
88
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework--phar-76KB-red.svg" alt="Framework Phar Size"></a>
99
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/cocoapods/l/AFNetworking.svg" alt="License"></a>
1010
</p>
1111

12-
<p align="center"> A lightweight PHP framework for studying <p>
12+
<p align="center"> A Faster Lightweight Full-Stack PHP Framework <p>
1313

1414
<p align="center"> <a href="./README-CN.md">中文版</a> <p>
1515

@@ -31,7 +31,7 @@ Entry file ----> Register autoload function
3131
----> View
3232
```
3333

34-
In addition, unit test, nosql support, api documents and some auxiliary scripts, etc. Finnally, My framework directory as follows:
34+
In addition, unit test, nosql support, api documents and some auxiliary scripts, e.g. Finnally, My framework directory as follows:
3535

3636
# Project Directory Structure
3737

@@ -114,7 +114,7 @@ vendor [composer vendor directory]
114114
├── pre-commit [git pre-commit example file]
115115
├── commit-msg [git commit-msg example file]
116116
.babelrc [babel config file]
117-
.env [the environment variables file]
117+
.env.example [the environment variables example file]
118118
.gitignore [git ignore config file]
119119
build [build php code to phar file script]
120120
cli [run this framework with the php cli mode]
@@ -168,6 +168,31 @@ Register a function by used set_exception_handler to handle the exception which
168168

169169
Loading framework-defined and user-defined config files.
170170

171+
For example,the master-salve database config:
172+
173+
```
174+
[database]
175+
dbtype = mysqldb
176+
dbprefix = easy
177+
dbname = easyphp
178+
dbhost = localhost
179+
username = easyphp
180+
password = easyphp
181+
slave = 0,1
182+
183+
[database-slave-0]
184+
dbname = easyphp
185+
dbhost = localhost
186+
username = easyphp
187+
password = easyphp
188+
189+
[database-slave-1]
190+
dbname = easyphp
191+
dbhost = localhost
192+
username = easyphp
193+
password = easyphp
194+
```
195+
171196
[[file: framework/hanles/ConfigHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/ConfigHandle.php)]
172197

173198
## Request&Response Module
@@ -177,6 +202,14 @@ Loading framework-defined and user-defined config files.
177202

178203
All output is json in the framework, neithor framework's core error or business logic's output, beacuse I think is friendly.
179204

205+
##### Request param check, Support require/length/number check at present. Use as follows:
206+
```
207+
$request = App::$container->getSingle('request');
208+
$request->check('username', 'require');
209+
$request->check('password', 'length', 12);
210+
$request->check('code', 'number');
211+
```
212+
180213
[[file: framework/Request.php](https://github.com/TIGERB/easy-php/blob/master/framework/Request.php)]
181214

182215
[[file: framework/Response.php](https://github.com/TIGERB/easy-php/blob/master/framework/Response.php)]
@@ -663,3 +696,7 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/
663696
- The performance test and optimize
664697
- Use the lazy load thought to optimize the framework
665698
- Change Helper's method to the framework's function
699+
- v0.6.9(2017/05/22)
700+
- more friendly for api develop process
701+
+ request param check:require/length/number
702+
- support master-salve config for db

‎app/demo/controllers/DbOperationDemo.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ public function dbFindDemo()
4646
->orderBy('id asc')
4747
->findOne();
4848
$sql = $instance->sql;
49+
$database = $instance->masterSlave;
4950

50-
// return $sql;
51-
return $res;
51+
return [
52+
'db' => $database,
53+
'sql' => $sql,
54+
'res' => $res
55+
];
5256
}
5357

5458
/**
@@ -69,6 +73,7 @@ public function dbFindAllDemo()
6973
->limit(5)
7074
->findAll(['id','create_at']);
7175
$sql = $instance->sql;
76+
$database = $instance->masterSlave;
7277

7378
// return $sql;
7479
return $res;
@@ -104,8 +109,12 @@ public function dbSaveDemo()
104109
}
105110

106111
return [
107-
'user_id' => $userId,
108-
'test_id' => $testId
112+
'db' => $user->masterSlave,
113+
'sql' => $user->sql,
114+
'res' => [
115+
'user_id' => $userId,
116+
'test_id' => $testId
117+
]
109118
];
110119
}
111120

‎app/demo/controllers/Index.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace App\Demo\Controllers;
1111

1212
use Framework\App;
13-
use Framework\Loger;
13+
use Framework\Logger;
1414

1515
/**
1616
* Index Controller
@@ -42,12 +42,16 @@ public function hello()
4242
*
4343
* @param string $username 用户名
4444
* @param string $password 密码
45-
* @example domain/Demo/Index/get?username=test&password=123456
45+
* @param number code 验证码
46+
* @example domain/Demo/Index/test?username=tigerb&password=123456789987&code=123456
4647
* @return json
4748
*/
4849
public function test()
4950
{
5051
$request = App::$container->getSingle('request');
52+
$request->check('username', 'require');
53+
$request->check('password', 'length', 12);
54+
$request->check('code', 'number');
5155
return [
5256
'username' => $request->get('username', 'default value')
5357
];

‎composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tigerb/easy-php",
3-
"description": "A lightweight PHP framework for studying",
4-
"version": "0.6.8",
3+
"description": "A Faster Lightweight Full-Stack PHP Framework",
4+
"version": "0.6.9",
55
"type": "framework, easy-php, php framework",
66
"homepage": "http://php.tiegrb.cn/",
77
"license": "MIT",
@@ -24,7 +24,8 @@
2424
"composer dump-autoload --optimize"
2525
],
2626
"post-root-project-cmd": [
27-
"composer install"
27+
"composer install",
28+
"cp ./.git-hooks/* ./git/hooks"
2829
],
2930
"pre-status-cmd": [
3031
"cp .env.example .env",

‎config/database.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@
1010
********************************************/
1111

1212
return [
13-
/* 默认配置 */
13+
/* 主库配置 */
1414
'database' => [
1515
'dbtype' => env('database')['dbtype'],
1616
'dbprefix' => env('database')['dbprefix'],
1717
'dbname' => env('database')['dbname'],
1818
'dbhost' => env('database')['dbhost'],
1919
'username' => env('database')['username'],
20-
'password' => env('database')['password']
20+
'password' => env('database')['password'],
21+
'slave' => explode(',', env('database')['slave'])
22+
],
23+
/* 从库0配置 */
24+
'database-slave-0' => [
25+
'dbname' => env('database-slave-0')['dbname'],
26+
'dbhost' => env('database-slave-0')['dbhost'],
27+
'username' => env('database-slave-0')['username'],
28+
'password' => env('database-slave-0')['password'],
29+
],
30+
/* 从库1配置 */
31+
'database-slave-1' => [
32+
'dbname' => env('database-slave-1')['dbname'],
33+
'dbhost' => env('database-slave-1')['dbhost'],
34+
'username' => env('database-slave-1')['username'],
35+
'password' => env('database-slave-1')['password'],
2136
]
2237
];

‎framework/Container.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ public function setSingle($alias = '', $object = '')
108108
if (array_key_exists($alias, $this->instanceMap)) {
109109
return $this->instanceMap[$alias];
110110
}
111-
$this->instanceMap[$alias] = $object();
112-
return $this->instanceMap[$alias];
111+
$this->instanceMap[$alias] = $object;
113112
}
114113
if (is_object($alias)) {
115114
$className = get_class($alias);
@@ -144,14 +143,24 @@ public function setSingle($alias = '', $object = '')
144143
*
145144
* get a sington instance
146145
*
147-
* @param string $alias 类名或别名
146+
* @param string $alias 类名或别名
147+
* @param Closure $closure 闭包
148148
* @return object
149149
*/
150-
public function getSingle($alias = '')
150+
public function getSingle($alias = '', $closure = '')
151151
{
152152
if (array_key_exists($alias, $this->instanceMap)) {
153-
return $this->instanceMap[$alias];
153+
$instance = $this->instanceMap[$alias];
154+
if (is_callable($instance)) {
155+
return $instance();
156+
}
157+
return $instance;
158+
}
159+
160+
if (is_callable($closure)) {
161+
return $this->instanceMap[$alias] = $closure();
154162
}
163+
155164
throw new CoreHttpException(
156165
404,
157166
'Class:' . $alias

‎framework/Request.php

+63-15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Framework;
1313

14+
use Framework\Exceptions\CoreHttpException;
15+
1416
/**
1517
* 请求
1618
*
@@ -154,21 +156,6 @@ public function __construct(App $app)
154156
$this->loadEnv($app);
155157
}
156158

157-
/**
158-
* 加载环境参数
159-
*
160-
* @param App $app 框架实例
161-
* @return void
162-
*/
163-
public function loadEnv(App $app)
164-
{
165-
$env = parse_ini_file($app->rootPath . '/.env', true);
166-
if ($env === false) {
167-
throw CoreHttpException('load env fail', 500);
168-
}
169-
$this->envParams = array_merge($_ENV, $env);
170-
}
171-
172159
/**
173160
* 魔法函数__get.
174161
*
@@ -292,4 +279,65 @@ public function env($value = '')
292279
}
293280
return '';
294281
}
282+
283+
/**
284+
* 加载环境参数
285+
*
286+
* @param App $app 框架实例
287+
* @return void
288+
*/
289+
public function loadEnv(App $app)
290+
{
291+
$env = parse_ini_file($app->rootPath . '/.env', true);
292+
if ($env === false) {
293+
throw CoreHttpException('load env fail', 500);
294+
}
295+
$this->envParams = array_merge($_ENV, $env);
296+
}
297+
298+
/**
299+
* 参数验证
300+
*
301+
* 支持必传参数验证,参数长度验证,参数类型验证
302+
*
303+
* @param string $paramName 参数名
304+
* @param string $rule 规则
305+
* @return mixed
306+
*/
307+
public function check($paramName = '', $rule = '', $length = 0)
308+
{
309+
if (! is_int($length)) {
310+
throw new CoreHttpException(
311+
400,
312+
"length type is not int"
313+
);
314+
}
315+
316+
if ($rule === 'require') {
317+
if (! empty($this->request($paramName))) {
318+
return;
319+
}
320+
throw new CoreHttpException(404, "param {$paramName}");
321+
}
322+
323+
if ($rule === 'length') {
324+
if (strlen($this->request($paramName)) === $length) {
325+
return;
326+
}
327+
throw new CoreHttpException(
328+
400,
329+
"param {$paramName} length is not {$length}"
330+
);
331+
}
332+
333+
if ($rule === 'number') {
334+
if (is_numeric($this->request($paramName))) {
335+
return;
336+
}
337+
throw new CoreHttpException(
338+
400,
339+
"{$paramName} type is not number"
340+
);
341+
}
342+
}
295343
}

‎framework/handles/ExceptionHandle.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ public function register(App $app)
4949
*/
5050
public function exceptionHandler($exception)
5151
{
52-
throw $exception;
53-
}
52+
$exceptionInfo = [
53+
'code' => $exception->getCode(),
54+
'message' => $exception->getMessage(),
55+
'file' => $exception->getFile(),
56+
'line' => $exception->getLine(),
57+
'trace' => $exception->getTrace(),
58+
'previous' => $exception->getPrevious()
59+
];
5460

61+
CoreHttpException::reponseErr($exceptionInfo);
62+
}
5563
}

‎framework/orm/DB.php

+110-9
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,38 @@ class DB
7373
*/
7474
protected $id = '';
7575

76+
/**
77+
* 走主库的查寻语句
78+
*
79+
* @var array
80+
*/
81+
private $master = ['insert', 'update', 'delete'];
82+
83+
/**
84+
* 当前查询主从
85+
*
86+
* @var string
87+
*/
88+
private $masterSlave = '';
89+
90+
/**
91+
* 数据库配置
92+
*
93+
* @var array
94+
*/
95+
private $dbConfig = [
96+
'dbhost' => '',
97+
'dbname' => '',
98+
'username' => '',
99+
'password' => ''
100+
];
101+
76102
/**
77103
* 构造函数
78104
*/
79105
public function __construct()
80106
{
81-
$this->init();
107+
// $this->init();
82108
}
83109

84110
/**
@@ -96,20 +122,25 @@ public static function table($tableName = '')
96122
if (! empty($prefix)) {
97123
$db->tableName = $prefix . '_' . $db->tableName;
98124
}
99-
$db->init();
125+
// $db->init();
100126

101127
return $db;
102128
}
103129

104130
/**
105131
* 初始化策略
106132
*
133+
* @param $masterOrSlave 初始化主库还是从库
107134
* @return void
108135
*/
109-
public function init()
136+
public function init($masterOrSlave = '')
110137
{
111138
$config = APP::$container->getSingle('config');
112139
$this->dbtype = $config->config['database']['dbtype'];
140+
if (! empty($masterOrSlave)) {
141+
$this->masterSlave = $masterOrSlave;
142+
}
143+
$this->isMasterOrSlave();
113144
$this->decide();
114145
}
115146

@@ -121,14 +152,77 @@ public function init()
121152
public function decide()
122153
{
123154
$dbStrategyName = $this->dbStrategyMap[$this->dbtype];
124-
$this->dbInstance = APP::$container->setSingle(
125-
$this->dbtype,
126-
function () use ($dbStrategyName) {
127-
return new $dbStrategyName();
155+
$dbConfig = $this->dbConfig;
156+
$this->dbInstance = APP::$container->getSingle(
157+
"{$this->dbtype}-{$this->masterSlave}",
158+
function () use ($dbStrategyName, $dbConfig) {
159+
return new $dbStrategyName(
160+
$dbConfig['dbhost'],
161+
$dbConfig['dbname'],
162+
$dbConfig['username'],
163+
$dbConfig['password']
164+
);
128165
}
129166
);
130167
}
131168

169+
/**
170+
* 判断走主库还是从库
171+
*
172+
* @return void
173+
*/
174+
public function isMasterOrSlave()
175+
{
176+
if (! empty($this->masterSlave)) {
177+
$this->initMaster();
178+
return;
179+
}
180+
foreach ($this->master as $v) {
181+
$res = stripos($this->sql, $v);
182+
if ($res === 0 || $res) {
183+
$this->initMaster();
184+
return;
185+
}
186+
}
187+
$this->initSlave();
188+
}
189+
190+
/**
191+
* 初始化主库
192+
*/
193+
public function initMaster()
194+
{
195+
$config = APP::$container->getSingle('config');
196+
$dbConfig = $config->config['database'];
197+
$this->dbConfig['dbhost'] = $dbConfig['dbhost'];
198+
$this->dbConfig['dbname'] = $dbConfig['dbname'];
199+
$this->dbConfig['username'] = $dbConfig['username'];
200+
$this->dbConfig['password'] = $dbConfig['password'];
201+
202+
$this->masterSlave = 'master';
203+
}
204+
205+
/**
206+
* 初始化从库
207+
*/
208+
public function initSlave()
209+
{
210+
$config = APP::$container->getSingle('config');
211+
if (! isset($config->config['database']['slave'])) {
212+
$this->initMaster();
213+
return;
214+
}
215+
$slave = $config->config['database']['slave'];
216+
$randSlave = $slave[array_rand($slave)];
217+
$dbConfig = $config->config["database-slave-{$randSlave}"];
218+
$this->dbConfig['dbhost'] = $dbConfig['dbhost'];
219+
$this->dbConfig['dbname'] = $dbConfig['dbname'];
220+
$this->dbConfig['username'] = $dbConfig['username'];
221+
$this->dbConfig['password'] = $dbConfig['password'];
222+
223+
$this->masterSlave = "slave-{$randSlave}";
224+
}
225+
132226
/**
133227
* 查找一条数据
134228
*
@@ -165,6 +259,7 @@ public function findAll($data = [])
165259
public function save($data = [])
166260
{
167261
$this->insert($data);
262+
$this->init();
168263
$functionName = __FUNCTION__;
169264
return $this->dbInstance->$functionName($this);
170265
}
@@ -231,6 +326,7 @@ public function sum($data = '')
231326
public function query($sql = '')
232327
{
233328
$this->querySql($sql);
329+
$this->init();
234330
return $this->dbInstance->query($this);
235331
}
236332

@@ -250,6 +346,8 @@ public function buildSql()
250346
if (! empty($this->limit)) {
251347
$this->sql .= $this->limit;
252348
}
349+
350+
$this->init();
253351
}
254352

255353
/**
@@ -259,10 +357,11 @@ public function buildSql()
259357
*/
260358
public static function beginTransaction()
261359
{
262-
$instance = APP::$container->setSingle('DB', function () {
360+
$instance = APP::$container->getSingle('DB', function () {
263361
return new DB();
264362
}
265363
);
364+
$instance->init('master');
266365
$instance->dbInstance->beginTransaction();
267366
}
268367

@@ -273,10 +372,11 @@ public static function beginTransaction()
273372
*/
274373
public static function commit()
275374
{
276-
$instance = APP::$container->setSingle('DB', function () {
375+
$instance = APP::$container->getSingle('DB', function () {
277376
return new DB();
278377
}
279378
);
379+
$instance->init('master');
280380
$instance->dbInstance->commit();
281381
}
282382

@@ -291,6 +391,7 @@ public static function rollBack()
291391
return new DB();
292392
}
293393
);
394+
$instance->init('master');
294395
$instance->dbInstance->rollBack();
295396
}
296397

‎framework/orm/db/Mysql.php

+15-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Framework\Orm\Db;
1313

14-
use Framework\App;
1514
use Framework\Orm\DB;
1615
use Framework\Exceptions\CoreHttpException;
1716
use PDO;
@@ -75,18 +74,24 @@ class Mysql
7574
private $pdoStatement = '';
7675

7776
/**
78-
* construct function
77+
* init mysql driver by pdo
78+
*
79+
* @param string $dbhost host
80+
* @param string $dbname database name
81+
* @param string $username database username
82+
* @param string $password password
7983
*/
80-
public function __construct()
84+
public function __construct(
85+
$dbhost = '',
86+
$dbname = '',
87+
$username = '',
88+
$password = '')
8189
{
82-
$config = APP::$container->getSingle('config');
83-
$config = $config->config;
84-
$dbConfig = $config['database'];
85-
$this->dbhost = $dbConfig['dbhost'];
86-
$this->dbname = $dbConfig['dbname'];
90+
$this->dbhost = $dbhost;
91+
$this->dbname = $dbname;
8792
$this->dsn = "mysql:dbname={$this->dbname};host={$this->dbhost};";
88-
$this->username = $dbConfig['username'];
89-
$this->password = $dbConfig['password'];
93+
$this->username = $username;
94+
$this->password = $password;
9095

9196
$this->connect();
9297
}

‎framework/run.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,10 @@
6565
return new ErrorHandle();
6666
});
6767

68-
// $app->load(function () {
69-
// // 加载异常处理机制 由于本文件全局catch了异常 所以不存在未捕获异常
70-
// // 可省略注册未捕获异常Handle
71-
// // Loading exception handle.
72-
// // I'm not used it, because this file catch all exception
73-
// return new ExceptionHandle();
74-
// });
68+
$app->load(function () {
69+
// 加载异常处理机制 Loading exception handle.
70+
return new ExceptionHandle();
71+
});
7572

7673
$app->load(function () {
7774
// 加载nosql机制 Loading nosql handle
@@ -117,7 +114,7 @@
117114
$app->response(function () {
118115
return new Response();
119116
});
120-
} catch (CoreHttpException $e) {
117+
} catch (CoreHttException $e) {
121118
/**
122119
* 捕获异常
123120
*

‎public/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* TIERGB *
88
* <https://github.com/TIGERB> *
99
* *
10-
* Version: 0.6.8 *
10+
* Version: 0.6.9 *
1111
********************************************/
1212

1313
// 载入框架运行文件

‎runtime/.gitignore

100644100755
File mode changed.

‎runtime/.gitkeep

100644100755
File mode changed.

0 commit comments

Comments
 (0)
Please sign in to comment.