1 | <?php |
---|
2 | /** |
---|
3 | * Smarty Internal Plugin Compile Break |
---|
4 | * |
---|
5 | * Compiles the {break} tag |
---|
6 | * |
---|
7 | * @package Smarty |
---|
8 | * @subpackage Compiler |
---|
9 | * @author Uwe Tews |
---|
10 | */ |
---|
11 | /** |
---|
12 | * Smarty Internal Plugin Compile Break Class |
---|
13 | * |
---|
14 | * @package Smarty |
---|
15 | * @subpackage Compiler |
---|
16 | */ |
---|
17 | class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase { |
---|
18 | |
---|
19 | /** |
---|
20 | * Attribute definition: Overwrites base class. |
---|
21 | * |
---|
22 | * @var array |
---|
23 | * @see Smarty_Internal_CompileBase |
---|
24 | */ |
---|
25 | public $optional_attributes = array('levels'); |
---|
26 | /** |
---|
27 | * Attribute definition: Overwrites base class. |
---|
28 | * |
---|
29 | * @var array |
---|
30 | * @see Smarty_Internal_CompileBase |
---|
31 | */ |
---|
32 | public $shorttag_order = array('levels'); |
---|
33 | |
---|
34 | /** |
---|
35 | * Compiles code for the {break} tag |
---|
36 | * |
---|
37 | * @param array $args array with attributes from parser |
---|
38 | * @param object $compiler compiler object |
---|
39 | * @param array $parameter array with compilation parameter |
---|
40 | * @return string compiled code |
---|
41 | */ |
---|
42 | public function compile($args, $compiler, $parameter) |
---|
43 | { |
---|
44 | static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); |
---|
45 | // check and get attributes |
---|
46 | $_attr = $this->getAttributes($compiler, $args); |
---|
47 | |
---|
48 | if ($_attr['nocache'] === true) { |
---|
49 | $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |
---|
50 | } |
---|
51 | |
---|
52 | if (isset($_attr['levels'])) { |
---|
53 | if (!is_numeric($_attr['levels'])) { |
---|
54 | $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); |
---|
55 | } |
---|
56 | $_levels = $_attr['levels']; |
---|
57 | } else { |
---|
58 | $_levels = 1; |
---|
59 | } |
---|
60 | $level_count = $_levels; |
---|
61 | $stack_count = count($compiler->_tag_stack) - 1; |
---|
62 | while ($level_count > 0 && $stack_count >= 0) { |
---|
63 | if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { |
---|
64 | $level_count--; |
---|
65 | } |
---|
66 | $stack_count--; |
---|
67 | } |
---|
68 | if ($level_count != 0) { |
---|
69 | $compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno); |
---|
70 | } |
---|
71 | $compiler->has_code = true; |
---|
72 | return "<?php break {$_levels}?>"; |
---|
73 | } |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | ?> |
---|