public function getRenderCallback(string $uri, array $context = []): callable
    {
        if (! is_readable($uri)) {
            throw new FailedToLoadView(
                sprintf(
                    _('The View URI "%1$s" is not accessible or readable.'),
                    $uri
                )
            );
        }

        $closure = function () use ($uri, $context) {

            // Save current buffering level so we can backtrack in case of an error.
            // This is needed because the view itself might also add an unknown number of output buffering levels.
            $bufferLevel = ob_get_level();
            ob_start();

            try {
                include $uri;
            } catch (Exception $exception) {
                // Remove whatever levels were added up until now.
                while (ob_get_level() > $bufferLevel) {
                    ob_end_clean();
                }

                throw new FailedToLoadView(
                    sprintf(
                        _('Could not load the View URI "%1$s". Reason: "%2$s".'),
                        $uri,
                        $exception->getMessage()
                    ),
                    $exception->getCode(),
                    $exception
                );
            }

            return ob_get_clean();
        };

        return $closure;
    }