2
0

Abstract.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Controller
  17. * @subpackage Zend_Controller_Action_Helper
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Controller_Action
  23. */
  24. require_once 'Zend/Controller/Action.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Controller
  28. * @subpackage Zend_Controller_Action_Helper
  29. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. abstract class Zend_Controller_Action_Helper_Abstract
  33. {
  34. /**
  35. * $_actionController
  36. *
  37. * @var Zend_Controller_Action $_actionController
  38. */
  39. protected $_actionController = null;
  40. /**
  41. * @var mixed $_frontController
  42. */
  43. protected $_frontController = null;
  44. /**
  45. * setActionController()
  46. *
  47. * @param Zend_Controller_Action $actionController
  48. * @return Zend_Controller_ActionHelper_Abstract Provides a fluent interface
  49. */
  50. public function setActionController(Zend_Controller_Action $actionController = null)
  51. {
  52. $this->_actionController = $actionController;
  53. return $this;
  54. }
  55. /**
  56. * Retrieve current action controller
  57. *
  58. * @return Zend_Controller_Action
  59. */
  60. public function getActionController()
  61. {
  62. return $this->_actionController;
  63. }
  64. /**
  65. * Retrieve front controller instance
  66. *
  67. * @return Zend_Controller_Front
  68. */
  69. public function getFrontController()
  70. {
  71. if (null === $this->_frontController) {
  72. $this->_frontController = Zend_Controller_Front::getInstance();
  73. }
  74. return $this->_frontController;
  75. }
  76. /**
  77. * Hook into action controller initialization
  78. *
  79. * @return void
  80. */
  81. public function init()
  82. {
  83. }
  84. /**
  85. * Hook into action controller preDispatch() workflow
  86. *
  87. * @return void
  88. */
  89. public function preDispatch()
  90. {
  91. }
  92. /**
  93. * Hook into action controller postDispatch() workflow
  94. *
  95. * @return void
  96. */
  97. public function postDispatch()
  98. {
  99. }
  100. /**
  101. * getRequest() -
  102. *
  103. * @return Zend_Controller_Request_Abstract $request
  104. */
  105. public function getRequest()
  106. {
  107. $controller = $this->getActionController();
  108. if (null === $controller) {
  109. $controller = $this->getFrontController();
  110. }
  111. return $controller->getRequest();
  112. }
  113. /**
  114. * getResponse() -
  115. *
  116. * @return Zend_Controller_Response_Abstract $response
  117. */
  118. public function getResponse()
  119. {
  120. $controller = $this->getActionController();
  121. if (null === $controller) {
  122. $controller = $this->getFrontController();
  123. }
  124. return $controller->getResponse();
  125. }
  126. /**
  127. * getName()
  128. *
  129. * @return string
  130. */
  131. public function getName()
  132. {
  133. $full_class_name = get_class($this);
  134. if (strpos($full_class_name, '_') !== false) {
  135. $helper_name = strrchr($full_class_name, '_');
  136. return ltrim($helper_name, '_');
  137. } else {
  138. return $full_class_name;
  139. }
  140. }
  141. }