PHP Class think\Route

Show file Open project: top-think/framework Class Usage Examples

Public Methods

Method Description
alias ( string | array $rule = null, string $route = '', array $option = [] ) : void 注册别名路由
any ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void 注册路由
auto ( string $route ) : void 注册一个自动解析的URL路由
bind ( mixed $bind, string $type = 'module' ) : mixed 设置路由绑定
bindToClass ( string $url, string $class, string $depr = '/' ) : array 绑定到类
bindToController ( string $url, string $controller, string $depr = '/' ) : array 绑定到控制器类
bindToModule ( string $url, $controller, string $depr = '/' ) : array 绑定到模块/控制器
bindToNamespace ( string $url, string $namespace, string $depr = '/' ) : array 绑定到命名空间
check ( think\Request $request, string $url, string $depr = '/', boolean $checkDomain = false ) : false | array 检测URL路由
checkDomain ( think\Request $request, array &$currentRules, string $method = 'GET' ) : void 检测子域名部署
controller ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void 注册控制器路由 操作方法对应不同的请求后缀
delete ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void 注册DELETE路由
domain ( string | array $domain, mixed $rule = '', array $option = [], array $pattern = [] ) : void 注册子域名部署规则
get ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void 注册GET路由
getBind ( string $type ) : mixed 读取路由绑定
getGroup ( string $type ) : mixed 获取当前的分组信息
group ( string | array $name, array | Closure $routes, array $option = [], array $pattern = [] ) : void 注册路由分组
import ( array $rule, string $type = '*' ) : void 导入配置文件的路由规则
miss ( string $route, string $method = '*', array $option = [] ) : void 注册未匹配路由规则后的处理
name ( string | array $name = '', array $value = null ) : array 设置或者获取路由标识
parseUrl ( string $url, string $depr = '/', boolean $autoSearch = false ) : array 解析模块的URL地址 [模块/控制器/操作?]参数1=值1&参数2=值2.
patch ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void 注册PATCH路由
pattern ( string | array $name = null, string $rule = '' ) : void 注册变量规则
post ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void 注册POST路由
put ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void 注册PUT路由
resource ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void 注册资源路由
rest ( string $name, $resource = [] ) : void rest方法定义和修改
rule ( string $rule, string $route = '', string $type = '*', array $option = [], array $pattern = [] ) : void 注册路由规则
rules ( mixed $rules = '' ) : array 获取或者批量设置路由定义
setGroup ( string $name, array $option = [], array $pattern = [] ) : void 设置当前的路由分组
setMethodPrefix ( string $method, string $prefix = '' ) : void 设置不同请求类型下面的方法前缀

Protected Methods

Method Description
registerRules ( $rules, $type = '*' ) 批量注册路由
setRule ( string $rule, string $route, string $type = '*', array $option = [], array $pattern = [], string $group = '' ) : void 设置路由规则

Private Methods

Method Description
checkOption ( array $option, think\Request $request ) : boolean 路由参数有效性检查
checkRoute ( think\Request $request, array $rules, string $url, string $depr = '/', string $group = '', array $options = [] ) : mixed 检测路由规则
checkRouteAlias ( think\Request $request, string $url, string $depr ) : mixed 检测路由别名
checkRule ( string $rule, string $route, string $url, array $pattern, array $option, string $depr ) : array | false 检测路由规则
checkUrlBind ( string &$url, array &$rules, string $depr = '/' ) : mixed 检测URL绑定
getRouteExpress ( $key )
match ( string $url, string $rule, array $pattern ) : array | false 检测URL和规则路由是否匹配
parseModule ( string $url ) : array 解析URL地址为 模块/控制器/操作
parseRule ( string $rule, string $route, string $pathinfo, array $option = [], array $matches = [] ) : array 解析规则路由
parseUrlParams ( $url, array &$var = [] ) : void 解析URL地址中的参数Request对象
parseUrlPath ( string $url ) : array 解析URL的pathinfo参数和变量
parseVar ( $rule ) 分析路由规则中的变量
setDomain ( $domain )

Method Details

alias() public static method

注册别名路由
public static alias ( string | array $rule = null, string $route = '', array $option = [] ) : void
$rule string | array 路由别名
$route string 路由地址
$option array 路由参数
return void

any() public static method

注册路由
public static any ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$option array 路由参数
$pattern array 变量规则
return void

auto() public static method

注册一个自动解析的URL路由
public static auto ( string $route ) : void
$route string 路由地址
return void

bind() public static method

设置路由绑定
public static bind ( mixed $bind, string $type = 'module' ) : mixed
$bind mixed 绑定信息
$type string 绑定类型 默认为module 支持 namespace class
return mixed

bindToClass() public static method

绑定到类
public static bindToClass ( string $url, string $class, string $depr = '/' ) : array
$url string URL地址
$class string 类名(带命名空间)
$depr string URL分隔符
return array

bindToController() public static method

绑定到控制器类
public static bindToController ( string $url, string $controller, string $depr = '/' ) : array
$url string URL地址
$controller string 控制器名 (支持带模块名 index/user )
$depr string URL分隔符
return array

bindToModule() public static method

绑定到模块/控制器
public static bindToModule ( string $url, $controller, string $depr = '/' ) : array
$url string URL地址
$depr string URL分隔符
return array

bindToNamespace() public static method

绑定到命名空间
public static bindToNamespace ( string $url, string $namespace, string $depr = '/' ) : array
$url string URL地址
$namespace string 命名空间
$depr string URL分隔符
return array

check() public static method

检测URL路由
public static check ( think\Request $request, string $url, string $depr = '/', boolean $checkDomain = false ) : false | array
$request think\Request Request请求对象
$url string URL地址
$depr string URL分隔符
$checkDomain boolean 是否检测域名规则
return false | array

checkDomain() public static method

检测子域名部署
public static checkDomain ( think\Request $request, array &$currentRules, string $method = 'GET' ) : void
$request think\Request Request请求对象
$currentRules array 当前路由规则
$method string 请求类型
return void

controller() public static method

注册控制器路由 操作方法对应不同的请求后缀
public static controller ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$option array 路由参数
$pattern array 变量规则
return void

delete() public static method

注册DELETE路由
public static delete ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$option array 路由参数
$pattern array 变量规则
return void

domain() public static method

注册子域名部署规则
public static domain ( string | array $domain, mixed $rule = '', array $option = [], array $pattern = [] ) : void
$domain string | array 子域名
$rule mixed 路由规则
$option array 路由参数
$pattern array 变量规则
return void

get() public static method

注册GET路由
public static get ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$option array 路由参数
$pattern array 变量规则
return void

getBind() public static method

读取路由绑定
public static getBind ( string $type ) : mixed
$type string 绑定类型
return mixed

getGroup() public static method

获取当前的分组信息
public static getGroup ( string $type ) : mixed
$type string 分组信息名称 name option pattern
return mixed

group() public static method

注册路由分组
public static group ( string | array $name, array | Closure $routes, array $option = [], array $pattern = [] ) : void
$name string | array 分组名称或者参数
$routes array | Closure 路由地址
$option array 路由参数
$pattern array 变量规则
return void

import() public static method

导入配置文件的路由规则
public static import ( array $rule, string $type = '*' ) : void
$rule array 路由规则
$type string 请求类型
return void

miss() public static method

注册未匹配路由规则后的处理
public static miss ( string $route, string $method = '*', array $option = [] ) : void
$route string 路由地址
$method string 请求类型
$option array 路由参数
return void

name() public static method

设置或者获取路由标识
public static name ( string | array $name = '', array $value = null ) : array
$name string | array 路由命名标识 数组表示批量设置
$value array 路由地址及变量信息
return array

parseUrl() public static method

..
public static parseUrl ( string $url, string $depr = '/', boolean $autoSearch = false ) : array
$url string URL地址
$depr string URL分隔符
$autoSearch boolean 是否自动深度搜索控制器
return array

patch() public static method

注册PATCH路由
public static patch ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$option array 路由参数
$pattern array 变量规则
return void

pattern() public static method

注册变量规则
public static pattern ( string | array $name = null, string $rule = '' ) : void
$name string | array 变量名
$rule string 变量规则
return void

post() public static method

注册POST路由
public static post ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$option array 路由参数
$pattern array 变量规则
return void

put() public static method

注册PUT路由
public static put ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$option array 路由参数
$pattern array 变量规则
return void

registerRules() protected static method

批量注册路由
protected static registerRules ( $rules, $type = '*' )

resource() public static method

注册资源路由
public static resource ( string $rule, string $route = '', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$option array 路由参数
$pattern array 变量规则
return void

rest() public static method

rest方法定义和修改
public static rest ( string $name, $resource = [] ) : void
$name string 方法名称
return void

rule() public static method

注册路由规则
public static rule ( string $rule, string $route = '', string $type = '*', array $option = [], array $pattern = [] ) : void
$rule string 路由规则
$route string 路由地址
$type string 请求类型
$option array 路由参数
$pattern array 变量规则
return void

rules() public static method

获取或者批量设置路由定义
public static rules ( mixed $rules = '' ) : array
$rules mixed 请求类型或者路由定义数组
return array

setGroup() public static method

设置当前的路由分组
public static setGroup ( string $name, array $option = [], array $pattern = [] ) : void
$name string 分组名称
$option array 分组路由参数
$pattern array 分组变量规则
return void

setMethodPrefix() public static method

设置不同请求类型下面的方法前缀
public static setMethodPrefix ( string $method, string $prefix = '' ) : void
$method string 请求类型
$prefix string 类型前缀
return void

setRule() protected static method

设置路由规则
protected static setRule ( string $rule, string $route, string $type = '*', array $option = [], array $pattern = [], string $group = '' ) : void
$rule string 路由规则
$route string 路由地址
$type string 请求类型
$option array 路由参数
$pattern array 变量规则
$group string 所属分组
return void