PEEL Shopping
Open source ecommerce : PEEL Shopping
smarty_internal_config_file_compiler.php
Go to the documentation of this file.
1 <?php
20 
26  public $lex;
27 
33  public $parser;
34 
40  public $smarty;
41 
47  public $config;
48 
54  public $config_data = array();
55 
61  public function __construct($smarty)
62  {
63  $this->smarty = $smarty;
64  $this->config_data['sections'] = array();
65  $this->config_data['vars'] = array();
66  }
67 
75  {
76  /* here is where the compiling takes place. Smarty
77  tags in the templates are replaces with PHP code,
78  then written to compiled files. */
79  $this->config = $config;
80  // get config file source
81  $_content = $config->source->content . "\n";
82  // on empty template just return
83  if ($_content == '') {
84  return true;
85  }
86  // init the lexer/parser to compile the config file
87  $lex = new Smarty_Internal_Configfilelexer($_content, $this->smarty);
89  if ($this->smarty->_parserdebug) $parser->PrintTrace();
90  // get tokens from lexer and parse them
91  while ($lex->yylex()) {
92  if ($this->smarty->_parserdebug) echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n";
93  $parser->doParse($lex->token, $lex->value);
94  }
95  // finish parsing process
96  $parser->doParse(0, 0);
97  $config->compiled_config = '<?php $_config_vars = ' . var_export($this->config_data, true) . '; ?>';
98  }
99 
110  public function trigger_config_file_error($args = null)
111  {
114  // get template source line which has error
115  $line = $this->lex->line;
116  if (isset($args)) {
117  // $line--;
118  }
119  $match = preg_split("/\n/", $this->lex->data);
120  $error_text = "Syntax error in config file '{$this->config->source->filepath}' on line {$line} '{$match[$line-1]}' ";
121  if (isset($args)) {
122  // individual error message
123  $error_text .= $args;
124  } else {
125  // exspected token from parser
126  foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
127  $exp_token = $this->parser->yyTokenName[$token];
128  if (isset($this->lex->smarty_token_names[$exp_token])) {
129  // token type from lexer
130  $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
131  } else {
132  // otherwise internal token name
133  $expect[] = $this->parser->yyTokenName[$token];
134  }
135  }
136  // output parser error message
137  $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
138  }
139  throw new SmartyCompilerException($error_text);
140  }
141 
142 }
143 
144 ?>
trigger_config_file_error($args=null)
display compiler error messages without dying
compileSource(Smarty_Internal_Config $config)
Method to compile a Smarty template.
Smarty Internal Plugin Configfilelexer.
$match
Definition: search.php:86

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:17 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.