Development

/branches/1.2/lib/filter/sfExecutionFilter.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/filter/sfExecutionFilter.class.php

Revision 17858, 4.9 kB (checked in by FabianLange, 5 years ago)

[1.1, 1.2, 1.3] fixed some codeing standards (fixes #6376 - patch from gimler)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  * (c) 2004-2006 Sean Kerr <sean@code-box.org>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * sfExecutionFilter is the last filter registered for each filter chain. This
14  * filter does all action and view execution.
15  *
16  * @package    symfony
17  * @subpackage filter
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @author     Sean Kerr <sean@code-box.org>
20  * @version    SVN: $Id$
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     // get the current action instance
35     $actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance();
36
37     // execute the action, execute and render the view
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       // action in cache, so go to the view
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     // execute the action
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     // get the view instance
138     $view = $controller->getView($moduleName, $actionName, $viewName);
139
140     // execute the view
141     $view->execute();
142
143     // pass attributes to the view
144     $view->getAttributeHolder()->add($viewAttributes);
145
146     // render the view
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
Note: See TracBrowser for help on using the browser.