1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Generic else block, it supports all builtin optional-display blocks which are if/for/foreach/loop/with |
---|
5 | * |
---|
6 | * If any of those block contains an else statement, the content between {else} and {/block} (you do not |
---|
7 | * need to close the else block) will be shown if the block's condition has no been met |
---|
8 | * |
---|
9 | * Example : |
---|
10 | * |
---|
11 | * <code> |
---|
12 | * {foreach $array val} |
---|
13 | * $array is not empty so we display it's values : {$val} |
---|
14 | * {else} |
---|
15 | * if this shows, it means that $array is empty or doesn't exist. |
---|
16 | * {/foreach} |
---|
17 | * </code> |
---|
18 | * |
---|
19 | * This software is provided 'as-is', without any express or implied warranty. |
---|
20 | * In no event will the authors be held liable for any damages arising from the use of this software. |
---|
21 | * |
---|
22 | * @author Jordi Boggiano <j.boggiano@seld.be> |
---|
23 | * @copyright Copyright (c) 2008, Jordi Boggiano |
---|
24 | * @license http://dwoo.org/LICENSE Modified BSD License |
---|
25 | * @link http://dwoo.org/ |
---|
26 | * @version 1.0.0 |
---|
27 | * @date 2008-10-23 |
---|
28 | * @package Dwoo |
---|
29 | */ |
---|
30 | class Dwoo_Plugin_else extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block |
---|
31 | { |
---|
32 | public function init() |
---|
33 | { |
---|
34 | } |
---|
35 | |
---|
36 | public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
---|
37 | { |
---|
38 | $preContent = ''; |
---|
39 | while (true) { |
---|
40 | $preContent .= $compiler->removeTopBlock(); |
---|
41 | $block =& $compiler->getCurrentBlock(); |
---|
42 | $interfaces = class_implements($block['class'], false); |
---|
43 | if (in_array('Dwoo_IElseable', $interfaces) !== false) { |
---|
44 | break; |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | $params['initialized'] = true; |
---|
49 | $compiler->injectBlock($type, $params); |
---|
50 | return $preContent; |
---|
51 | } |
---|
52 | |
---|
53 | public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
---|
54 | { |
---|
55 | if (!isset($params['initialized'])) { |
---|
56 | return ''; |
---|
57 | } |
---|
58 | |
---|
59 | $block =& $compiler->getCurrentBlock(); |
---|
60 | $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE . $content . Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE; |
---|
61 | return ''; |
---|
62 | } |
---|
63 | } |
---|