PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 37ms app.codeStats 0ms

/lib/Dwoo/plugins/builtin/blocks/elseif.php

http://phpdays.googlecode.com/
PHP | 60 lines | 37 code | 8 blank | 15 comment | 4 complexity | 7941844f1fe32ae3c2e2f7e71d39610b MD5 | raw file
 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 */
18class 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		$params = $compiler->getCompiledParams($params);
48
49		$pre = Dwoo_Compiler::PHP_OPEN."elseif (".implode(' ', self::replaceKeywords($params['*'], $compiler)).") {\n" . Dwoo_Compiler::PHP_CLOSE;
50		$post = Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
51
52		if (isset($params['hasElse'])) {
53			$post .= $params['hasElse'];
54		}
55
56		$block =& $compiler->getCurrentBlock();
57		$block['params']['hasElse'] = $pre . $content . $post;
58		return '';
59	}
60}