Skip to content

Commit

Permalink
refactor(framework/router): refactor router 🔨
Browse files Browse the repository at this point in the history
  • Loading branch information
TIGERB committed Aug 29, 2017
1 parent a403347 commit 6aba101
Show file tree
Hide file tree
Showing 19 changed files with 782 additions and 553 deletions.
2 changes: 1 addition & 1 deletion .git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

PHPCS_BIN=./vendor/bin/phpcs
PHPCS_CODING_STANDARD=PSR1,PSR2
PHPCS_IGNORE=./vendor,./.git-hooks,./.env,./.gitignore,./composer.json,./composer.lock,./README.md,/frontend,./docs,./config,./.babelrc,./LICENSE,./yarn.lock,./webpack.config.js,./package.json,.travis.yml,phpunit.xml
PHPCS_IGNORE=./vendor,./.git-hooks,./.env,./.gitignore,./composer.json,./composer.lock,./README.md,/frontend,./docs,./config,./.babelrc,./LICENSE,./yarn.lock,./webpack.config.js,./package.json,.travis.yml,phpunit.xml,README-CN.md,cli,.tmp_staging
TMP_STAGING=".tmp_staging"

# parse config
Expand Down
24 changes: 23 additions & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ framework [Easy PHP核心框架目录]
│ ├── Model.php [数据模型基类]
│ └── db [数据库类目录]
│ └── Mysql.php [mysql实体类]
├── router [路由策略]
│ ├── RouterInterface.php [路由策略接口]
│ ├── General.php [普通路由]
│ ├── Pathinfo.php [pathinfo路由]
│ ├── Userdefined.php [自定义路由]
│ ├── Micromonomer.php [微单体路由]
│ ├── Job.php [脚本任务路由]
│ └── EasyRouter.php [路由策略入口类]
├── nosql [nosql类目录]
│ ├── Memcahed.php [Memcahed类文件]
│ ├── MongoDB.php [MongoDB类文件]
Expand Down Expand Up @@ -225,6 +233,17 @@ $request->check('code', 'number');

## 路由模块

```
├── router [路由策略]
│ ├── RouterInterface.php [路由策略接口]
│ ├── General.php [普通路由]
│ ├── Pathinfo.php [pathinfo路由]
│ ├── Userdefined.php [自定义路由]
│ ├── Micromonomer.php [微单体路由]
│ ├── Job.php [脚本任务路由]
│ └── EasyRouter.php [路由策略入口类]
```

通过用户访问的url信息,通过路由规则执行目标控制器类的的成员方法。我在这里把路由大致分成了四类:

**传统路由**
Expand Down Expand Up @@ -725,7 +744,7 @@ cp ./.git-hooks/* ./git/hooks

# TODO

- 重构路由,简化jobs路由流程
- 集成swoole
- 增加数据库变更辅助
- 集成swagger
- 提供更友善的开发api帮助
Expand All @@ -738,6 +757,9 @@ cp ./.git-hooks/* ./git/hooks

# DONE

- v0.7.1(2017/08/29)
- 重构路由模块

- v0.7.0(2017/06/18)
- 集成travis-ci实现持续集成部署
- 增加脚本目录
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ framework [easy-php framework directory]
│ ├── Model.php [data model]
│ └── db [db type directory]
│ └── Mysql.php [mysql class file]
├── router [router strategy]
│ ├── RouterInterface.php [router strategy interface]
│ ├── General.php [general strategy class]
│ ├── Pathinfo.php [pathinfo strategy class]
│ ├── Userdefined.php [userdefined strategy class]
│ ├── Micromonomer.php [micromonomer strategy class]
│ ├── Job.php [job strategy class]
│ └── EasyRouter.php [router strategy entrance class]
├── nosql [nosql directory]
│ ├── Memcahed.php [memcahed class file]
│ ├── MongoDB.php [mongoDB class file]
Expand Down Expand Up @@ -222,6 +230,17 @@ $request->check('code', 'number');

## Route Handle Module

```
├── router [datebase object relation map class directory]
│ ├── RouterInterface.php [router strategy interface]
│ ├── General.php [general strategy class]
│ ├── Pathinfo.php [pathinfo strategy class]
│ ├── Userdefined.php [userdefined strategy class]
│ ├── Micromonomer.php [micromonomer strategy class]
│ ├── Job.php [job strategy class]
│ └── EasyRouter.php [router strategy entrance class]
```

Execute the target controller's function by the router parse the url information.Is composed of four types of:

**tradition router**
Expand Down Expand Up @@ -719,7 +738,7 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/

# TODO

- Refactor router handle and make the jobs route more simple
- Use swoole
- Add database sql helper
- Integrate swagger
- Provide much friendly help for user
Expand All @@ -733,6 +752,9 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/

# DONE

- v0.7.1(2017/08/29)
- refactor router by the strategy design pattern

- v0.7.0(2017/06/18)
- implement ci by travis-ci
- add jobs script folder
Expand Down
23 changes: 11 additions & 12 deletions cli
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/php
<?php
/********************************************
* Easy PHP *
* *
* A lightweight PHP framework for studying *
* *
* TIERGB *
* <https://github.com/TIGERB> *
* *
********************************************/

/*************************************************
* Easy PHP *
* *
* A Faster Lightweight Full-Stack PHP Framework *
* *
* TIERGB *
* <https://github.com/TIGERB> *
* *
*************************************************/
/**
* cli模式
*
Expand Down Expand Up @@ -41,7 +40,7 @@ $help = function () {
\033[36m Quick start demo \033[0m:
php cli --run

\033[32mEasy PHP: A Faster Lightweight Full-Stack PHP Framework. Version 0.7.0\033[0m
\033[32mEasy PHP: A Faster Lightweight Full-Stack PHP Framework. Version 0.7.1\033[0m

\033[32mAuthor : TIGERB <https://github.com/TIGERB>\033[0m
\n
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tigerb/easy-php",
"description": "A Faster Lightweight Full-Stack PHP Framework",
"version": "0.7.0",
"version": "0.7.1",
"type": "framework",
"homepage": "http://php.tiegrb.cn/",
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
use Framework\Helper;

return [
/* 应用目录名称 */
'application_folder_name' => 'app',

/* 脚本目录名称 */
'jobs_folder_name' => 'jobs',

/* 默认模块 */
'module' => [
'demo'
Expand Down
20 changes: 10 additions & 10 deletions framework/App.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/********************************************
* Easy PHP *
* *
* A lightweight PHP framework for studying *
* *
* TIERGB *
* <https://github.com/TIGERB> *
* *
********************************************/
/*************************************************
* Easy PHP *
* *
* A Faster Lightweight Full-Stack PHP Framework *
* *
* TIERGB *
* <https://github.com/TIGERB> *
* *
*************************************************/

namespace Framework;

Expand Down Expand Up @@ -222,7 +222,7 @@ public function callSelf($method = '', $uri = '', $argus = array())
$router->moduleName = $requestUri[0];
$router->controllerName = $requestUri[1];
$router->actionName = $requestUri[2];
$router->routeStrategy = 'microMonomer';
$router->routeStrategy = 'micromonomer';
$router->route();
return $this->responseData;
}
Expand Down
Loading

0 comments on commit 6aba101

Please sign in to comment.