Haanga_Compiler::compile_file PHP Method

compile_file() final public method

@param string $file File path
final public compile_file ( string $file, boolean $safe = FALSE, $context = [] ) : Generated
$file string
$safe boolean Whether or not add check if the function is already defined @return Generated PHP code
return Generated
    final function compile_file($file, $safe = FALSE, $context = array())
    {
        if (!is_readable($file)) {
            throw new Haanga_Compiler_Exception("{$file} is not a file");
        }
        $this->_base_dir = dirname($file);
        $this->file = realpath($file);
        $this->line = 0;
        $this->check_function = $safe;
        $this->context = $context;
        $name = $this->set_template_name($file);
        try {
            return $this->compile(file_get_contents($file), $name, $file);
        } catch (Exception $e) {
            $this->Error((string) $e);
        }
    }

Usage Example

Beispiel #1
0
 static final function main_cli()
 {
     $argv = $GLOBALS['argv'];
     $haanga = new Haanga_Compiler();
     $code = $haanga->compile_file($argv[1], TRUE);
     if (!isset($argv[2]) || $argv[2] != '--notags') {
         $code = "<?php\n\n{$code}";
     }
     echo $code;
 }