public function insertByArray($paths, $params, $e)
{
//生成树形的路由表,便于快速查找,
// 如 规则
// "/b/a?z=1&y=2" => service1
// "/b/a?z=1&x=2" => service2
// 对应的 规则结构是
// path -> a+
// |-b+
// param -> |-x+
// |-z => service2
// |-y+
// |-z => service1
//
//
//
$paths = array_filter($paths, function ($i) {
return !empty($i);
});
array_unshift($paths, '/');
if (empty($paths)) {
$paths = array('');
}
if ($params !== null) {
//排序,使参数与顺序无关
sort($params, SORT_STRING);
$params = array_filter($params, function ($i) {
return !empty($i);
});
$node = $this->routes->findNode($paths, true, true);
if ($node && $node['value'] instanceof \phprs\util\Tree) {
$route = $node['value'];
return $route->insert($params, $e, false);
} else {
$route = new Tree();
$route->insert($params, $e, false);
return $this->routes->insert($paths, $route, false);
}
} else {
return $this->routes->insert($paths, $e, false);
}
}