123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- class sfPartialView extends sfPHPView
- {
- protected
- $partialVars = array();
-
- public function execute()
- {
- }
-
- public function setPartialVars(array $partialVars)
- {
- $this->partialVars = $partialVars;
- $this->getAttributeHolder()->add($partialVars);
- }
-
- public function configure()
- {
- $this->setDecorator(false);
- $this->setTemplate($this->actionName.$this->getExtension());
- if ('global' == $this->moduleName)
- {
- $this->setDirectory($this->context->getConfiguration()->getDecoratorDir($this->getTemplate()));
- }
- else
- {
- $this->setDirectory($this->context->getConfiguration()->getTemplateDir($this->moduleName, $this->getTemplate()));
- }
- }
-
- public function render()
- {
- if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
- {
- $timer = sfTimerManager::getTimer(sprintf('Partial "%s/%s"', $this->moduleName, $this->actionName));
- }
- if ($retval = $this->getCache())
- {
- return $retval;
- }
- else if (sfConfig::get('sf_cache'))
- {
- $mainResponse = $this->context->getResponse();
- $responseClass = get_class($mainResponse);
- $this->context->setResponse($response = new $responseClass($this->context->getEventDispatcher(), array_merge($mainResponse->getOptions(), array('content_type' => $mainResponse->getContentType()))));
- }
-
- $this->preRenderCheck();
- $this->getAttributeHolder()->set('sf_type', 'partial');
-
- $retval = $this->renderFile($this->getDirectory().'/'.$this->getTemplate());
- if (sfConfig::get('sf_cache'))
- {
- $retval = $this->viewCache->setPartialCache($this->moduleName, $this->actionName, $this->cacheKey, $retval);
- $this->context->setResponse($mainResponse);
- $mainResponse->merge($response);
- }
- if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
- {
- $timer->addTime();
- }
- return $retval;
- }
- public function getCache()
- {
- if (!sfConfig::get('sf_cache'))
- {
- return null;
- }
- $this->viewCache = $this->context->getViewCacheManager();
- $this->viewCache->registerConfiguration($this->moduleName);
- $this->cacheKey = $this->viewCache->computeCacheKey($this->partialVars);
- if ($retval = $this->viewCache->getPartialCache($this->moduleName, $this->actionName, $this->cacheKey))
- {
- return $retval;
- }
- }
- }
|