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