Properties

$name

$name : string

路由标识

Type

string

$domain

$domain : string

所在域名

Type

string

$router

$router : \think\Route

路由对象

Type

Route

$parent

$parent : \think\route\RuleGroup

路由所属分组

Type

RuleGroup

$rule

$rule : mixed

分组路由规则

Type

mixed

$route

$route : string|\Closure

路由地址

Type

Closure

$method

$method : string

请求类型

Type

string

$vars

$vars : array

路由变量

Type

array

$option

$option : array

路由参数

Type

array

$pattern

$pattern : array

路由变量规则

Type

array

$mergeOptions

$mergeOptions : array

需要和分组合并的路由参数

Type

array

$rules

$rules : array

分组路由(包括子分组)

Type

array

$miss

$miss : \think\route\RuleItem

MISS路由

Type

RuleItem

$fullName

$fullName : string

完整名称

Type

string

$alias

$alias : string

分组别名

Type

string

Methods

check()

check(\think\Request  $request, string  $url, bool  $completeMatch = false) : \think\route\Dispatch|false

检测分组路由

Parameters

\think\Request $request

请求对象

string $url

访问地址

bool $completeMatch

路由是否完全匹配

Returns

\think\route\Dispatch|false —

option()

option(array  $option) : $this

设置路由参数

Parameters

array $option

参数

Returns

$this —

setOption()

setOption(string  $name, mixed  $value) : $this

设置单个路由参数

Parameters

string $name

参数名

mixed $value

Returns

$this —

pattern()

pattern(array  $pattern) : $this

注册变量规则

Parameters

array $pattern

变量规则

Returns

$this —

name()

name(string  $name) : $this

设置标识

Parameters

string $name

标识名

Returns

$this —

getRouter()

getRouter() : \think\Route

获取路由对象

Returns

\think\Route —

getName()

getName() : string

获取Name

Returns

string —

getRule()

getRule() : mixed

获取当前路由规则

Returns

mixed —

getRoute()

getRoute() : mixed

获取当前路由地址

Returns

mixed —

getVars()

getVars() : array

获取当前路由的变量

Returns

array —

getParent()

getParent() : $this|null

获取Parent对象

Returns

$this|null —

getDomain()

getDomain() : string

获取所属域名

Returns

string —

config()

config(string  $name = '') : mixed

获取路由参数

Parameters

string $name

变量名

Returns

mixed —

getPattern()

getPattern(string  $name = '') : mixed

获取变量规则定义

Parameters

string $name

变量名

Returns

mixed —

getOption()

getOption(string  $name = '', mixed  $default = null) : mixed

获取路由参数定义

Parameters

string $name

参数名

mixed $default

默认值

Returns

mixed —

getMethod()

getMethod() : string

获取当前路由的请求类型

Returns

string —

method()

method(string  $method) : $this

设置路由请求类型

Parameters

string $method

请求类型

Returns

$this —

ext()

ext(string  $ext = '') : $this

检查后缀

Parameters

string $ext

URL后缀

Returns

$this —

denyExt()

denyExt(string  $ext = '') : $this

检查禁止后缀

Parameters

string $ext

URL后缀

Returns

$this —

domain()

domain(string  $domain) : $this

检查域名

Parameters

string $domain

域名

Returns

$this —

filter()

filter(array  $filter) : $this

设置参数过滤检查

Parameters

array $filter

参数过滤

Returns

$this —

model()

model(array|string|\Closure  $var, string|\Closure  $model = null, bool  $exception = true) : $this

绑定模型

Parameters

array|string|\Closure $var

路由变量名 多个使用 & 分割

string|\Closure $model

绑定模型类

bool $exception

是否抛出异常

Returns

$this —

append()

append(array  $append = []) : $this

附加路由隐式参数

Parameters

array $append

追加参数

Returns

$this —

validate()

validate(mixed  $validate, string  $scene = null, array  $message = [], bool  $batch = false) : $this

绑定验证

Parameters

mixed $validate

验证器类

string $scene

验证场景

array $message

验证提示

bool $batch

批量验证

Returns

$this —

middleware()

middleware(string|array|\Closure  $middleware, mixed  ...$params) : $this

指定路由中间件

Parameters

string|array|\Closure $middleware

中间件

mixed $params variadic

参数

Returns

$this —

allowCrossDomain()

allowCrossDomain(array  $header = []) : $this

允许跨域

Parameters

array $header

自定义Header

Returns

$this —

token()

token(string  $token = '__token__') : $this

表单令牌验证

Parameters

string $token

表单令牌token名称

Returns

$this —

cache()

cache(array|string  $cache) : $this

设置路由缓存

Parameters

array|string $cache

缓存

Returns

$this —

depr()

depr(string  $depr) : $this

检查URL分隔符

Parameters

string $depr

URL分隔符

Returns

$this —

mergeOptions()

mergeOptions(array  $option = []) : $this

设置需要合并的路由参数

Parameters

array $option

路由参数

Returns

$this —

https()

https(bool  $https = true) : $this

检查是否为HTTPS请求

Parameters

bool $https

是否为HTTPS

Returns

$this —

json()

json(bool  $json = true) : $this

检查是否为JSON请求

Parameters

bool $json

是否为JSON

Returns

$this —

ajax()

ajax(bool  $ajax = true) : $this

检查是否为AJAX请求

Parameters

bool $ajax

是否为AJAX

Returns

$this —

pjax()

pjax(bool  $pjax = true) : $this

检查是否为PJAX请求

Parameters

bool $pjax

是否为PJAX

Returns

$this —

view()

view(array  $view = []) : $this

路由到一个模板地址 需要额外传入的模板变量

Parameters

array $view

视图

Returns

$this —

completeMatch()

completeMatch(bool  $match = true) : $this

设置路由完整匹配

Parameters

bool $match

是否完整匹配

Returns

$this —

removeSlash()

removeSlash(bool  $remove = true) : $this

是否去除URL最后的斜线

Parameters

bool $remove

是否去除最后斜线

Returns

$this —

crossDomainRule()

crossDomainRule() : $this

设置路由规则全局有效

Returns

$this —

mergeGroupOptions()

mergeGroupOptions() : array

合并分组参数

Returns

array —

parseRule()

parseRule(\think\Request  $request, string  $rule, mixed  $route, string  $url, array  $option = [], array  $matches = []) : \think\route\Dispatch

解析匹配到的规则路由

Parameters

\think\Request $request

请求对象

string $rule

路由规则

mixed $route

路由地址

string $url

URL地址

array $option

路由参数

array $matches

匹配的变量

Returns

\think\route\Dispatch —

parseUrlPath()

parseUrlPath(string  $url) : array

解析URL的pathinfo参数

Parameters

string $url

URL地址

Returns

array —

__call()

__call(string  $method, array  $args) : $this

设置路由参数

Parameters

string $method

方法名

array $args

调用参数

Returns

$this —

__sleep()

__sleep() : mixed

Returns

mixed —

__wakeup()

__wakeup() : mixed

Returns

mixed —

__debugInfo()

__debugInfo() : mixed

Returns

mixed —

__construct()

__construct(\think\Route  $router, \think\route\RuleGroup  $parent = null, string  $name = '', mixed  $rule = null) : mixed

架构函数

Parameters

\think\Route $router

路由对象

\think\route\RuleGroup $parent

上级对象

string $name

分组名称

mixed $rule

分组路由

Returns

mixed —

getAlias()

getAlias() : string

获取分组别名

Returns

string —

alias()

alias(string  $alias) : $this

设置路由分组别名

Parameters

string $alias

路由分组别名

Returns

$this —

lazy()

lazy(bool  $lazy = true) : $this

延迟解析分组的路由规则

Parameters

bool $lazy

路由是否延迟解析

Returns

$this —

parseGroupRule()

parseGroupRule(mixed  $rule) : void

解析分组和域名的路由规则及绑定

Parameters

mixed $rule

路由规则

getMissRule()

getMissRule() : \think\route\RuleItem|null

获取分组的MISS路由

Returns

\think\route\RuleItem|null —

miss()

miss(string|\Closure  $route, string  $method = '*') : \think\route\RuleItem

注册MISS路由

Parameters

string|\Closure $route

路由地址

string $method

请求类型

Returns

\think\route\RuleItem —

addRule()

addRule(string  $rule, mixed  $route = null, string  $method = '*') : \think\route\RuleItem

添加分组下的路由规则

Parameters

string $rule

路由规则

mixed $route

路由地址

string $method

请求类型

Returns

\think\route\RuleItem —

addRuleItem()

addRuleItem(\think\route\Rule  $rule, string  $method = '*') : $this

注册分组下的路由规则

Parameters

\think\route\Rule $rule

路由规则

string $method

请求类型

Returns

$this —

prefix()

prefix(string  $prefix) : $this

设置分组的路由前缀

Parameters

string $prefix

路由前缀

Returns

$this —

mergeRuleRegex()

mergeRuleRegex(bool  $merge = true) : $this

合并分组的路由规则正则

Parameters

bool $merge

是否合并

Returns

$this —

getFullName()

getFullName() : string

获取完整分组Name

Returns

string —

getRules()

getRules(string  $method = '') : array

获取分组的路由规则

Parameters

string $method

请求类型

Returns

array —

clear()

clear() : void

清空分组下的路由规则

dispatch()

dispatch(\think\Request  $request, mixed  $route, array  $option) : \think\route\Dispatch

发起路由调度

Parameters

\think\Request $request

Request对象

mixed $route

路由地址

array $option

路由参数

Returns

\think\route\Dispatch —

dispatchMethod()

dispatchMethod(\think\Request  $request, string  $route) : \think\route\dispatch\Callback

解析URL地址为 模块/控制器/操作

Parameters

\think\Request $request

Request对象

string $route

路由地址

Returns

\think\route\dispatch\Callback —

dispatchController()

dispatchController(\think\Request  $request, string  $route) : \think\route\dispatch\Controller

解析URL地址为 模块/控制器/操作

Parameters

\think\Request $request

Request对象

string $route

路由地址

Returns

\think\route\dispatch\Controller —

checkOption()

checkOption(array  $option, \think\Request  $request) : bool

路由检查

Parameters

array $option

路由参数

\think\Request $request

Request对象

Returns

bool —

parseUrlParams()

parseUrlParams(string  $url, array  $var = []) : void

解析URL地址中的参数Request对象

Parameters

string $url
array $var

变量

buildRuleRegex()

buildRuleRegex(string  $rule, array  $match, array  $pattern = [], array  $option = [], bool  $completeMatch = false, string  $suffix = '') : string

生成路由的正则规则

Parameters

string $rule

路由规则

array $match

匹配的变量

array $pattern

路由变量规则

array $option

路由参数

bool $completeMatch

路由是否完全匹配

string $suffix

路由正则变量后缀

Returns

string —

buildNameRegex()

buildNameRegex(string  $name, array  $pattern, string  $suffix) : string

生成路由变量的正则规则

Parameters

string $name

路由变量

array $pattern

变量规则

string $suffix

路由正则变量后缀

Returns

string —

setFullName()

setFullName() : void

设置分组的路由规则

checkUrl()

checkUrl(string  $url) : bool

分组URL匹配检查

Parameters

string $url

URL

Returns

bool —

checkMergeRuleRegex()

checkMergeRuleRegex(\think\Request  $request, array  $rules, string  $url, bool  $completeMatch) : \think\route\Dispatch|false

检测分组路由

Parameters

\think\Request $request

请求对象

array $rules

路由规则

string $url

访问地址

bool $completeMatch

路由是否完全匹配

Returns

\think\route\Dispatch|false —