libs/sysplugins/smarty_internal_config_file_compiler.php Quellcode

smarty_internal_config_file_compiler.php
gehe zur Dokumentation dieser Datei
1 <?php
19 {
25  public $lexer_class;
26 
32  public $parser_class;
38  public $lex;
39 
45  public $parser;
46 
52  public $smarty;
53 
59  public $template;
60 
66  public $config_data = array();
67 
73  public $write_compiled_code = true;
74 
83  {
84  $this->smarty = $smarty;
85  // get required plugins
86  $this->lexer_class = $lexer_class;
87  $this->parser_class = $parser_class;
88  $this->smarty = $smarty;
89  $this->config_data['sections'] = array();
90  $this->config_data['vars'] = array();
91  }
92 
101  {
102  $this->template = $template;
103  $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->name, $this->template->source->timestamp, $this->template->source->type);
104  // on empty config just return
105  if ($template->source->content == '') {
106  return true;
107  }
108  if ($this->smarty->debugging) {
109  Smarty_Internal_Debug::start_compile($this->template);
110  }
111  // init the lexer/parser to compile the config file
112  $lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->content) . "\n", $this);
113  $parser = new $this->parser_class($lex, $this);
114 
115  if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
116  $mbEncoding = mb_internal_encoding();
117  mb_internal_encoding('ASCII');
118  } else {
119  $mbEncoding = null;
120  }
121 
122  if ($this->smarty->_parserdebug) {
123  $parser->PrintTrace();
124  }
125  // get tokens from lexer and parse them
126  while ($lex->yylex()) {
127  if ($this->smarty->_parserdebug) {
128  echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n";
129  }
130  $parser->doParse($lex->token, $lex->value);
131  }
132  // finish parsing process
133  $parser->doParse(0, 0);
134 
135  if ($mbEncoding) {
136  mb_internal_encoding($mbEncoding);
137  }
138  if ($this->smarty->debugging) {
139  Smarty_Internal_Debug::end_compile($this->template);
140  }
141  // template header code
142  $template_header = "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
143  $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
144 
145  $code = '<?php Smarty_Internal_Extension_Config::loadConfigVars($_smarty_tpl, ' . var_export($this->config_data, true) . '); ?>';
146  return $template_header . Smarty_Internal_Extension_CodeFrame::create($this->template, $code);
147  }
148 
159  public function trigger_config_file_error($args = null)
160  {
163  // get config source line which has error
164  $line = $this->lex->line;
165  if (isset($args)) {
166  // $line--;
167  }
168  $match = preg_split("/\n/", $this->lex->data);
169  $error_text = "Syntax error in config file '{$this->template->source->filepath}' on line {$line} '{$match[$line - 1]}' ";
170  if (isset($args)) {
171  // individual error message
172  $error_text .= $args;
173  } else {
174  // expected token from parser
175  foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
176  $exp_token = $this->parser->yyTokenName[$token];
177  if (isset($this->lex->smarty_token_names[$exp_token])) {
178  // token type from lexer
179  $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
180  } else {
181  // otherwise internal token name
182  $expect[] = $this->parser->yyTokenName[$token];
183  }
184  }
185  // output parser error message
186  $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
187  }
188  throw new SmartyCompilerException($error_text);
189  }
190 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.