function __construct($file, $resolve_path = true) { $this->file = $file; if($resolve_path) { if(!$srcfile = resolveTemplateSourceFileName($file)) throw new FileNotFoundException('template file not found', $file); } else $srcfile = $file; $this->codefile = resolveTemplateCompiledFileName($srcfile); if (!isset($GLOBALS['template_render'][$this->codefile])) { if (Limb :: toolkit()->getINI('common.ini')->getOption('force_compile', 'Templates')) { include_once(LIMB_DIR . '/class/template/compiler/template_compiler.inc.php'); compileTemplateFile($file, $resolve_path); } if(!file_exists($this->codefile)) { include_once(LIMB_DIR . '/class/template/compiler/template_compiler.inc.php'); compileTemplateFile($file, $resolve_path); } $errorlevel = error_reporting(); if(!defined('DONT_LOWER_TEMPLATES_ERROR_REPORTING')) { error_reporting($errorlevel &~E_WARNING); } $parse_error = include_once($this->codefile); if(!defined('SET_TEMPLATES_ERROR_REPORTING')) error_reporting($errorlevel); } $this->render_function = $GLOBALS['template_render'][$this->codefile]; $func = $GLOBALS['template_construct'][$this->codefile]; $func($this); }
/** * Compiles a template file. Uses the file scheme to location the source, * instantiates the code_writer and root_compiler_component (as the root) component then * instantiates the source_file_parser to parse the template. * Creates the initialize and render functions in the compiled template. */ function compileTemplateFile($filename, $resolve_path = true) { global $tag_dictionary; if($resolve_path) { if(!$sourcefile = resolveTemplateSourceFileName($filename)) throw new FileNotFoundException('template file not found', $filename); } else $sourcefile = $filename; $destfile = resolveTemplateCompiledFileName($sourcefile); if (empty($sourcefile)) { throw new FileNotFoundException('compiled template file not found', $filename); } $code = new Codewriter(); $code->setFunctionPrefix(md5($destfile)); $tree = new RootCompilerComponent(); $tree->setSourceFile($sourcefile); $sfp = new SourceFileParser($sourcefile, $tag_dictionary); $sfp->parse($tree); $tree->prepare(); $render_function = $code->beginFunction('($dataspace)'); $tree->generate($code); $code->endFunction(); $construct_function = $code->beginFunction('($dataspace)'); $tree->generateConstructor($code); $code->endFunction(); $code->writePhp('$GLOBALS[\'template_render\'][$this->codefile] = \'' . $render_function . '\';'); $code->writePhp('$GLOBALS[\'template_construct\'][$this->codefile] = \'' . $construct_function . '\';'); writeTemplateFile($destfile, $code->getCode()); }