protected function middleware(FinalCallback $callback, ServerRequestInterface $request)
    {
        $response = $this->container->get(self::RESPONSE);

        if (interface_exists(Application::MIDDLEWARE) === true) {
            $middleware = new Dispatcher($this->middlewares, $response);

            $delegate = new Delegate($callback);

            $result = $middleware->process($request, $delegate);
        }

        return isset($result) ? $result : $callback($request);
    }