nepttune / router
可定制的路由工厂
此软件包的规范存储库似乎已不存在,因此软件包已被冻结。
v2.0.2
2019-09-17 12:52 UTC
Requires
- hashids/hashids: ^3.0
- nette/application: ^3.0
README
🔧 可定制的路由工厂
介绍
带有一些基本模块配置的预制路由工厂。
依赖项
如何使用
- 在配置文件中将
\Nepttune\RouterFactory
注册为服务。别忘了注入neon参数。 - 通过调用
@routerFactory::createRouter
方法创建路由。 - 您可以配置工厂以创建子域路由或标准路由
- 子域路由使用以下模式
//<module>.%domain%/[<locale>/]<presenter>/<action>[/<id>]
。 - 标准路由使用以下模式
/[<locale>/]<module>/<presenter>/<action>[/<id>]
。 - 标准路由还可以创建不包含
<module>
部分的路由,在这种情况下使用配置的默认模块。
- 子域路由使用以下模式
- 区域设置参数与
[a-z]{2}
模式进行验证。 - id参数与
\d+
模式进行验证 - 如果hashids
设置为true,则将id哈希为字符串。
示例配置
services:
routerFactory:
class: Nepttune\RouterFactory
arguments:
- %router%
router: @routerFactory::createRouter
parameters:
router:
subdomain: false
apimodule: true
defaultModule: 'Www'
hashids: true
hashidsSalt: 'x7royUaK0g'
modules:
admin: Admin
配置选项
hashids
(布尔值) - 路由器是否应使用Hashids来隐藏真实的id参数hashidsSalt
(字符串) - 传递给hashids的盐,使哈希在多个应用程序中唯一hashidsCharset
(字符串) - 传递给hashids的字符集,可能的字符集合hashidsPadding
(整数) - 传递给hashids的填充,哈希的最小长度subdomain
(布尔值) - 路由器是否应创建子域路由器
以下选项仅适用于标准路由器 - 当subdomain
选项为false时。
defaultModule
(字符串) - 默认模块的名称,当URL中未提供时使用apimodule
(布尔值) - 路由器是否应创建简单的不带参数的API路由 -/api/<presenter>/<action>
modules
(关联数组) - 要创建的路由列表 - 例如,admin: Admin
将创建除通用路由之外的admin路由