Marvin3
Marvin3

Reputation: 6041

Call static function with parameter as a callback

I'm trying to pass static function as a callback with parameter, as I'm using old version of PHP, I can't use anonymous function, as it's done in original code https://github.com/bobthecow/mustache.php/wiki , in section "Using all these options".

class SampleClass {

    function __construct( ) {

    }

    static function generateHTML($markup, $data) {
        require_once( 'lib/Mustache/Autoloader.php' );

        Mustache_Autoloader::register();

        $mengine = new Mustache_Engine(array(
            'escape' => /* Here I need to pass escapeMustache function */
        ));

        $renderer = new TempRenderer($data, false);
        echo $mengine->render($markup, $renderer);
    }
    static function escapeMustache($value) {
        return $value;
    }

}

What's the best way to pass custom escape function?

Thank you.

Upvotes: 0

Views: 598

Answers (1)

Marvin3
Marvin3

Reputation: 6041

Thanks to @MichaelBerkowski

Mustache_Engine(array('escape' => array('SampleClass','escapeMustache'))

Upvotes: 2

Related Questions