src/Katar.php
public function render($file, $env = array()) {
        $file = $this->views_path . '/' . $file;

        if(!file_exists($file)) {
            throw new \Exception("Could not compile $file, file not found");
        }

        // Cache compiled HTML
        $cacheHash = md5($file . serialize($env));
        $cache_file = $this->views_cache . "/$cacheHash.cache";
        if( !$this->debug && (file_exists($cache_file) 
            && filemtime($cache_file) > filemtime($file))) {
            return file_get_contents($cache_file);
        }

        // If it's not cached, load compiled file and execute
        $this->currFile = $file;
        $hash = md5($file);
        $this->compile($file);
        $compiled_file = $this->views_cache . '/' . $hash;

        // Set a custom error handler
        set_error_handler(array($this, 'onTemplateError'));

        require_once($compiled_file);
        $output = call_user_func('katar_' . $hash, $env);

        // Restore the handler as we leave Katar
        restore_error_handler();

        file_put_contents($cache_file, $output);

        return $output;
    }
public function render($file, $env = array()) {
        $file = $this->views_path . '/' . $file;

        if(!file_exists($file)) {
            throw new \Exception("Could not compile $file, file not found");
        }

        // Cache compiled HTML
        $cacheHash = md5($file . serialize($env));
        $cache_file = $this->views_cache . "/$cacheHash.cache";
        if( !$this->debug && (file_exists($cache_file) 
            && filemtime($cache_file) > filemtime($file))) {
            return file_get_contents($cache_file);
        }

        // If it's not cached, load compiled file and execute
        $this->currFile = $file;
        $hash = md5($file);
        $this->compile($file);
        $compiled_file = $this->views_cache . '/' . $hash;

        // Set a custom error handler
        set_error_handler(array($this, 'onTemplateError'));

        require_once($compiled_file);
        $output = call_user_func('katar_' . $hash, $env);

        // Restore the handler as we leave Katar
        restore_error_handler();

        file_put_contents($cache_file, $output);

        return $output;
    }
public function render ( $ file , $ env = array ( ) ) { $ file = $ this -> views_path . '/' . $ file ; if ( ! file_exists ( $ file ) ) { throw new \ Exception ( "Could not compile $file, file not found" ) ; } // Cache compiled HTML $ cacheHash = md5 ( $ file . serialize ( $ env ) ) ; $ cache_file = $ this -> views_cache . "/$cacheHash.cache" ; if ( ! $ this -> debug && ( file_exists ( $ cache_file ) && filemtime ( $ cache_file ) > filemtime ( $ file ) ) ) { return file_get_contents ( $ cache_file ) ; } // If it's not cached, load compiled file and execute $ this -> currFile = $ file ; $ hash = md5 ( $ file ) ; $ this -> compile ( $ file ) ; $ compiled_file = $ this -> views_cache . '/' . $ hash ; // Set a custom error handler set_error_handler ( array ( $ this , 'onTemplateError' ) ) ; require_once ( $ compiled_file ) ; $ output = call_user_func ( 'katar_' . $ hash , $ env ) ; // Restore the handler as we leave Katar restore_error_handler ( ) ; file_put_contents ( $ cache_file , $ output ) ; return $ output ; }
Compiles a Katar file to a PHP file, and caches the output as
HTML. Returns the HTML result of executing the Katar template
with the given environment.

@param string $file The path of the file to be compiled
@param array $env The environmental variables to be added to the
included file's context

@return string HTML code resulting in compiling the Katar template
with the given environment
Compiles a Katar file to a PHP file and caches the output as HTML . Returns the HTML result of executing the Katar template with the given environment .