3 * Smarty Internal Plugin Compile Break
4 * Compiles the {break} tag
12 * Smarty Internal Plugin Compile Break Class
15 * @subpackage Compiler
17 class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
20 * Attribute definition: Overwrites base class.
23 * @see Smarty_Internal_CompileBase
25 public $optional_attributes = array('levels');
27 * Attribute definition: Overwrites base class.
30 * @see Smarty_Internal_CompileBase
32 public $shorttag_order = array('levels');
35 * Compiles code for the {break} tag
37 * @param array $args array with attributes from parser
38 * @param object $compiler compiler object
39 * @param array $parameter array with compilation parameter
41 * @return string compiled code
43 public function compile($args, $compiler, $parameter)
45 static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
46 // check and get attributes
47 $_attr = $this->getAttributes($compiler, $args);
49 if ($_attr['nocache'] === true) {
50 $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
53 if (isset($_attr['levels'])) {
54 if (!is_numeric($_attr['levels'])) {
55 $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
57 $_levels = $_attr['levels'];
61 $level_count = $_levels;
62 $stack_count = count($compiler->_tag_stack) - 1;
63 while ($level_count > 0 && $stack_count >= 0) {
64 if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
69 if ($level_count != 0) {
70 $compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno);
73 return "<?php break {$_levels}?>";