使用路由工厂
在 config.neon
services:
routeFactory.Front: FrontModule\RouteFactory
routeFactory.Admin: AdminModule\RouteFactory
route:
class: \RouteFactory
setup:
- addRouteFactory(@routeFactory.Front)
- addRouteFactory(@routeFactory.Admin)
类RouteFactory:
class RouteFactory
{
/** @var array */
private $routerFactories = array();
public function addRouteFactory(IRouteFactory $routeFactory)
{
$this->routeFactories[] = $routeFactory;
}
public function createRouter()
{
$router = new RouteList();
foreach ($this->routeFactories as $routeFactory) {
$router[] = $routeFactory->createRouter();
}
return $router;
}
}
接口 IRouteFactory:
interface IRouteFactory
{
public function createRouter();
}
模块路由工厂
namespace FrontModule;
class RouteFactory implements \IRouteFactory
{
public function createRouter()
{
$router = new RouteList('Front');
// your routes
return $router;
}
}