Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
TIGERB committed May 22, 2017
2 parents f78f870 + 4ed7253 commit 3ecf827
Show file tree
Hide file tree
Showing 16 changed files with 354 additions and 69 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp
slave = 0,1

[database-slave-0]
dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp

[database-slave-1]
dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp

[nosql]
support = redis
Expand Down
44 changes: 41 additions & 3 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<p align="center">
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/build-passing-brightgreen.svg" alt="Build Status"></a>
<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>
<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>
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework-148KB-orange.svg" alt="Framework Size"></a>
<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>
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework-152KB-orange.svg" alt="Framework Size"></a>
<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>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/cocoapods/l/AFNetworking.svg" alt="License"></a>
</p>
Expand Down Expand Up @@ -115,7 +115,7 @@ vendor [composer目录]
├── pre-commit [git pre-commit预commit钩子示例文件]
├── commit-msg [git commit-msg示例文件]
.babelrc [babel配置文件]
.env [环境变量文件]
.env.example [环境变量示例文件]
.gitignore [git忽略文件配置]
build [php打包脚本]
cli [框架cli模式运行脚本]
Expand Down Expand Up @@ -171,6 +171,31 @@ require('../framework/run.php');

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

例如,数据库主从配置.env文件参数示例:

```
[database]
dbtype = mysqldb
dbprefix = easy
dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp
slave = 0,1
[database-slave-0]
dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp
[database-slave-1]
dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp
```

[[file: framework/hanles/ConfigHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/ConfigHandle.php)]

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

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

##### 请求参数校验,目前提供必传,长度,数字类型校验,使用如下
```
$request = App::$container->getSingle('request');
$request->check('username', 'require');
$request->check('password', 'length', 12);
$request->check('code', 'number');
```

[[file: framework/Request.php](https://github.com/TIGERB/easy-php/blob/master/framework/Request.php)]

[[file: framework/Response.php](https://github.com/TIGERB/easy-php/blob/master/framework/Response.php)]
Expand Down Expand Up @@ -669,3 +702,8 @@ cp ./.git-hooks/* ./git/hooks
- 懒加载优化框架加载流程
- 变更Helper助手类的成员方法为框架函数,简化使用提高生产效率
- 性能测试和优化

- v0.6.9(2017/05/21)
- 提供更友善的开发api帮助
+ 请求参数校验:require/length/number
- 支持mysql主从配置
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<p align="center">
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/build-passing-brightgreen.svg" alt="Build Status"></a>
<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>
<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>
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework-148KB-orange.svg" alt="Framework Size"></a>
<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>
<a href="https://github.com/TIGERB/easy-php/releases"><img src="https://img.shields.io/badge/framework-152KB-orange.svg" alt="Framework Size"></a>
<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>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/cocoapods/l/AFNetworking.svg" alt="License"></a>
</p>

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

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

Expand All @@ -31,7 +31,7 @@ Entry file ----> Register autoload function
----> View
```

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

# Project Directory Structure

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

Loading framework-defined and user-defined config files.

For example,the master-salve database config:

```
[database]
dbtype = mysqldb
dbprefix = easy
dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp
slave = 0,1
[database-slave-0]
dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp
[database-slave-1]
dbname = easyphp
dbhost = localhost
username = easyphp
password = easyphp
```

[[file: framework/hanles/ConfigHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/ConfigHandle.php)]

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

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

##### Request param check, Support require/length/number check at present. Use as follows:
```
$request = App::$container->getSingle('request');
$request->check('username', 'require');
$request->check('password', 'length', 12);
$request->check('code', 'number');
```

[[file: framework/Request.php](https://github.com/TIGERB/easy-php/blob/master/framework/Request.php)]

[[file: framework/Response.php](https://github.com/TIGERB/easy-php/blob/master/framework/Response.php)]
Expand Down Expand Up @@ -663,3 +696,7 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/
- The performance test and optimize
- Use the lazy load thought to optimize the framework
- Change Helper's method to the framework's function
- v0.6.9(2017/05/22)
- more friendly for api develop process
+ request param check:require/length/number
- support master-salve config for db
17 changes: 13 additions & 4 deletions app/demo/controllers/DbOperationDemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ public function dbFindDemo()
->orderBy('id asc')
->findOne();
$sql = $instance->sql;
$database = $instance->masterSlave;

// return $sql;
return $res;
return [
'db' => $database,
'sql' => $sql,
'res' => $res
];
}

/**
Expand All @@ -69,6 +73,7 @@ public function dbFindAllDemo()
->limit(5)
->findAll(['id','create_at']);
$sql = $instance->sql;
$database = $instance->masterSlave;

// return $sql;
return $res;
Expand Down Expand Up @@ -104,8 +109,12 @@ public function dbSaveDemo()
}

return [
'user_id' => $userId,
'test_id' => $testId
'db' => $user->masterSlave,
'sql' => $user->sql,
'res' => [
'user_id' => $userId,
'test_id' => $testId
]
];
}

Expand Down
8 changes: 6 additions & 2 deletions app/demo/controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace App\Demo\Controllers;

use Framework\App;
use Framework\Loger;
use Framework\Logger;

/**
* Index Controller
Expand Down Expand Up @@ -42,12 +42,16 @@ public function hello()
*
* @param string $username 用户名
* @param string $password 密码
* @example domain/Demo/Index/get?username=test&password=123456
* @param number code 验证码
* @example domain/Demo/Index/test?username=tigerb&password=123456789987&code=123456
* @return json
*/
public function test()
{
$request = App::$container->getSingle('request');
$request->check('username', 'require');
$request->check('password', 'length', 12);
$request->check('code', 'number');
return [
'username' => $request->get('username', 'default value')
];
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tigerb/easy-php",
"description": "A lightweight PHP framework for studying",
"version": "0.6.8",
"description": "A Faster Lightweight Full-Stack PHP Framework",
"version": "0.6.9",
"type": "framework, easy-php, php framework",
"homepage": "http://php.tiegrb.cn/",
"license": "MIT",
Expand All @@ -24,7 +24,8 @@
"composer dump-autoload --optimize"
],
"post-root-project-cmd": [
"composer install"
"composer install",
"cp ./.git-hooks/* ./git/hooks"
],
"pre-status-cmd": [
"cp .env.example .env",
Expand Down
19 changes: 17 additions & 2 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@
********************************************/

return [
/* 默认配置 */
/* 主库配置 */
'database' => [
'dbtype' => env('database')['dbtype'],
'dbprefix' => env('database')['dbprefix'],
'dbname' => env('database')['dbname'],
'dbhost' => env('database')['dbhost'],
'username' => env('database')['username'],
'password' => env('database')['password']
'password' => env('database')['password'],
'slave' => explode(',', env('database')['slave'])
],
/* 从库0配置 */
'database-slave-0' => [
'dbname' => env('database-slave-0')['dbname'],
'dbhost' => env('database-slave-0')['dbhost'],
'username' => env('database-slave-0')['username'],
'password' => env('database-slave-0')['password'],
],
/* 从库1配置 */
'database-slave-1' => [
'dbname' => env('database-slave-1')['dbname'],
'dbhost' => env('database-slave-1')['dbhost'],
'username' => env('database-slave-1')['username'],
'password' => env('database-slave-1')['password'],
]
];
19 changes: 14 additions & 5 deletions framework/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ public function setSingle($alias = '', $object = '')
if (array_key_exists($alias, $this->instanceMap)) {
return $this->instanceMap[$alias];
}
$this->instanceMap[$alias] = $object();
return $this->instanceMap[$alias];
$this->instanceMap[$alias] = $object;
}
if (is_object($alias)) {
$className = get_class($alias);
Expand Down Expand Up @@ -144,14 +143,24 @@ public function setSingle($alias = '', $object = '')
*
* get a sington instance
*
* @param string $alias 类名或别名
* @param string $alias 类名或别名
* @param Closure $closure 闭包
* @return object
*/
public function getSingle($alias = '')
public function getSingle($alias = '', $closure = '')
{
if (array_key_exists($alias, $this->instanceMap)) {
return $this->instanceMap[$alias];
$instance = $this->instanceMap[$alias];
if (is_callable($instance)) {
return $instance();
}
return $instance;
}

if (is_callable($closure)) {
return $this->instanceMap[$alias] = $closure();
}

throw new CoreHttpException(
404,
'Class:' . $alias
Expand Down
Loading

0 comments on commit 3ecf827

Please sign in to comment.