for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\application\route;
use nebula\application\NameFinder;
use nebula\component\route\RouteMatcher;
use nebula\component\route\RouteCollection;
/**
* 应用
*
*/
class GroupRoutes
{
* 名称查找器
* @var NameFinder
protected $finder;
* 路由集合
* @var RouteCollection[]
protected $routes = [];
* 默认分组
* @var string
protected $default = 'global:';
public function __construct(NameFinder $finder) {
$this->finder = $finder;
}
* 注册路由
* @param string|null $group
* @param RouteMatcher $router
* @return void
public function add(?string $group = null, string $name, RouteMatcher $router)
$group = $group ? $this->finder->getFullName($group) : $this->default;
if (\array_key_exists($group, $this->routes)) {
$this->routes[$group]->add($name, $router);
} else {
$this->routes[$group] = new RouteCollection([$name => $router]);
* 搜索路由
* @param string $name
* @return RouteMatcher|null
public function find(string $name, ?string $default = null):?RouteMatcher
list($group, $name) = $this->finder->info($name, $default ?? $this->default);
return $this->routes[$group]->get($name);
return null;