1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17:
18: class Smarty_Internal_Config_File_Compiler
19: {
20: 21: 22: 23: 24:
25: public $lex;
26:
27: 28: 29: 30: 31:
32: public $parser;
33:
34: 35: 36: 37: 38:
39: public $smarty;
40:
41: 42: 43: 44: 45:
46: public $config;
47:
48: 49: 50: 51: 52:
53: public $config_data = array();
54:
55: 56: 57: 58: 59:
60: public function __construct($smarty)
61: {
62: $this->smarty = $smarty;
63: $this->config_data['sections'] = array();
64: $this->config_data['vars'] = array();
65: }
66:
67: 68: 69: 70: 71: 72: 73:
74: public function compileSource(Smarty_Internal_Config $config)
75: {
76: 77: 78:
79: $this->config = $config;
80:
81: $_content = $config->source->content . "\n";
82:
83: if ($_content == '') {
84: return true;
85: }
86:
87: $lex = new Smarty_Internal_Configfilelexer($_content, $this);
88: $parser = new Smarty_Internal_Configfileparser($lex, $this);
89:
90: if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
91: $mbEncoding = mb_internal_encoding();
92: mb_internal_encoding('ASCII');
93: } else {
94: $mbEncoding = null;
95: }
96:
97:
98: if ($this->smarty->_parserdebug) {
99: $parser->PrintTrace();
100: }
101:
102: while ($lex->yylex()) {
103: if ($this->smarty->_parserdebug) {
104: echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n";
105: }
106: $parser->doParse($lex->token, $lex->value);
107: }
108:
109: $parser->doParse(0, 0);
110:
111: if ($mbEncoding) {
112: mb_internal_encoding($mbEncoding);
113: }
114:
115: $config->compiled_config = '<?php $_config_vars = ' . var_export($this->config_data, true) . '; ?>';
116: }
117:
118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
128: public function trigger_config_file_error($args = null)
129: {
130: $this->lex = Smarty_Internal_Configfilelexer::instance();
131: $this->parser = Smarty_Internal_Configfileparser::instance();
132:
133: $line = $this->lex->line;
134: if (isset($args)) {
135:
136: }
137: $match = preg_split("/\n/", $this->lex->data);
138: $error_text = "Syntax error in config file '{$this->config->source->filepath}' on line {$line} '{$match[$line - 1]}' ";
139: if (isset($args)) {
140:
141: $error_text .= $args;
142: } else {
143:
144: foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
145: $exp_token = $this->parser->yyTokenName[$token];
146: if (isset($this->lex->smarty_token_names[$exp_token])) {
147:
148: $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
149: } else {
150:
151: $expect[] = $this->parser->yyTokenName[$token];
152: }
153: }
154:
155: $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
156: }
157: throw new SmartyCompilerException($error_text);
158: }
159: }
160: