PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/nooku/libraries/koowa/template/filter/template.php

https://github.com/bhar1red/anahita
PHP | 62 lines | 26 code | 4 blank | 32 comment | 3 complexity | 4e21f5dce40700f314aa5610d0d68408 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: template.php 4628 2012-05-06 19:56:43Z johanjanssens $
  4. * @package Koowa_Template
  5. * @subpackage Filter
  6. * @copyright Copyright (C) 2007 - 2012 Johan Janssens. All rights reserved.
  7. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
  8. * @link http://www.nooku.org
  9. */
  10. /**
  11. * Template read filter for the @template alias. To load templates inline
  12. *
  13. * @author Johan Janssens <johan@nooku.org>
  14. * @package Koowa_Template
  15. * @subpackage Filter
  16. */
  17. class KTemplateFilterTemplate extends KTemplateFilterAbstract implements KTemplateFilterRead
  18. {
  19. /**
  20. * Initializes the options for the object
  21. *
  22. * Called from {@link __construct()} as a first step of object instantiation.
  23. *
  24. * @param object An optional KConfig object with configuration options
  25. * @return void
  26. */
  27. protected function _initialize(KConfig $config)
  28. {
  29. $config->append(array(
  30. 'priority' => KCommand::PRIORITY_HIGH,
  31. ));
  32. parent::_initialize($config);
  33. }
  34. /**
  35. * Replace template alias with loadFile functions.
  36. *
  37. * This function only replaces relative identifiers to a full path
  38. * based on the path of the template.
  39. *
  40. * @param string
  41. * @return KTemplateFilterAlias
  42. */
  43. public function read(&$text)
  44. {
  45. if(preg_match_all('#@template\(\'(.*)\'#siU', $text, $matches))
  46. {
  47. foreach($matches[1] as $key => $match)
  48. {
  49. if(is_string($match) && strpos($match, '.') === false )
  50. {
  51. $path = dirname($this->getTemplate()->getPath()).DS.$match.'.php';
  52. $text = str_replace($matches[0][$key], '$this->loadFile('."'".$path."'", $text);
  53. }
  54. }
  55. }
  56. return $this;
  57. }
  58. }