我设法将request-handler与aura-router与单个router handler结合使用。
我正在尝试实现特定于路由的中间件,而不是“全局”应用程序中间件。
$routerContainer = new RouterContainer();
$map = $routerContainer->getMap();
// Works fine...
$map->get('index', '/', 'App\Http\Controllers\HomeController::index');
// Error: Invalid request handler: array
$map->get('index', '/', [
new SampleRouteMiddleware(),
'App\Http\Controllers\HomeController::index'
]);
$request = ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$requestContainer = new RequestHandlerContainer();
$dispatcher = new Dispatcher([
new SampleAppMiddleware(), // applies to all routes...
new AuraRouter($routerContainer),
new RequestHandler($requestContainer),
]);
$response = $dispatcher->dispatch($request);