Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | |||
3 | /** |
||
4 | * Smarty Internal Plugin Smarty Template Compiler Base |
||
5 | * |
||
6 | * This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser |
||
7 | * |
||
8 | * @package Smarty |
||
9 | * @subpackage Compiler |
||
10 | * @author Uwe Tews |
||
11 | */ |
||
12 | /** |
||
13 | * Class SmartyTemplateCompiler |
||
14 | */ |
||
15 | class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase { |
||
16 | /** |
||
17 | * Initialize compiler |
||
18 | */ |
||
19 | public function __construct($lexer_class, $parser_class, $smarty) |
||
20 | { |
||
21 | $this->smarty = $smarty; |
||
22 | parent::__construct(); |
||
23 | // get required plugins |
||
24 | $this->smarty->loadPlugin($lexer_class); |
||
25 | $this->smarty->loadPlugin($parser_class); |
||
26 | $this->lexer_class = $lexer_class; |
||
27 | $this->parser_class = $parser_class; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Methode to compile a Smarty template |
||
32 | * |
||
33 | * @param $_content template source |
||
34 | * @return bool true if compiling succeeded, false if it failed |
||
35 | */ |
||
36 | protected function doCompile($_content) |
||
37 | { |
||
38 | /* here is where the compiling takes place. Smarty |
||
39 | tags in the templates are replaces with PHP code, |
||
40 | then written to compiled files. */ |
||
41 | // init the lexer/parser to compile the template |
||
42 | $lex = new $this->lexer_class($_content,$this->smarty); |
||
43 | $parser = new $this->parser_class($lex, $this); |
||
44 | // $parser->PrintTrace(); |
||
45 | // get tokens from lexer and parse them |
||
46 | while ($lex->yylex() && !$this->abort_and_recompile) { |
||
47 | // echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n"; |
||
48 | $parser->doParse($lex->token, $lex->value); |
||
49 | } |
||
50 | |||
51 | if ($this->abort_and_recompile) { |
||
52 | // exit here on abort |
||
53 | return false; |
||
54 | } |
||
55 | // finish parsing process |
||
56 | $parser->doParse(0, 0); |
||
57 | // check for unclosed tags |
||
58 | if (count($this->_tag_stack) > 0) { |
||
59 | // get stacked info |
||
60 | list($_open_tag, $_data) = array_pop($this->_tag_stack); |
||
61 | $this->trigger_template_error("unclosed {" . $_open_tag . "} tag"); |
||
62 | } |
||
63 | |||
64 | if (!$this->compile_error) { |
||
65 | // return compiled code |
||
66 | return $parser->retvalue; |
||
67 | } else { |
||
68 | // compilation error |
||
69 | return false; |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | |||
74 | ?> |