public function preParse() { global $tag_dictionary; $file = $this->attributes['file']; if (!isset($this->attributes['file']) || !$this->attributes['file']) { throw new WactException('missing required attribute', array('tag' => $this->tag, 'attribute' => 'file', 'file' => $this->source_file, 'line' => $this->starting_line_no)); } if (!$this->resolved_source_file = resolveTemplateSourceFileName($file)) { throw new WactException('missing file', array('tag' => $this->tag, 'srcfile' => $file, 'file' => $this->source_file, 'line' => $this->starting_line_no)); } $sfp = new SourceFileParser($this->resolved_source_file, $tag_dictionary); $sfp->parse($this); return PARSER_FORBID_PARSING; }
public function preParse() { global $tag_dictionary; if (! array_key_exists('file', $this->attributes) || empty($this->attributes['file'])) { throw new WactException('missing required attribute', array('tag' => $this->tag, 'attribute' => 'file', 'file' => $this->source_file, 'line' => $this->starting_line_no)); } $file = $this->attributes['file']; if (!$this->resolved_source_file = resolveTemplateSourceFileName($file)) { throw new WactException('missing file', array('tag' => $this->tag, 'srcfile' => $file, 'file' => $this->source_file, 'line' => $this->starting_line_no)); } if (array_key_exists('literal', $this->attributes)) { $literal_component = new TextNode(readTemplateFile($this->resolved_source_file)); $this->addChild($literal_component); } else { $sfp = new SourceFileParser($this->resolved_source_file, $tag_dictionary); $sfp->parse($this); } return PARSER_FORBID_PARSING; }
/** * 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()); }