Development

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

You must first sign up to be able to contribute.

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

Revision 29523, 5.0 kB (checked in by fabien, 5 years ago)

[1.3, 1.4] fixed typos in phpdoc

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
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     if (sfConfig::get('sf_cache'))
69     {
70       $uri = $this->context->getViewCacheManager()->getCurrentCacheKey();
71       if (null !== $uri && $this->context->getViewCacheManager()->hasActionCache($uri))
72       {
73         // action in cache, so go to the view
74         return sfView::SUCCESS;
75       }
76     }
77
78     return $this->executeAction($actionInstance);
79   }
80
81   /**
82    * Executes the execute method of an action.
83    *
84    * @param sfAction $actionInstance An sfAction instance
85    *
86    * @return string The view type
87    */
88   protected function executeAction($actionInstance)
89   {
90     // execute the action
91     $actionInstance->preExecute();
92     $viewName = $actionInstance->execute($this->context->getRequest());
93     $actionInstance->postExecute();
94
95     return null === $viewName ? sfView::SUCCESS : $viewName;
96   }
97
98   /**
99    * Handles the view.
100    *
101    * @param sfFilterChain $filterChain    The current filter chain
102    * @param sfAction      $actionInstance An sfAction instance
103    * @param string        $viewName       The view name
104    */
105   protected function handleView($filterChain, $actionInstance, $viewName)
106   {
107     switch ($viewName)
108     {
109       case sfView::HEADER_ONLY:
110         $this->context->getResponse()->setHeaderOnly(true);
111         return;
112       case sfView::NONE:
113         return;
114     }
115
116     $this->executeView($actionInstance->getModuleName(), $actionInstance->getActionName(), $viewName, $actionInstance->getVarHolder()->getAll());
117   }
118
119   /**
120    * Executes and renders the view.
121    *
122    * The behavior of this method depends on the controller render mode:
123    *
124    *   - sfView::NONE: Nothing happens.
125    *   - sfView::RENDER_CLIENT: View data populates the response content.
126    *   - sfView::RENDER_VAR: View data populates the data presentation variable.
127    *
128    * @param string $moduleName     The module name
129    * @param string $actionName     The action name
130    * @param string $viewName       The view name
131    * @param array  $viewAttributes An array of view attributes
132    *
133    * @return string The view data
134    */
135   protected function executeView($moduleName, $actionName, $viewName, $viewAttributes)
136   {
137     $controller = $this->context->getController();
138
139     // get the view instance
140     $view = $controller->getView($moduleName, $actionName, $viewName);
141
142     // execute the view
143     $view->execute();
144
145     // pass attributes to the view
146     $view->getAttributeHolder()->add($viewAttributes);
147
148     // render the view
149     switch ($controller->getRenderMode())
150     {
151       case sfView::RENDER_NONE:
152         break;
153
154       case sfView::RENDER_CLIENT:
155         $viewData = $view->render();
156         $this->context->getResponse()->setContent($viewData);
157         break;
158
159       case sfView::RENDER_VAR:
160         $viewData = $view->render();
161         $controller->getActionStack()->getLastEntry()->setPresentation($viewData);
162         break;
163     }
164   }
165 }
166
Note: See TracBrowser for help on using the browser.