public static function withBasePath(ServerRequestInterface $request, $basePath, $pathInfo = null)
    {
        $path = $request->getUri()->getPath();
        if (strpos($path, $basePath) !== 0) {
            throw new \InvalidArgumentException;
        }
        $pathInfo = is_null($pathInfo) ? substr($path, strlen($basePath)) : $pathInfo;

        return $request
            ->withAttribute(self::BASE_PATH, $basePath)
            ->withAttribute(self::PATH_INFO, $pathInfo);
    }