Comments (13)
考虑路由规则增加正则表达式支持,你觉得如何?
from phpboot.
目前大部分的框架都支持正则路由, 我认为是必须支持的。
from phpboot.
同意,正在加此功能
from phpboot.
考虑再三,决定先不加正则路由,理由如下:
- phprs的定位是开发RESTful接口的框架,对于restful的url,并不提倡定义复杂的路由规则,当前基于层次结构的路由定义已经能够满足
- 对于“严格匹配”的需求,可以对原有路由规则实现进行扩展,代价更小。
- 对于“正则规则”的路由,自动生成文档将是个问题,将无法把正则转换成可读性好的接口示例。
- 性能问题,由于php原生的正则函数不支持批量规则匹配,将导致路由匹配时,需逐条匹配规则。
- 对于特殊情况,当前路由规则无法满足的,可以在webserver端配置正则路由并rewrite解决。
- 为保持框架简单,非必要的特性,还是不引入为妙。
from phpboot.
是的,问题不在于使用何种方式实现,而在于接口必须能在url错误的情况下返回404.
from phpboot.
@route()增加一个参数,用于表示是否严格匹配路径
@route({"GET", "/", true}) 表示严格匹配,GET /abc将和此路由不匹配
@route({"GET", "/"}) 默认形式,非严格匹配,GET /abc将和此路由匹配
from phpboot.
我认为严格匹配模式应该是默认开启的。
API的语义应该是明确的,我不晓得什么场景下会用到不严格匹配的模式?
from phpboot.
默认不严格匹配, 主要是为了向下兼容,另外也是参照nginx location配置规则,如果没有历史包袱,可以考虑默认严格。
典型场景有:
- hook, 通常会应用于一类接口
- 资源名不确定的情况,比如文件下载的接口,因为文件不固定,所以可以使用@route(GET,/files/) 定义,对应请求可以是/files/123 或者/files/mydir/123等。
from phpboot.
至少已经能支持严格匹配了,
更进一步的话,能否在配置中使用一个全局开关呢,避免每个路由都要显示配置?
from phpboot.
同意, 已增加配置
"phprs\\Router"=>[
"properties"=>[
"default_strict_matching"=>true, //默认是否严格匹配
]
],
from phpboot.
hook路由,不应该使用严格匹配。
from phpboot.
我觉得hook路由是不是使用严格匹配,还是由业务决定的,举两个例子
- 使用严格匹配的情况
如果需要只hook创建订单的接口POST /orders/, 此时应该使用严格匹配@route(POST, /orders/, true),否则会hook其他接口,如POST /orders/* - 使用严格匹配的情况
如果为了增加权限控制,需要hook所有订单相关接口,此时则应该使用非严格匹配
from phpboot.
我理解的hook,就是为了同时匹配多个接口的。
hook如果只是满足特定的接口,为何不直接与该接口实现放在一起?
可能某些场景下,需要分开实现,目前还没有遇到,暂时保留意见。
from phpboot.
Related Issues (20)
- 如何定义文件传输的接口呢? HOT 4
- Exceptions throwed by hook, can't be catched. HOT 1
- create \PDO with IoCFactory failed
- cannot extract the “0” node from url path
- how to create the database table for example/users? HOT 1
- 如何自定义配置段 HOT 1
- 求助,"error":"phprs\\util\\exceptions\\NotFound","message HOT 1
- How about add 401 unAuth error response HOT 2
- 想做一个签名校验 HOT 2
- undue sql wrap with ``
- 有版本功能吗? HOT 2
- 想问一下如何添加根据路径的hook HOT 1
- 找不到类的报错 HOT 2
- Class App\Controllers\Books does not exist HOT 1
- 请问RPC调用如何设置超时时间?
- 支持mongodb数据库吗 HOT 2
- 关于APC扩展
- How to access custom values defined in config.php
- conf.json 可能泄漏 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpboot.