Development

/branches/1.4/lib/view/sfPartialView.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/view/sfPartialView.class.php

Revision 31928, 4.0 kB (checked in by Kris.Wallsmith, 4 years ago)

[1.3, 1.4] copied more values into a cachable partial's cloned response when the partial is marked as contextual in cache.yml (closes #7192)

  • 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  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * A View to render partials.
13  *
14  * @package    symfony
15  * @subpackage view
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfPartialView extends sfPHPView
20 {
21   protected
22     $viewCache   = null,
23     $checkCache  = false,
24     $cacheKey    = null,
25     $partialVars = array();
26
27   /**
28    * Constructor.
29    *
30    * @see sfView
31    */
32   public function initialize($context, $moduleName, $actionName, $viewName)
33   {
34     $ret = parent::initialize($context, $moduleName, $actionName, $viewName);
35
36     $this->viewCache = $this->context->getViewCacheManager();
37
38     if (sfConfig::get('sf_cache'))
39     {
40       $this->checkCache = $this->viewCache->isActionCacheable($moduleName, $actionName);
41     }
42
43     return $ret;
44   }
45
46   /**
47    * Executes any presentation logic for this view.
48    */
49   public function execute()
50   {
51   }
52
53   /**
54    * @param array $partialVars
55    */
56   public function setPartialVars(array $partialVars)
57   {
58     $this->partialVars = $partialVars;
59     $this->getAttributeHolder()->add($partialVars);
60   }
61
62   /**
63    * Configures template for this view.
64    */
65   public function configure()
66   {
67     $this->setDecorator(false);
68     $this->setTemplate($this->actionName.$this->getExtension());
69     if ('global' == $this->moduleName)
70     {
71       $this->setDirectory($this->context->getConfiguration()->getDecoratorDir($this->getTemplate()));
72     }
73     else
74     {
75       $this->setDirectory($this->context->getConfiguration()->getTemplateDir($this->moduleName, $this->getTemplate()));
76     }
77   }
78
79   /**
80    * Renders the presentation.
81    *
82    * @return string Current template content
83    */
84   public function render()
85   {
86     if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
87     {
88       $timer = sfTimerManager::getTimer(sprintf('Partial "%s/%s"', $this->moduleName, $this->actionName));
89     }
90
91     if ($retval = $this->getCache())
92     {
93       return $retval;
94     }
95
96     if ($this->checkCache)
97     {
98       $mainResponse = $this->context->getResponse();
99
100       $responseClass = get_class($mainResponse);
101       $response = new $responseClass($this->context->getEventDispatcher(), $mainResponse->getOptions());
102
103       // the inner response has access to different properties, depending on whether it is marked as contextual in cache.yml
104       if ($this->viewCache->isContextual($this->viewCache->getPartialUri($this->moduleName, $this->actionName, $this->cacheKey)))
105       {
106         $response->copyProperties($mainResponse);
107       }
108       else
109       {
110         $response->setContentType($mainResponse->getContentType());
111       }
112
113       $this->context->setResponse($response);
114     }
115
116     try
117     {
118       // execute pre-render check
119       $this->preRenderCheck();
120
121       $this->getAttributeHolder()->set('sf_type', 'partial');
122
123       // render template
124       $retval = $this->renderFile($this->getDirectory().'/'.$this->getTemplate());
125     }
126     catch (Exception $e)
127     {
128       if ($this->checkCache)
129       {
130         $this->context->setResponse($mainResponse);
131         $mainResponse->merge($response);
132       }
133
134       throw $e;
135     }
136
137     if ($this->checkCache)
138     {
139       $retval = $this->viewCache->setPartialCache($this->moduleName, $this->actionName, $this->cacheKey, $retval);
140       $this->context->setResponse($mainResponse);
141       $mainResponse->merge($response);
142     }
143
144     if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
145     {
146       $timer->addTime();
147     }
148
149     return $retval;
150   }
151
152   public function getCache()
153   {
154     if (!$this->checkCache)
155     {
156       return null;
157     }
158
159     $this->cacheKey = $this->viewCache->checkCacheKey($this->partialVars);
160     if ($retval = $this->viewCache->getPartialCache($this->moduleName, $this->actionName, $this->cacheKey))
161     {
162       return $retval;
163     }
164   }
165 }
166
Note: See TracBrowser for help on using the browser.