Properties

$rules

$rules

$miss

$miss

$auto

$auto

$fullName

$fullName

$domain

$domain

$name

$name : string

路由标识

Type

string

$router

$router : \think\route\Route

路由对象

Type

\think\route\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

$doAfter

$doAfter : bool

是否需要后置操作

Type

bool

$lockOption

$lockOption : bool

是否锁定参数

Type

bool

Methods

__construct()

__construct(\think\Route  $router, string  $name = '', mixed  $rule = null, array  $option = [], array  $pattern = []) : mixed

架构函数

Parameters

\think\Route $router

路由对象

string $name

路由域名

mixed $rule

域名路由

array $option

路由参数

array $pattern

变量规则

Returns

mixed —

getDomain()

getDomain() : string

获取路由所在域名

Returns

string —

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 —

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 —

getAutoRule()

getAutoRule() : string

获取分组的自动路由

Returns

string —

addAutoRule()

addAutoRule(string  $route) : void

注册自动路由

Parameters

string $route

路由规则

addMissRule()

addMissRule(string  $route, string  $method = '*', array  $option = []) : \think\route\RuleItem

注册MISS路由

Parameters

string $route

路由地址

string $method

请求类型

array $option

路由参数

Returns

\think\route\RuleItem —

addRule()

addRule(string  $rule, string  $route, string  $method = '*', array  $option = [], array  $pattern = []) : $this

添加分组下的路由规则或者子分组

Parameters

string $rule

路由规则

string $route

路由地址

string $method

请求类型

array $option

路由参数

array $pattern

变量规则

Returns

$this —

addRules()

addRules(array  $rules, string  $method = '*', array  $option = [], array  $pattern = []) : void

批量注册路由规则

Parameters

array $rules

路由规则

string $method

请求类型

array $option

路由参数

array $pattern

变量规则

addRuleItem()

addRuleItem(mixed  $rule, mixed  $method = '*') : mixed

Parameters

mixed $rule
mixed $method

Returns

mixed —

prefix()

prefix(string  $prefix) : $this

设置分组的路由前缀

Parameters

string $prefix

Returns

$this —

only()

only(array  $only) : $this

设置资源允许

Parameters

array $only

Returns

$this —

except()

except(array  $except) : $this

设置资源排除

Parameters

array $except

Returns

$this —

vars()

vars(array  $vars) : $this

设置变量

Parameters

array $vars

变量

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

清空分组下的路由规则

getName()

getName() : string

获取Name

Returns

string —

getRule()

getRule() : string

获取当前路由规则

Returns

string —

getRoute()

getRoute() : mixed

获取当前路由地址

Returns

mixed —

getMethod()

getMethod() : string

获取当前路由的请求类型

Returns

string —

getVars()

getVars() : array

获取当前路由的变量

Returns

array —

getRouter()

getRouter() : \think\route\Route

获取路由对象

Returns

\think\route\Route —

doAfter()

doAfter() : bool

路由是否有后置操作

Returns

bool —

getParent()

getParent() : \think\route\RuleGroup|null

获取路由分组

Returns

\think\route\RuleGroup|null —

getPattern()

getPattern(string  $name = '') : mixed

获取变量规则定义

Parameters

string $name

变量名

Returns

mixed —

getConfig()

getConfig(string  $name = '') : mixed

获取路由参数

Parameters

string $name

变量名

Returns

mixed —

getOption()

getOption(string  $name = '') : mixed

获取路由参数定义

Parameters

string $name

参数名

Returns

mixed —

option()

option(string|array  $name, mixed  $value = '') : $this

注册路由参数

Parameters

string|array $name

参数名

mixed $value

Returns

$this —

pattern()

pattern(string|array  $name, string  $rule = '') : $this

注册变量规则

Parameters

string|array $name

变量名

string $rule

变量规则

Returns

$this —

name()

name(string  $name) : $this

设置标识

Parameters

string $name

标识名

Returns

$this —

method()

method(string  $method) : $this

设置路由请求类型

Parameters

string $method

Returns

$this —

before()

before(array|\Closure  $before) : $this

设置路由前置行为

Parameters

array|\Closure $before

Returns

$this —

after()

after(array|\Closure  $after) : $this

设置路由后置行为

Parameters

array|\Closure $after

Returns

$this —

ext()

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

检查后缀

Parameters

string $ext

Returns

$this —

denyExt()

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

检查禁止后缀

Parameters

string $ext

Returns

$this —

domain()

domain(string  $domain) : $this

检查域名

Parameters

string $domain

Returns

$this —

filter()

filter(string|array  $name, mixed  $value = null) : $this

设置参数过滤检查

Parameters

string|array $name
mixed $value

Returns

$this —

model()

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

绑定模型

Parameters

array|string $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 —

response()

response(mixed  $response) : $this

绑定Response对象

Parameters

mixed $response

Returns

$this —

header()

header(mixed  $header, string  $value = null) : $this

设置Response Header信息

Parameters

mixed $header
string $value

参数值

Returns

$this —

middleware()

middleware(string|array|\Closure  $middleware, mixed  $param = null) : $this

指定路由中间件

Parameters

string|array|\Closure $middleware
mixed $param

Returns

$this —

cache()

cache(array|string  $cache) : $this

设置路由缓存

Parameters

array|string $cache

Returns

$this —

depr()

depr(bool  $depr) : $this

检查URL分隔符

Parameters

bool $depr

Returns

$this —

mergeExtraVars()

mergeExtraVars(bool  $merge = true) : $this

是否合并额外参数

Parameters

bool $merge

Returns

$this —

mergeOptions()

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

设置需要合并的路由参数

Parameters

array $option

Returns

$this —

https()

https(bool  $https = true) : $this

检查是否为HTTPS请求

Parameters

bool $https

Returns

$this —

ajax()

ajax(bool  $ajax = true) : $this

检查是否为AJAX请求

Parameters

bool $ajax

Returns

$this —

pjax()

pjax(bool  $pjax = true) : $this

检查是否为PJAX请求

Parameters

bool $pjax

Returns

$this —

mobile()

mobile(bool  $mobile = true) : $this

检查是否为手机访问

Parameters

bool $mobile

Returns

$this —

view()

view(bool|array  $view = true) : $this

当前路由到一个模板地址 当使用数组的时候可以传入模板变量

Parameters

bool|array $view

Returns

$this —

redirect()

redirect(bool  $redirect = true) : $this

当前路由为重定向

Parameters

bool $redirect

是否为重定向

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 —

allowCrossDomain()

allowCrossDomain(bool  $allow = true, array  $header = []) : $this

设置是否允许跨域

Parameters

bool $allow
array $header

Returns

$this —

crossDomainRule()

crossDomainRule() : $this

设置路由规则全局有效

Returns

$this —

mergeGroupOptions()

mergeGroupOptions() : array

合并分组参数

Returns

array —

parseRule()

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

解析匹配到的规则路由

Parameters

\think\Request $request

请求对象

string $rule

路由规则

string $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 —

bind()

bind(string  $bind) : $this

设置路由绑定

Parameters

string $bind

绑定信息

Returns

$this —

setFullName()

setFullName() : void

设置分组的路由规则

getMethodRules()

getMethodRules(string  $method) : array

获取当前请求的路由规则(包括子分组、资源路由)

Parameters

string $method

Returns

array —

checkUrl()

checkUrl(string  $url) : bool

分组URL匹配检查

Parameters

string $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 —

checkCrossDomain()

checkCrossDomain(\think\Request  $request) : \think\route\Dispatch|void

检查OPTIONS请求

Parameters

\think\Request $request

Returns

\think\route\Dispatch|void —

checkBefore()

checkBefore(mixed  $before) : mixed

检查路由前置行为

Parameters

mixed $before

前置行为

Returns

mixed —

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 —

dispatchModule()

dispatchModule(\think\Request  $request, string  $route) : \think\route\dispatch\Module

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

Parameters

\think\Request $request

Request对象

string $route

路由地址

Returns

\think\route\dispatch\Module —

checkOption()

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

路由检查

Parameters

array $option

路由参数

\think\Request $request

Request对象

Returns

bool —

parseUrlParams()

parseUrlParams(\think\Request  $request, mixed  $url, array  $var = []) : void

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

Parameters

\think\Request $request
mixed $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, string  $pattern, string  $suffix) : string

生成路由变量的正则规则

Parameters

string $name

路由变量

string $pattern

变量规则

string $suffix

路由正则变量后缀

Returns

string —

parseVar()

parseVar(string  $rule) : array

分析路由规则中的变量

Parameters

string $rule

路由规则

Returns

array —

parseBindAppendParam()

parseBindAppendParam(mixed  $bind) : mixed

Parameters

mixed $bind

Returns

mixed —

bindToClass()

bindToClass(\think\Request  $request, string  $url, string  $class) : \think\route\dispatch\Callback

绑定到类

Parameters

\think\Request $request
string $url

URL地址

string $class

类名(带命名空间)

Returns

\think\route\dispatch\Callback —

bindToNamespace()

bindToNamespace(\think\Request  $request, string  $url, string  $namespace) : \think\route\dispatch\Callback

绑定到命名空间

Parameters

\think\Request $request
string $url

URL地址

string $namespace

命名空间

Returns

\think\route\dispatch\Callback —

bindToController()

bindToController(\think\Request  $request, string  $url, string  $controller) : \think\route\dispatch\Controller

绑定到控制器类

Parameters

\think\Request $request
string $url

URL地址

string $controller

控制器名 (支持带模块名 index/user )

Returns

\think\route\dispatch\Controller —

bindToModule()

bindToModule(\think\Request  $request, string  $url, string  $controller) : \think\route\dispatch\Module

绑定到模块/控制器

Parameters

\think\Request $request
string $url

URL地址

string $controller

控制器类名(带命名空间)

Returns

\think\route\dispatch\Module —

checkRouteAlias()

checkRouteAlias(\think\Request  $request, string  $url) : \think\route\Dispatch|false

检测路由别名

Parameters

\think\Request $request
string $url

URL地址

Returns

\think\route\Dispatch|false —

checkUrlBind()

checkUrlBind(\think\Request  $request, string  $url) : \think\route\Dispatch|false

检测URL绑定

Parameters

\think\Request $request
string $url

URL地址

Returns

\think\route\Dispatch|false —