PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/application/libraries/Zend/View/Helper/Action.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 164 lines | 72 code | 20 blank | 72 comment | 6 complexity | b8a3d10e8279c52840fcb87044e18ef7 MD5 | raw file
  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_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @version $Id: Action.php 23775 2011-03-01 17:25:24Z ralph $
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /** Zend_View_Helper_Abstract.php */
  23. require_once 'Zend/View/Helper/Abstract.php';
  24. /**
  25. * Helper for rendering output of a controller action
  26. *
  27. * @package Zend_View
  28. * @subpackage Helper
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_View_Helper_Action extends Zend_View_Helper_Abstract
  33. {
  34. /**
  35. * @var string
  36. */
  37. public $defaultModule;
  38. /**
  39. * @var Zend_Controller_Dispatcher_Interface
  40. */
  41. public $dispatcher;
  42. /**
  43. * @var Zend_Controller_Request_Abstract
  44. */
  45. public $request;
  46. /**
  47. * @var Zend_Controller_Response_Abstract
  48. */
  49. public $response;
  50. /**
  51. * Constructor
  52. *
  53. * Grab local copies of various MVC objects
  54. *
  55. * @return void
  56. */
  57. public function __construct()
  58. {
  59. $front = Zend_Controller_Front::getInstance();
  60. $modules = $front->getControllerDirectory();
  61. if (empty($modules)) {
  62. require_once 'Zend/View/Exception.php';
  63. $e = new Zend_View_Exception('Action helper depends on valid front controller instance');
  64. $e->setView($this->view);
  65. throw $e;
  66. }
  67. $request = $front->getRequest();
  68. $response = $front->getResponse();
  69. if (empty($request) || empty($response)) {
  70. require_once 'Zend/View/Exception.php';
  71. $e = new Zend_View_Exception('Action view helper requires both a registered request and response object in the front controller instance');
  72. $e->setView($this->view);
  73. throw $e;
  74. }
  75. $this->request = clone $request;
  76. $this->response = clone $response;
  77. $this->dispatcher = clone $front->getDispatcher();
  78. $this->defaultModule = $front->getDefaultModule();
  79. }
  80. /**
  81. * Reset object states
  82. *
  83. * @return void
  84. */
  85. public function resetObjects()
  86. {
  87. $params = $this->request->getUserParams();
  88. foreach (array_keys($params) as $key) {
  89. $this->request->setParam($key, null);
  90. }
  91. $this->response->clearBody();
  92. $this->response->clearHeaders()
  93. ->clearRawHeaders();
  94. }
  95. /**
  96. * Retrieve rendered contents of a controller action
  97. *
  98. * If the action results in a forward or redirect, returns empty string.
  99. *
  100. * @param string $action
  101. * @param string $controller
  102. * @param string $module Defaults to default module
  103. * @param array $params
  104. * @return string
  105. */
  106. public function action($action, $controller, $module = null, array $params = array())
  107. {
  108. $this->resetObjects();
  109. if (null === $module) {
  110. $module = $this->defaultModule;
  111. }
  112. // clone the view object to prevent over-writing of view variables
  113. $viewRendererObj = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
  114. Zend_Controller_Action_HelperBroker::addHelper(clone $viewRendererObj);
  115. $this->request->setParams($params)
  116. ->setModuleName($module)
  117. ->setControllerName($controller)
  118. ->setActionName($action)
  119. ->setDispatched(true);
  120. $this->dispatcher->dispatch($this->request, $this->response);
  121. // reset the viewRenderer object to it's original state
  122. Zend_Controller_Action_HelperBroker::addHelper($viewRendererObj);
  123. if (!$this->request->isDispatched()
  124. || $this->response->isRedirect())
  125. {
  126. // forwards and redirects render nothing
  127. return '';
  128. }
  129. $return = $this->response->getBody();
  130. $this->resetObjects();
  131. return $return;
  132. }
  133. /**
  134. * Clone the current View
  135. *
  136. * @return Zend_View_Interface
  137. */
  138. public function cloneView()
  139. {
  140. $view = clone $this->view;
  141. $view->clearVars();
  142. return $view;
  143. }
  144. }