1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Acts as a php elseif block, allowing you to add one more condition |
---|
5 | * if the previous one(s) didn't match. See the {if} plugin for syntax details |
---|
6 | * |
---|
7 | * This software is provided 'as-is', without any express or implied warranty. |
---|
8 | * In no event will the authors be held liable for any damages arising from the use of this software. |
---|
9 | * |
---|
10 | * @author Jordi Boggiano <j.boggiano@seld.be> |
---|
11 | * @copyright Copyright (c) 2008, Jordi Boggiano |
---|
12 | * @license http://dwoo.org/LICENSE Modified BSD License |
---|
13 | * @link http://dwoo.org/ |
---|
14 | * @version 1.0.0 |
---|
15 | * @date 2008-10-23 |
---|
16 | * @package Dwoo |
---|
17 | */ |
---|
18 | class Dwoo_Plugin_elseif extends Dwoo_Plugin_if implements Dwoo_ICompilable_Block, Dwoo_IElseable |
---|
19 | { |
---|
20 | public function init(array $rest) |
---|
21 | { |
---|
22 | } |
---|
23 | |
---|
24 | public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
---|
25 | { |
---|
26 | $preContent = ''; |
---|
27 | while (true) { |
---|
28 | $preContent .= $compiler->removeTopBlock(); |
---|
29 | $block =& $compiler->getCurrentBlock(); |
---|
30 | $interfaces = class_implements($block['class'], false); |
---|
31 | if (in_array('Dwoo_IElseable', $interfaces) !== false) { |
---|
32 | break; |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | $params['initialized'] = true; |
---|
37 | $compiler->injectBlock($type, $params); |
---|
38 | return $preContent; |
---|
39 | } |
---|
40 | |
---|
41 | public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
---|
42 | { |
---|
43 | if (!isset($params['initialized'])) { |
---|
44 | return ''; |
---|
45 | } |
---|
46 | |
---|
47 | $tokens = $compiler->getParamTokens($params); |
---|
48 | $params = $compiler->getCompiledParams($params); |
---|
49 | |
---|
50 | $pre = Dwoo_Compiler::PHP_OPEN."elseif (".implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n" . Dwoo_Compiler::PHP_CLOSE; |
---|
51 | $post = Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE; |
---|
52 | |
---|
53 | if (isset($params['hasElse'])) { |
---|
54 | $post .= $params['hasElse']; |
---|
55 | } |
---|
56 | |
---|
57 | $block =& $compiler->getCurrentBlock(); |
---|
58 | $block['params']['hasElse'] = $pre . $content . $post; |
---|
59 | return ''; |
---|
60 | } |
---|
61 | } |
---|