Abstract.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 preDispatch() workflow
  79. *
  80. * @return void
  81. */
  82. public function preDispatch()
  83. {
  84. }
  85. /**
  86. * Hook into action controller postDispatch() workflow
  87. *
  88. * @return void
  89. */
  90. public function postDispatch()
  91. {
  92. }
  93. /**
  94. * getRequest() -
  95. *
  96. * @return Zend_Controller_Request_Abstract $request
  97. */
  98. public function getRequest()
  99. {
  100. $controller = $this->getActionController();
  101. if (null === $controller) {
  102. $controller = $this->getFrontController();
  103. }
  104. return $controller->getRequest();
  105. }
  106. /**
  107. * getResponse() -
  108. *
  109. * @return Zend_Controller_Response_Abstract $response
  110. */
  111. public function getResponse()
  112. {
  113. $controller = $this->getActionController();
  114. if (null === $controller) {
  115. $controller = $this->getFrontController();
  116. }
  117. return $controller->getResponse();
  118. }
  119. /**
  120. * getName()
  121. *
  122. * @return string
  123. */
  124. public function getName()
  125. {
  126. $full_class_name = get_class($this);
  127. if (strpos($full_class_name, '_') !== false) {
  128. $helper_name = strrchr($full_class_name, '_');
  129. return ltrim($helper_name, '_');
  130. } else {
  131. return $full_class_name;
  132. }
  133. }
  134. }