| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
class sfExecutionFilter extends sfFilter |
|---|
| 23 |
{ |
|---|
| 24 |
|
|---|
| 25 |
* Executes this filter. |
|---|
| 26 |
* |
|---|
| 27 |
* @param sfFilterChain $filterChain The filter chain |
|---|
| 28 |
* |
|---|
| 29 |
* @throws <b>sfInitializeException</b> If an error occurs during view initialization. |
|---|
| 30 |
* @throws <b>sfViewException</b> If an error occurs while executing the view. |
|---|
| 31 |
*/ |
|---|
| 32 |
public function execute($filterChain) |
|---|
| 33 |
{ |
|---|
| 34 |
|
|---|
| 35 |
$actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance(); |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) |
|---|
| 39 |
{ |
|---|
| 40 |
$timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $actionInstance->getModuleName(), $actionInstance->getActionName())); |
|---|
| 41 |
|
|---|
| 42 |
$viewName = $this->handleAction($filterChain, $actionInstance); |
|---|
| 43 |
|
|---|
| 44 |
$timer->addTime(); |
|---|
| 45 |
$timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $actionInstance->getModuleName(), $actionInstance->getActionName())); |
|---|
| 46 |
|
|---|
| 47 |
$this->handleView($filterChain, $actionInstance, $viewName); |
|---|
| 48 |
|
|---|
| 49 |
$timer->addTime(); |
|---|
| 50 |
} |
|---|
| 51 |
else |
|---|
| 52 |
{ |
|---|
| 53 |
$viewName = $this->handleAction($filterChain, $actionInstance); |
|---|
| 54 |
$this->handleView($filterChain, $actionInstance, $viewName); |
|---|
| 55 |
} |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
* Handles the action. |
|---|
| 60 |
* |
|---|
| 61 |
* @param sfFilterChain $filterChain The current filter chain |
|---|
| 62 |
* @param sfAction $actionInstance An sfAction instance |
|---|
| 63 |
* |
|---|
| 64 |
* @return string The view type |
|---|
| 65 |
*/ |
|---|
| 66 |
protected function handleAction($filterChain, $actionInstance) |
|---|
| 67 |
{ |
|---|
| 68 |
$uri = $this->context->getRouting()->getCurrentInternalUri(); |
|---|
| 69 |
|
|---|
| 70 |
if (sfConfig::get('sf_cache') && !is_null($uri) && $this->context->getViewCacheManager()->hasActionCache($uri)) |
|---|
| 71 |
{ |
|---|
| 72 |
|
|---|
| 73 |
return sfView::SUCCESS; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
return $this->executeAction($actionInstance); |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
* Executes the execute method of an action. |
|---|
| 81 |
* |
|---|
| 82 |
* @param sfAction $actionInstance An sfAction instance |
|---|
| 83 |
* |
|---|
| 84 |
* @return string The view type |
|---|
| 85 |
*/ |
|---|
| 86 |
protected function executeAction($actionInstance) |
|---|
| 87 |
{ |
|---|
| 88 |
|
|---|
| 89 |
$actionInstance->preExecute(); |
|---|
| 90 |
$viewName = $actionInstance->execute($this->context->getRequest()); |
|---|
| 91 |
$actionInstance->postExecute(); |
|---|
| 92 |
|
|---|
| 93 |
return is_null($viewName) ? sfView::SUCCESS : $viewName; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
* Handles the view. |
|---|
| 98 |
* |
|---|
| 99 |
* @param sfFilterChain $filterChain The current filter chain |
|---|
| 100 |
* @param sfAction $actionInstance An sfAction instance |
|---|
| 101 |
* @param string $viewName The view name |
|---|
| 102 |
*/ |
|---|
| 103 |
protected function handleView($filterChain, $actionInstance, $viewName) |
|---|
| 104 |
{ |
|---|
| 105 |
switch ($viewName) |
|---|
| 106 |
{ |
|---|
| 107 |
case sfView::HEADER_ONLY: |
|---|
| 108 |
$this->context->getResponse()->setHeaderOnly(true); |
|---|
| 109 |
return; |
|---|
| 110 |
case sfView::NONE: |
|---|
| 111 |
return; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
$this->executeView($actionInstance->getModuleName(), $actionInstance->getActionName(), $viewName, $actionInstance->getVarHolder()->getAll()); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
* Executes and renders the view. |
|---|
| 119 |
* |
|---|
| 120 |
* The behavior of this method depends on the controller render mode: |
|---|
| 121 |
* |
|---|
| 122 |
* - sfView::NONE: Nothing happens. |
|---|
| 123 |
* - sfView::RENDER_CLIENT: View data populates the response content. |
|---|
| 124 |
* - sfView::RENDER_DATA: View data populates the data presentation variable. |
|---|
| 125 |
* |
|---|
| 126 |
* @param string $moduleName The module name |
|---|
| 127 |
* @param string $actionName The action name |
|---|
| 128 |
* @param string $viewName The view name |
|---|
| 129 |
* @param array $viewAttributes An array of view attributes |
|---|
| 130 |
* |
|---|
| 131 |
* @return string The view data |
|---|
| 132 |
*/ |
|---|
| 133 |
protected function executeView($moduleName, $actionName, $viewName, $viewAttributes) |
|---|
| 134 |
{ |
|---|
| 135 |
$controller = $this->context->getController(); |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
$view = $controller->getView($moduleName, $actionName, $viewName); |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
$view->execute(); |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
$view->getAttributeHolder()->add($viewAttributes); |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
switch ($controller->getRenderMode()) |
|---|
| 148 |
{ |
|---|
| 149 |
case sfView::RENDER_NONE: |
|---|
| 150 |
break; |
|---|
| 151 |
|
|---|
| 152 |
case sfView::RENDER_CLIENT: |
|---|
| 153 |
$viewData = $view->render(); |
|---|
| 154 |
$this->context->getResponse()->setContent($viewData); |
|---|
| 155 |
break; |
|---|
| 156 |
|
|---|
| 157 |
case sfView::RENDER_VAR: |
|---|
| 158 |
$viewData = $view->render(); |
|---|
| 159 |
$controller->getActionStack()->getLastEntry()->setPresentation($viewData); |
|---|
| 160 |
break; |
|---|
| 161 |
} |
|---|
| 162 |
} |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|