/Kwf/Component/View/Renderer.php

https://github.com/koala-framework/koala-framework · PHP · 87 lines · 80 code · 6 blank · 1 comment · 6 complexity · f5f6b1d2e646887a489488c638cd53ec MD5 · raw file

  1. <?php
  2. abstract class Kwf_Component_View_Renderer extends Kwf_Component_View_Helper_Abstract
  3. {
  4. protected function _canBeIncludedInFullPageCache($componentId, $viewCacheEnabled)
  5. {
  6. //is caching possible for this type? and is view cache enabled?
  7. $settings = $this->getViewCacheSettings($componentId);
  8. return $settings['enabled'] && $viewCacheEnabled;
  9. }
  10. protected function _getRenderPlaceholder($componentId, $config = array(), $value = null, $viewCacheEnabled = true)
  11. {
  12. $type = $this->_getType();
  13. $this->_getRenderer()->includedComponent($componentId, $type);
  14. if ($this->_canBeIncludedInFullPageCache($componentId, $viewCacheEnabled)) {
  15. $pass = 1;
  16. } else {
  17. $pass = 2;
  18. }
  19. $config = $config ? base64_encode(serialize($config)) : '';
  20. return "<kwc$pass $type $componentId $value $config>";
  21. }
  22. protected function _getComponentById($componentId)
  23. {
  24. $ret = Kwf_Component_Data_Root::getInstance()
  25. ->getComponentById($componentId, array('ignoreVisible' => true));
  26. if (!$ret) throw new Kwf_Exception("Can't find component '$componentId' for rendering");
  27. return $ret;
  28. }
  29. protected function _getType()
  30. {
  31. $ret = substr(strrchr(get_class($this), '_'), 1);
  32. $ret = strtolower(substr($ret, 0, 1)).substr($ret, 1); //anfangsbuchstaben klein
  33. return $ret;
  34. }
  35. /**
  36. * wird für ungecachte komponenten aufgerufen
  37. *
  38. * wird nur aufgerufen wenn ungecached
  39. */
  40. public abstract function render($componentId, $config);
  41. /**
  42. * Kann die render ausgabe (die aus cache oder direkt aus render kommen kann)
  43. * anpassen.
  44. *
  45. * wird immer aufgerufen, auch wenn sie gecached ist
  46. */
  47. public function renderCached($cachedContent, $componentId, $config)
  48. {
  49. return $cachedContent;
  50. }
  51. public function getViewCacheSettings($componentId)
  52. {
  53. return array(
  54. 'enabled' => true,
  55. 'lifetime' => null
  56. );
  57. }
  58. public static function replaceHtmlKwfUp($ret)
  59. {
  60. $ret = preg_replace_callback('#((class|id|for|style)="[^"]*)"#', array('Kwf_Component_View_Renderer', '_replaceKwfUpCb'), $ret);
  61. return $ret;
  62. }
  63. public static function _replaceKwfUpCb($m)
  64. {
  65. return self::_replaceKwfUp($m[0]);
  66. }
  67. protected static function _replaceKwfUp($ret)
  68. {
  69. static $up;
  70. if (!isset($up)) {
  71. $up = Kwf_Config::getValue('application.uniquePrefix');
  72. if ($up) $up .= '-';
  73. }
  74. return str_replace('kwfUp-', $up, $ret);
  75. }
  76. }