protected function wrapMiddleware($path, $middleware)
    {
        return function(
            ServerRequestInterface $request,
            ResponseInterface $response,
            $next
        ) use ($middleware, $path) {
            $uriPath = $request->getUri()->getPath();

            if ($uriPath === $path || strpos($uriPath, rtrim($path, '/') . '/') === 0) {
                $ret = $middleware($request, $response, $next);
            } else {
                $ret = $next($request, $response);
            }
            
            return $ret;
        };
    }