Code

Updated smarty
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compilebase.php
1 <?php
3 /**
4 * Smarty Internal Plugin CompileBase
5
6 * @package Smarty
7 * @subpackage Compiler
8 * @author Uwe Tews 
9 */
11 /**
12 * This class does extend all internal compile plugins
13 */
14 //abstract class Smarty_Internal_CompileBase implements TagCompilerInterface 
15 abstract class Smarty_Internal_CompileBase 
16 {
17     function __construct()
18     {
19         // initialize valid attributes
20         $this->required_attributes = array();
21         $this->optional_attributes = array();
22     } 
24     /**
25     * This function checks if the attributes passed are valid
26     * 
27     * The attributes passed for the tag to compile are checked against the list of required and 
28     * optional attributes. Required attributes must be present. Optional attributes are check against
29     * against the corresponding list. The keyword '_any' specifies that any attribute will be accepted 
30     * as valid
31     * 
32     * @todo More generallized handling of the nocache attributes in compile plugins
33     * @param array $args attributes applied to the tag
34     * @return array attributes for further processing
35     */
36     function _get_attributes ($args)
37     { 
38         // check if all required attributes present
39         foreach ($this->required_attributes as $attr) {
40             if (!array_key_exists($attr, $args)) {
41                 $this->compiler->trigger_template_error("missing \"" . $attr . "\" attribute");
42             } 
43         } 
44         // check for unallowed attributes
45         if ($this->optional_attributes != array('_any')) {
46             $tmp_array = array_merge($this->required_attributes, $this->optional_attributes);
47             foreach ($args as $key => $dummy) {
48                  if (!in_array($key, $tmp_array) && $key !== 0) {
49                    $this->compiler->trigger_template_error("unexpected \"" . $key . "\" attribute");
50                 } 
51             } 
52         } 
54         return $args;
55     } 
57     /**
58     * Push opening tag name on stack
59     * 
60     * Optionally additional data can be saved on stack
61     * 
62     * @param string $open_tag the opening tag's name
63     * @param anytype $data optional data which shall be saved on stack
64     */
65     function _open_tag($open_tag, $data = null)
66     {
67         array_push($this->compiler->_tag_stack, array($open_tag, $data));
68     } 
70     /**
71     * Pop closing tag
72     * 
73     * Raise an error if this stack-top doesn't match with expected opening tags
74     * 
75     * @param array $ |string $expected_tag the expected opening tag names
76     * @return anytype the opening tag's name or saved data
77     */
78     function _close_tag($expected_tag)
79     {
80         if (count($this->compiler->_tag_stack) > 0) {
81             // get stacked info
82             list($_open_tag, $_data) = array_pop($this->compiler->_tag_stack); 
83             // open tag must match with the expected ones
84             if (in_array($_open_tag, (array)$expected_tag)) {
85                 if (is_null($_data)) {
86                     // return opening tag
87                     return $_open_tag;
88                 } else {
89                     // return restored data
90                     return $_data;
91                 } 
92             } 
93             // wrong nesting of tags
94             $this->compiler->trigger_template_error("unclosed {" . $_open_tag . "} tag");
95             return;
96         } 
97         // wrong nesting of tags
98         $this->compiler->trigger_template_error("unexpected closing tag");
99         return;
100     } 
101
103 ?>