PHP Class phprs\util\HttpRouterEntries

Author: caoym 针对 path?arg1=x&argy=y的形式url进行路由 搜索匹配的规则时,如果有多条规则匹配,则返回路径最深的(或者querystring最多的)规则 比如规则 "/api" => service1, "/api?arg1=x" => service2, 查询"/api?arg1=x&arg2=y" 找到service2
Datei anzeigen Open project: caoym/phprs-restful Class Usage Examples

Public Methods

Method Description
__construct ( )
export ( ) : array 树打平输出成数组
find ( string $q, string& &$matched_path = null ) : found
findByArray ( string $paths, string $params, array &$matched_path = null ) : mixed | null 查找url对应的实体
insert ( $query, $e, $strict = false ) 增加一条规则
insertByArray ( array $paths, array $params, mixed $e ) : boolean 增加一条路由规则
pathToString ( array $path ) : string 数组路径转字符串路径
stringToPath ( string $path ) : array 字符串路转径数组路

Private Methods

Method Description
findParams ( Tree $root, $params ) : mixed | null 查找querystring对应的实体 querystring 参数匹配条件在tree中的存储方式如下

Method Details

__construct() public method

public __construct ( )

export() public method

树打平输出成数组
public export ( ) : array
return array

find() public method

public find ( string $q, string& &$matched_path = null ) : found
$q string
$matched_path string&
return found object

findByArray() public method

查找url对应的实体
public findByArray ( string $paths, string $params, array &$matched_path = null ) : mixed | null
$paths string
$params string
$matched_path array 已匹配的路径
return mixed | null

insert() public method

增加一条规则
public insert ( $query, $e, $strict = false )
$query string 请求的url形式
$e mixed
$strict boolean 是否严格匹配

insertByArray() public method

增加一条路由规则
public insertByArray ( array $paths, array $params, mixed $e ) : boolean
$paths array
$params array
$e mixed
return boolean

pathToString() public static method

数组路径转字符串路径
public static pathToString ( array $path ) : string
$path array
return string 用/连接的字符串

stringToPath() public static method

字符串路转径数组路
public static stringToPath ( string $path ) : array
$path string
return array