AbstractHelper.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ hdJu3rr7BgJDAVkYjTvYG/ZRNRdup1qDbnUhOCimuXM=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2015 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.4
  11. */
  12. /**
  13. * view helpers abstract class
  14. */
  15. namespace Cube\View\Helper;
  16. use Cube\View,
  17. Cube\Controller\Front,
  18. Cube\Translate,
  19. Cube\Translate\Adapter\AbstractAdapter as TranslateAdapter;
  20. abstract class AbstractHelper implements HelperInterface
  21. {
  22. /**
  23. * view object
  24. *
  25. * @var \Cube\View
  26. */
  27. protected $_view = null;
  28. /**
  29. *
  30. * the view partial to be used
  31. *
  32. * @var string
  33. */
  34. protected $_partial;
  35. /**
  36. *
  37. * translate adapter
  38. *
  39. * @var \Cube\Translate\Adapter\AbstractAdapter
  40. */
  41. protected $_translate;
  42. /**
  43. *
  44. * the end tag of the html element
  45. *
  46. * @var string
  47. */
  48. protected $_endTag = '>';
  49. /**
  50. *
  51. * get the view object
  52. *
  53. * @return \Cube\View
  54. */
  55. public function getView()
  56. {
  57. if ($this->_view === null) {
  58. $this->setView();
  59. }
  60. return $this->_view;
  61. }
  62. /**
  63. * set the view object
  64. *
  65. * @param \Cube\View $view
  66. *
  67. * @return $this
  68. */
  69. public function setView(View $view = null)
  70. {
  71. if (!$view instanceof View) {
  72. $bootstrap = Front::getInstance()->getBootstrap();
  73. if ($bootstrap->hasResource('view')) {
  74. $view = $bootstrap->getResource('view');
  75. } else {
  76. $view = new View();
  77. }
  78. }
  79. $this->_view = $view;
  80. return $this;
  81. }
  82. /**
  83. *
  84. * get the view file
  85. *
  86. * @return string
  87. */
  88. public function getPartial()
  89. {
  90. return $this->_partial;
  91. }
  92. /**
  93. *
  94. * set the view file
  95. *
  96. * @param string $partial
  97. *
  98. * @return $this
  99. */
  100. public function setPartial($partial)
  101. {
  102. $this->_partial = $partial;
  103. return $this;
  104. }
  105. /**
  106. *
  107. * get translate adapter
  108. *
  109. * @return \Cube\Translate\Adapter\AbstractAdapter
  110. */
  111. public function getTranslate()
  112. {
  113. if (!$this->_translate instanceof TranslateAdapter) {
  114. $translate = Front::getInstance()->getBootstrap()->getResource('translate');
  115. if ($translate instanceof Translate) {
  116. $this->setTranslate(
  117. $translate->getAdapter());
  118. }
  119. }
  120. return $this->_translate;
  121. }
  122. /**
  123. *
  124. * set translate adapter
  125. *
  126. * @param \Cube\Translate\Adapter\AbstractAdapter $translate
  127. *
  128. * @return $this
  129. */
  130. public function setTranslate(TranslateAdapter $translate)
  131. {
  132. $this->_translate = $translate;
  133. return $this;
  134. }
  135. }