4  * Smarty Internal Plugin Compile Break
 
   6  * Compiles the {break} tag
 
  13  * Smarty Internal Plugin Compile Break Class
 
  15 class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase {
 
  16         // attribute definitions
 
  17     public $optional_attributes = array('levels'); 
 
  18     public $shorttag_order = array('levels');
 
  22      * Compiles code for the {break} tag
 
  24      * @param array $args array with attributes from parser
 
  25      * @param object $compiler compiler object
 
  26      * @param array $parameter array with compilation parameter
 
  27      * @return string compiled code
 
  29     public function compile($args, $compiler, $parameter)
 
  31         $this->compiler = $compiler;
 
  32         $this->smarty = $compiler->smarty;
 
  33         // check and get attributes
 
  34         $_attr = $this->_get_attributes($args);
 
  36         if ($_attr['nocache'] === true) {
 
  37                 $this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
 
  40         if (isset($_attr['levels'])) {
 
  41             if (!is_numeric($_attr['levels'])) {
 
  42                 $this->compiler->trigger_template_error('level attribute must be a numeric constant', $this->compiler->lex->taglineno);
 
  44             $_levels = $_attr['levels'];
 
  48         $level_count = $_levels;
 
  49         $stack_count = count($compiler->_tag_stack) - 1;
 
  50         while ($level_count > 0 && $stack_count >= 0) {
 
  51             if (in_array($compiler->_tag_stack[$stack_count][0], array('for', 'foreach', 'while', 'section'))) {
 
  56         if ($level_count != 0) {
 
  57             $this->compiler->trigger_template_error("cannot break {$_levels} level(s)", $this->compiler->lex->taglineno);
 
  59         // this tag does not return compiled code
 
  60         $this->compiler->has_code = true;
 
  61         return "<?php break {$_levels}?>";