| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 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 = sfConfig::get('sf_lazy_cache_key') ? $this->viewCache->isActionCacheable($moduleName, $actionName) : true; |
|---|
| 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 |
else if ($this->checkCache) |
|---|
| 96 |
{ |
|---|
| 97 |
$mainResponse = $this->context->getResponse(); |
|---|
| 98 |
$responseClass = get_class($mainResponse); |
|---|
| 99 |
$this->context->setResponse($response = new $responseClass($this->context->getEventDispatcher(), array_merge($mainResponse->getOptions(), array('content_type' => $mainResponse->getContentType())))); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
try |
|---|
| 103 |
{ |
|---|
| 104 |
|
|---|
| 105 |
$this->preRenderCheck(); |
|---|
| 106 |
|
|---|
| 107 |
$this->getAttributeHolder()->set('sf_type', 'partial'); |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
$retval = $this->renderFile($this->getDirectory().'/'.$this->getTemplate()); |
|---|
| 111 |
} |
|---|
| 112 |
catch (Exception $e) |
|---|
| 113 |
{ |
|---|
| 114 |
if ($this->checkCache) |
|---|
| 115 |
{ |
|---|
| 116 |
$this->context->setResponse($mainResponse); |
|---|
| 117 |
$mainResponse->merge($response); |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
throw $e; |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
if ($this->checkCache) |
|---|
| 124 |
{ |
|---|
| 125 |
$retval = $this->viewCache->setPartialCache($this->moduleName, $this->actionName, $this->cacheKey, $retval); |
|---|
| 126 |
$this->context->setResponse($mainResponse); |
|---|
| 127 |
$mainResponse->merge($response); |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) |
|---|
| 131 |
{ |
|---|
| 132 |
$timer->addTime(); |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
return $retval; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
public function getCache() |
|---|
| 139 |
{ |
|---|
| 140 |
if (!$this->checkCache) |
|---|
| 141 |
{ |
|---|
| 142 |
return null; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
$this->cacheKey = $this->viewCache->checkCacheKey($this->partialVars); |
|---|
| 146 |
if ($retval = $this->viewCache->getPartialCache($this->moduleName, $this->actionName, $this->cacheKey)) |
|---|
| 147 |
{ |
|---|
| 148 |
return $retval; |
|---|
| 149 |
} |
|---|
| 150 |
} |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|