我有一些代码:
AController
class AController extends Controller
{
public function __construct()
{
echo 'outside - AController';
echo '<br/>';
$this->middleware(function ($request, $next) {
echo 'inside - AController';
echo '<br/>';
return $next($request);
});
}
public function handle()
{
$B = new BController;
if ( $B->check() ) {
$controller = BController::class;
$action = 'index';
} else {
$controller = BController::class;
$action = 'nothing';
}
$container = app();
$route = $container->make(Route::class);
$controllerInstance = $container->make($controller);
return (new ControllerDispatcher($container))->dispatch($route, $controllerInstance, $action);
}
}
BController
class BController extends Controller
{
public function __construct()
{
echo 'outside - BController';
echo '<br/>';
$this->middleware(function ($request, $next) {
echo 'inside - BController';
echo '<br/>';
return $next($request);
});
}
}
当从AController调用BController时,在浏览器中显示:
外面 - AController里面 - AController
外面 - BController为什么BController中的中间件从AController调用时没有显示出来?
外面 - AController里面 - AController
外面 - BControllerinside - BController