2
0

Abstract.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Controller_Action
  24. */
  25. require_once 'Zend/Controller/Action.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Controller
  29. * @subpackage Zend_Controller_Action_Helper
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. abstract class Zend_Controller_Action_Helper_Abstract
  34. {
  35. /**
  36. * $_actionController
  37. *
  38. * @var Zend_Controller_Action $_actionController
  39. */
  40. protected $_actionController = null;
  41. /**
  42. * @var mixed $_frontController
  43. */
  44. protected $_frontController = null;
  45. /**
  46. * setActionController()
  47. *
  48. * @param Zend_Controller_Action $actionController
  49. * @return Zend_Controller_ActionHelper_Abstract Provides a fluent interface
  50. */
  51. public function setActionController(Zend_Controller_Action $actionController = null)
  52. {
  53. $this->_actionController = $actionController;
  54. return $this;
  55. }
  56. /**
  57. * Retrieve current action controller
  58. *
  59. * @return Zend_Controller_Action
  60. */
  61. public function getActionController()
  62. {
  63. return $this->_actionController;
  64. }
  65. /**
  66. * Retrieve front controller instance
  67. *
  68. * @return Zend_Controller_Front
  69. */
  70. public function getFrontController()
  71. {
  72. if (null === $this->_frontController) {
  73. $this->_frontController = Zend_Controller_Front::getInstance();
  74. }
  75. return $this->_frontController;
  76. }
  77. /**
  78. * Hook into action controller initialization
  79. *
  80. * @return void
  81. */
  82. public function init()
  83. {
  84. }
  85. /**
  86. * Hook into action controller preDispatch() workflow
  87. *
  88. * @return void
  89. */
  90. public function preDispatch()
  91. {
  92. }
  93. /**
  94. * Hook into action controller postDispatch() workflow
  95. *
  96. * @return void
  97. */
  98. public function postDispatch()
  99. {
  100. }
  101. /**
  102. * getRequest() -
  103. *
  104. * @return Zend_Controller_Request_Abstract $request
  105. */
  106. public function getRequest()
  107. {
  108. $controller = $this->getActionController();
  109. if (null === $controller) {
  110. $controller = $this->getFrontController();
  111. }
  112. return $controller->getRequest();
  113. }
  114. /**
  115. * getResponse() -
  116. *
  117. * @return Zend_Controller_Response_Abstract $response
  118. */
  119. public function getResponse()
  120. {
  121. $controller = $this->getActionController();
  122. if (null === $controller) {
  123. $controller = $this->getFrontController();
  124. }
  125. return $controller->getResponse();
  126. }
  127. /**
  128. * getName()
  129. *
  130. * @return string
  131. */
  132. public function getName()
  133. {
  134. $full_class_name = get_class($this);
  135. if (strpos($full_class_name, '_') !== false) {
  136. $helper_name = strrchr($full_class_name, '_');
  137. return ltrim($helper_name, '_');
  138. } else {
  139. return $full_class_name;
  140. }
  141. }
  142. }