PageRenderTime 32ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/Opl/Opt/Instruction/Extend.php

https://bitbucket.org/kandsten/hitta.sverok.se
PHP | 78 lines | 52 code | 10 blank | 16 comment | 6 complexity | 928eb87b5941f0f007e251b8f1393184 MD5 | raw file
Possible License(s): GPL-3.0, MIT
  1. <?php
  2. /*
  3. * OPEN POWER LIBS <http://www.invenzzia.org>
  4. *
  5. * This file is subject to the new BSD license that is bundled
  6. * with this package in the file LICENSE. It is also available through
  7. * WWW at this URL: <http://www.invenzzia.org/license/new-bsd>
  8. *
  9. * Copyright (c) Invenzzia Group <http://www.invenzzia.org>
  10. * and other contributors. See website for details.
  11. *
  12. * $Id: Extend.php 231 2009-09-19 07:13:14Z zyxist $
  13. */
  14. class Opt_Instruction_Extend extends Opt_Compiler_Processor
  15. {
  16. protected $_name = 'extend';
  17. public function configure()
  18. {
  19. /* IMPORTANT NOTICE: This instruction is partially hard-coded inside the compiler, because
  20. * it would be to hard to do what it is intented to do from this level. See: _generateExtend()
  21. * in "Internal tools and utilities" of /opt/compiler/class.php
  22. */
  23. $this->_addInstructions(array('opt:extend'));
  24. } // end configure();
  25. public function processNode(Opt_Xml_Node $node)
  26. {
  27. if($node->getParent()->getType() != 'Opt_Xml_Root')
  28. {
  29. throw new Opt_InstructionInvalidParent_Exception($node->getXmlName(), 'ROOT');
  30. }
  31. $params = array(
  32. 'file' => array(0 => self::REQUIRED, self::HARD_STRING),
  33. 'escaping' => array(0 => self::OPTIONAL, self::BOOL, NULL),
  34. 'dynamic' => array(0 => self::OPTIONAL, self::BOOL, false),
  35. '__UNKNOWN__' => array(0 => self::OPTIONAL, self::HARD_STRING, null),
  36. );
  37. $branches = $this->_extractAttributes($node, $params);
  38. if(!is_null($params['escaping']))
  39. {
  40. $this->_compiler->set('escaping', $params['escaping']);
  41. }
  42. if($params['dynamic'] && !is_null($branch = $this->_compiler->inherits($this->_compiler->get('currentTemplate'))))
  43. {
  44. }
  45. elseif(isset($branches[$this->_compiler->get('branch')]))
  46. {
  47. $branch = $branches[$this->_compiler->get('branch')];
  48. }
  49. else
  50. {
  51. $branch = $params['file'];
  52. }
  53. $node->set('branch', $branch);
  54. $node->set('postprocess', true);
  55. $this->_process($node);
  56. } // end processNode();
  57. public function postprocessNode(Opt_Xml_Node $node)
  58. {
  59. if($this->_compiler->processor('snippet')->isSnippet($node->get('branch')))
  60. {
  61. $node->getParent()->set('snippet', $node->get('branch'));
  62. }
  63. else
  64. {
  65. $node->getParent()->set('extend', $node->get('branch'));
  66. }
  67. } // end postprocessNode();
  68. } // end Opt_Instruction_Extends;