init
[garradin.git] / include / libs / template_lite / internal / compile.compile_config.php
1 <?php
2 /**
3 * Template Lite compile config variables - template internal module
4 *
5 * Type: template
6 * Name: compile_config
7 */
8
9 function compile_compile_config($variable, &$object)
10 {
11 $_result = "";
12
13 // remove the beginning and ending #
14 $variable = substr($variable, 1, -1);
15
16 // get [foo] and .foo and (...) pieces
17 preg_match_all('!(?:^\w+)|(?:' . $object->_var_bracket_regexp . ')|\.\$?\w+|\S+!', $variable, $_match);
18 $variable = $_match[0];
19 $var_name = array_shift($variable);
20
21 $_result = "\$this->_confs['$var_name']";
22 foreach ($variable as $var)
23 {
24 if ($var{0} == '[')
25 {
26 $var = substr($var, 1, -1);
27 if (is_numeric($var))
28 {
29 $_result .= "[$var]";
30 }
31 elseif ($var{0} == '$')
32 {
33 $_result .= "[" . $object->_compile_variable($var) . "]";
34 }
35 elseif ($var{0} == '#')
36 {
37 $_result .= "[" . $object->_compile_config($var) . "]";
38 }
39 else
40 {
41 $_result .= "['$var']";
42 }
43 }
44 else if ($var{0} == '.')
45 {
46 if ($var{1} == '$')
47 {
48 $_result .= "[\$this->_TPL['" . substr($var, 2) . "']]";
49 }
50 else
51 {
52 $_result .= "['" . substr($var, 1) . "']";
53 }
54 }
55 else if (substr($var,0,2) == '->')
56 {
57 if(substr($var,2,2) == '__')
58 {
59 throw new Template_Exception('call to internal object members is not allowed', $object);
60 }
61 else if (substr($var, 2, 1) == '$')
62 {
63 $_output .= '->{(($var=$this->_TPL[\''.substr($var,3).'\']) && substr($var,0,2)!=\'__\') ? $_var : throw new Template_Exception("cannot access property \\"$var\\"", $this)}';
64 }
65 }
66 else
67 {
68 throw new Template_Exception('#' . $var_name.implode('', $variable) . '# is an invalid reference', $object);
69 }
70 }
71 return $_result;
72 }
73
74 ?>