/packages/Output/Smarty/Core/sysplugins/smarty_internal_compile_continue.php
PHP | 77 lines | 34 code | 6 blank | 37 comment | 9 complexity | ad8ee630467af7e1ce7b40487a703a16 MD5 | raw file
1<?php
2/**
3 * Smarty Internal Plugin Compile Continue
4 * Compiles the {continue} tag
5 *
6 * @package Smarty
7 * @subpackage Compiler
8 * @author Uwe Tews
9 */
10
11/**
12 * Smarty Internal Plugin Compile Continue Class
13 *
14 * @package Smarty
15 * @subpackage Compiler
16 */
17class Smarty_Internal_Compile_Continue 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 /**
28 * Attribute definition: Overwrites base class.
29 *
30 * @var array
31 * @see Smarty_Internal_CompileBase
32 */
33 public $shorttag_order = array('levels');
34
35 /**
36 * Compiles code for the {continue} tag
37 *
38 * @param array $args array with attributes from parser
39 * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
40 * @param array $parameter array with compilation parameter
41 *
42 * @return string compiled code
43 * @throws \SmartyCompilerException
44 */
45 public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
46 {
47 static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
48 // check and get attributes
49 $_attr = $this->getAttributes($compiler, $args);
50
51 if ($_attr[ 'nocache' ] === true) {
52 $compiler->trigger_template_error('nocache option not allowed', null, true);
53 }
54
55 if (isset($_attr[ 'levels' ])) {
56 if (!is_numeric($_attr[ 'levels' ])) {
57 $compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
58 }
59 $_levels = $_attr[ 'levels' ];
60 } else {
61 $_levels = 1;
62 }
63 $level_count = $_levels;
64 $stack_count = count($compiler->_tag_stack) - 1;
65 while ($level_count > 0 && $stack_count >= 0) {
66 if (isset($_is_loopy[ $compiler->_tag_stack[ $stack_count ][ 0 ] ])) {
67 $level_count --;
68 }
69 $stack_count --;
70 }
71 if ($level_count != 0) {
72 $compiler->trigger_template_error("cannot continue {$_levels} level(s)", null, true);
73 }
74
75 return "<?php continue {$_levels};?>";
76 }
77}