| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class sfPHPView extends sfView |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
* Executes any presentation logic for this view. |
|---|
| 25 |
*/ |
|---|
| 26 |
public function execute() |
|---|
| 27 |
{ |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
* Loads core and standard helpers to be use in the template. |
|---|
| 32 |
*/ |
|---|
| 33 |
protected function loadCoreAndStandardHelpers() |
|---|
| 34 |
{ |
|---|
| 35 |
static $coreHelpersLoaded = 0; |
|---|
| 36 |
|
|---|
| 37 |
if ($coreHelpersLoaded) |
|---|
| 38 |
{ |
|---|
| 39 |
return; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
$coreHelpersLoaded = 1; |
|---|
| 43 |
|
|---|
| 44 |
$helpers = array_unique(array_merge(array('Helper', 'Url', 'Asset', 'Tag', 'Escaping'), sfConfig::get('sf_standard_helpers'))); |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
if (!sfConfig::get('sf_compat_10') && false !== $i = array_search('Form', $helpers)) |
|---|
| 48 |
{ |
|---|
| 49 |
unset($helpers[$i]); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
$this->context->getConfiguration()->loadHelpers($helpers); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
* Renders the presentation. |
|---|
| 57 |
* |
|---|
| 58 |
* @param string $_sfFile Filename |
|---|
| 59 |
* |
|---|
| 60 |
* @return string File content |
|---|
| 61 |
*/ |
|---|
| 62 |
protected function renderFile($_sfFile) |
|---|
| 63 |
{ |
|---|
| 64 |
if (sfConfig::get('sf_logging_enabled')) |
|---|
| 65 |
{ |
|---|
| 66 |
$this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Render "%s"', $_sfFile)))); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
$this->loadCoreAndStandardHelpers(); |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
$vars = $this->attributeHolder->toArray(); |
|---|
| 73 |
extract($vars); |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
ob_start(); |
|---|
| 77 |
ob_implicit_flush(0); |
|---|
| 78 |
|
|---|
| 79 |
try |
|---|
| 80 |
{ |
|---|
| 81 |
require($_sfFile); |
|---|
| 82 |
} |
|---|
| 83 |
catch (Exception $e) |
|---|
| 84 |
{ |
|---|
| 85 |
|
|---|
| 86 |
ob_end_clean(); |
|---|
| 87 |
throw $e; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
return ob_get_clean(); |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
* Retrieves the template engine associated with this view. |
|---|
| 95 |
* |
|---|
| 96 |
* Note: This will return null because PHP itself has no engine reference. |
|---|
| 97 |
* |
|---|
| 98 |
* @return null |
|---|
| 99 |
*/ |
|---|
| 100 |
public function getEngine() |
|---|
| 101 |
{ |
|---|
| 102 |
return null; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
* Configures template. |
|---|
| 107 |
* |
|---|
| 108 |
* @return void |
|---|
| 109 |
*/ |
|---|
| 110 |
public function configure() |
|---|
| 111 |
{ |
|---|
| 112 |
|
|---|
| 113 |
$this->context->set('view_instance', $this); |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
require($this->context->getConfigCache()->checkConfig('modules/'.$this->moduleName.'/config/view.yml')); |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
if (!$this->directory) |
|---|
| 120 |
{ |
|---|
| 121 |
$this->setDirectory($this->context->getConfiguration()->getTemplateDir($this->moduleName, $this->getTemplate())); |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
* Loop through all template slots and fill them in with the results of presentation data. |
|---|
| 127 |
* |
|---|
| 128 |
* @param string $content A chunk of decorator content |
|---|
| 129 |
* |
|---|
| 130 |
* @return string A decorated template |
|---|
| 131 |
*/ |
|---|
| 132 |
protected function decorate($content) |
|---|
| 133 |
{ |
|---|
| 134 |
if (sfConfig::get('sf_logging_enabled')) |
|---|
| 135 |
{ |
|---|
| 136 |
$this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Decorate content with "%s/%s"', $this->getDecoratorDirectory(), $this->getDecoratorTemplate())))); |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
$attributeHolder = $this->attributeHolder; |
|---|
| 141 |
|
|---|
| 142 |
$this->attributeHolder = $this->initializeAttributeHolder(array('sf_content' => new sfOutputEscaperSafe($content))); |
|---|
| 143 |
$this->attributeHolder->set('sf_type', 'layout'); |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
$ret = $this->renderFile($this->getDecoratorDirectory().'/'.$this->getDecoratorTemplate()); |
|---|
| 147 |
|
|---|
| 148 |
$this->attributeHolder = $attributeHolder; |
|---|
| 149 |
|
|---|
| 150 |
return $ret; |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
* Renders the presentation. |
|---|
| 155 |
* |
|---|
| 156 |
* @return string A string representing the rendered presentation |
|---|
| 157 |
*/ |
|---|
| 158 |
public function render() |
|---|
| 159 |
{ |
|---|
| 160 |
$content = null; |
|---|
| 161 |
if (sfConfig::get('sf_cache')) |
|---|
| 162 |
{ |
|---|
| 163 |
$viewCache = $this->context->getViewCacheManager(); |
|---|
| 164 |
$uri = $this->context->getRouting()->getCurrentInternalUri(); |
|---|
| 165 |
|
|---|
| 166 |
if (!is_null($uri)) |
|---|
| 167 |
{ |
|---|
| 168 |
list($content, $decoratorTemplate) = $viewCache->getActionCache($uri); |
|---|
| 169 |
if (!is_null($content)) |
|---|
| 170 |
{ |
|---|
| 171 |
$this->setDecoratorTemplate($decoratorTemplate); |
|---|
| 172 |
} |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
if (is_null($content)) |
|---|
| 178 |
{ |
|---|
| 179 |
|
|---|
| 180 |
$this->preRenderCheck(); |
|---|
| 181 |
|
|---|
| 182 |
$this->attributeHolder->set('sf_type', 'action'); |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
$content = $this->renderFile($this->getDirectory().'/'.$this->getTemplate()); |
|---|
| 186 |
|
|---|
| 187 |
if (sfConfig::get('sf_cache') && !is_null($uri)) |
|---|
| 188 |
{ |
|---|
| 189 |
$content = $viewCache->setActionCache($uri, $content, $this->isDecorator() ? $this->getDecoratorDirectory().'/'.$this->getDecoratorTemplate() : false); |
|---|
| 190 |
} |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
if ($this->isDecorator()) |
|---|
| 195 |
{ |
|---|
| 196 |
$content = $this->decorate($content); |
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
return $content; |
|---|
| 200 |
} |
|---|
| 201 |
} |
|---|
| 202 |
|
|---|