protected function routeMiddleware()
    {
        $router = $this->router;
        $dispatcher = $this->dispatcher;

        if (!$dispatcher->wasForwarded() && $router->wasMatched()) {
            $actionMethod = $dispatcher->getActionName();

            $route = $router->getMatchedRoute();

            $paths = $route->getPaths();

            if (!empty($paths['middleware'])) {
                $middlewares = $paths['middleware'];

                if (!is_array($middlewares)) {
                    $middlewares = [$middlewares];
                }

                foreach ($middlewares as $key => $middleware) {
                    if (is_int($key)) {
                        $middlewareClass  = $middleware;
                        $middlewareParams = [];
                    } else {
                        $middlewareClass  = $key;
                        $middlewareParams = !is_array($middlewares) ? [$middleware] : $middleware;
                    }

                    $this->middleware($middlewareClass, ...$middlewareParams)->only([$actionMethod]);
                }
            }
        }
    }