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