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;
    }
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;
    }
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 ; }
Get the rendering callback for a given URI.

@since 0.1.0

@param string $uri     URI to render.
@param array  $context Context in which to render.

@return callable Rendering callback.
@throws FailedToLoadView If the View URI is not accessible or readable.
@throws FailedToLoadView If the View URI could not be loaded.
Get the rendering callback for a given URI .