Changeset 1300
- Timestamp:
- 05/03/06 09:03:12 (3 years ago)
- Files:
-
- trunk/lib/action/sfAction.class.php (modified) (1 diff)
- trunk/lib/config/sfCacheConfigHandler.class.php (modified) (4 diffs)
- trunk/lib/controller/sfController.class.php (modified) (1 diff)
- trunk/lib/debug/sfWebDebug.class.php (modified) (2 diffs)
- trunk/lib/filter/sfCacheFilter.class.php (modified) (8 diffs)
- trunk/lib/helper/PartialHelper.php (modified) (5 diffs)
- trunk/lib/request/sfWebRequest.class.php (modified) (1 diff)
- trunk/lib/response/sfWebResponse.class.php (modified) (1 diff)
- trunk/lib/view/sfPHPView.class.php (modified) (13 diffs)
- trunk/lib/view/sfView.class.php (modified) (5 diffs)
- trunk/lib/view/sfViewCacheManager.class.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/action/sfAction.class.php
r1292 r1300 101 101 } 102 102 103 // ignore cache? (only in debug mode)104 if (sfConfig::get('sf_debug') && $this->request->getParameter('ignore_cache', false, 'symfony/request/sfWebRequest') == true)105 {106 return 1;107 }108 109 103 $cache = $this->getContext()->getViewCacheManager(); 110 104 trunk/lib/config/sfCacheConfigHandler.class.php
r1044 r1300 64 64 "{\n"; 65 65 66 if ($this->getConfigValue('activate', $actionName)) 67 { 68 $data[] = $this->addCache($actionName); 69 } 66 $data[] = $this->addCache($actionName); 70 67 71 68 $data[] = "}\n"; … … 75 72 76 73 // general cache configuration 77 if ($this->getConfigValue('activate', $actionName)) 78 { 79 $data[] = ($first ? '' : "else\n{")."\n"; 80 $data[] = $this->addCache('DEFAULT'); 81 $data[] = ($first ? '' : "}")."\n"; 82 } 74 $data[] = ($first ? '' : "else\n{")."\n"; 75 $data[] = $this->addCache('DEFAULT'); 76 $data[] = ($first ? '' : "}")."\n"; 83 77 84 78 // compile data … … 95 89 $data = array(); 96 90 91 // activated? 92 $activate = $this->getConfigValue('activate', $actionName); 93 97 94 // cache type for this action (slot or page) 98 95 $type = $this->getConfigValue('type', $actionName); 99 96 100 97 // lifetime 101 $lifeTime = $this->getConfigValue('lifetime', $actionName);98 $lifeTime = (!$activate) ? 0 : $this->getConfigValue('lifetime', $actionName); 102 99 103 100 // client_lifetime 104 $clientLifetime = $this->getConfigValue('client_lifetime', $actionName, $lifeTime);101 $clientLifetime = (!$activate) ? 0 : $this->getConfigValue('client_lifetime', $actionName, $lifeTime); 105 102 106 103 // vary … … 112 109 113 110 // add cache information to cache manager 114 $data[] = sprintf(" \$ this->cacheManager->addCache(\$context->getModuleName(), '%s', '%s', %s, '%s', %s);\n\n",111 $data[] = sprintf(" \$cacheManager->addCache(\$context->getModuleName(), '%s', '%s', %s, '%s', %s);\n\n", 115 112 $actionName, $type, $lifeTime, $clientLifetime, var_export($vary, true)); 116 113 trunk/lib/controller/sfController.class.php
r1295 r1300 466 466 $class = $moduleClass; 467 467 } 468 469 return new $class(); 470 } 471 472 // view class (as configured in module.yml or defined in action) 473 $viewName = $this->getContext()->getRequest()->getAttribute($moduleName.'_'.$actionName.'_view_name', '', 'symfony/action/view') ? $this->getContext()->getRequest()->getAttribute($moduleName.'_'.$actionName.'_view_name', '', 'symfony/action/view') : sfConfig::get('mod_'.strtolower($moduleName).'_view_class'); 474 $file = sfConfig::get('sf_symfony_lib_dir').'/view/'.$viewName.'View.class.php'; 475 if (is_readable($file)) 476 { 477 $class = $viewName.'View'; 478 479 return new $class(); 480 } 481 482 $class = 'sfPHPView'; 468 } 469 else 470 { 471 // view class (as configured in module.yml or defined in action) 472 $viewName = $this->getContext()->getRequest()->getAttribute($moduleName.'_'.$actionName.'_view_name', '', 'symfony/action/view') ? $this->getContext()->getRequest()->getAttribute($moduleName.'_'.$actionName.'_view_name', '', 'symfony/action/view') : sfConfig::get('mod_'.strtolower($moduleName).'_view_class'); 473 $file = sfConfig::get('sf_symfony_lib_dir').'/view/'.$viewName.'View.class.php'; 474 $class = is_readable($file) ? $viewName.'View' : 'sfPHPView'; 475 } 483 476 484 477 return new $class(); trunk/lib/debug/sfWebDebug.class.php
r1296 r1300 376 376 } 377 377 378 public function decorateContentWithDebug($internalUri, $suffix, $retval, $ border_color, $bg_color)378 public function decorateContentWithDebug($internalUri, $suffix, $retval, $new = false) 379 379 { 380 380 if (!sfConfig::get('sf_web_debug')) … … 382 382 return $retval; 383 383 } 384 385 $border_color = $new ? '#f00' : '#f00'; 386 $bg_color = $new ? '#9ff' : '#ff9'; 384 387 385 388 $cache = $this->context->getViewCacheManager(); trunk/lib/filter/sfCacheFilter.class.php
r1279 r1300 57 57 if (is_readable(sfConfig::get('sf_app_module_dir').'/'.$cacheConfigFile)) 58 58 { 59 $actionName = $context->getActionName(); 59 $actionName = $context->getActionName(); 60 $cacheManager = $this->cacheManager; 60 61 require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$cacheConfigFile)); 61 62 } … … 64 65 list($uri, $suffix) = $this->cacheManager->getInternalUri('page'); 65 66 $this->toSave[$uri.'_'.$suffix] = false; 66 if ($this->cacheManager-> hasCacheConfig($uri, $suffix))67 if ($this->cacheManager->isCacheable($uri, $suffix)) 67 68 { 68 69 $inCache = $this->getPageCache($uri, $suffix); … … 79 80 list($uri, $suffix) = $this->cacheManager->getInternalUri('slot'); 80 81 $this->toSave[$uri.'_'.$suffix] = false; 81 if ($this->cacheManager-> hasCacheConfig($uri, $suffix))82 if ($this->cacheManager->isCacheable($uri, $suffix)) 82 83 { 83 84 $inCache = $this->getActionCache($uri, $suffix); … … 130 131 131 132 $this->setPageCache($uri, $suffix); 133 134 if (sfConfig::get('sf_web_debug')) 135 { 136 $content = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $suffix, $this->response->getContent(), true); 137 $this->response->setContent($content); 138 } 132 139 } 133 140 … … 157 164 $this->cacheManager->set(serialize($this->response), $uri, $suffix); 158 165 159 if (sfConfig::get('sf_web_debug'))160 {161 $content = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $suffix, $this->response->getContent(), '#f00', '#9ff');162 $this->response->setContent($content);163 }164 165 166 if (sfConfig::get('sf_logging_active')) 166 167 { … … 172 173 { 173 174 $context = $this->getContext(); 174 175 // ignore cache?176 if (sfConfig::get('sf_debug') && $this->request->getParameter('ignore_cache', false, 'symfony/request/sfWebRequest') == true)177 {178 if (sfConfig::get('sf_logging_active'))179 {180 $context->getLogger()->info('{sfCacheFilter} discard page cache for "'.$uri.' - '.$suffix.'"');181 }182 183 return false;184 }185 175 186 176 // get the current action information … … 195 185 } 196 186 197 if ($retval !== null)198 { 199 $cachedResponse = unserialize($retval);200 $cachedResponse->setContext($context);201 202 $controller = $context->getController();203 if ($controller->getRenderMode() == sfView::RENDER_VAR)204 { 205 $controller->getActionStack()->getLastEntry()->setPresentation($cachedResponse->getContent());206 $this->response->setContent('');207 }208 else209 {210 $context->setResponse($cachedResponse);211 212 if (sfConfig::get('sf_web_debug'))213 {214 $content = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $suffix, $cachedResponse->getContent(), '#f00', '#ff9'); 215 $this->response->setContent($content);216 }217 }218 219 return true;220 } 221 222 return false;187 if ($retval === null) 188 { 189 return false; 190 } 191 192 $cachedResponse = unserialize($retval); 193 $cachedResponse->setContext($context); 194 195 $controller = $context->getController(); 196 if ($controller->getRenderMode() == sfView::RENDER_VAR) 197 { 198 $controller->getActionStack()->getLastEntry()->setPresentation($cachedResponse->getContent()); 199 $this->response->setContent(''); 200 } 201 else 202 { 203 $context->setResponse($cachedResponse); 204 205 if (sfConfig::get('sf_web_debug')) 206 { 207 $content = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $suffix, $cachedResponse->getContent(), false); 208 $context->getResponse()->setContent($content); 209 } 210 } 211 212 return true; 223 213 } 224 214 … … 226 216 { 227 217 $content = $this->response->getParameter($uri.'_'.$suffix, null, 'symfony/cache'); 228 $this->cacheManager->set($content, $uri, $suffix); 218 219 if ($content !== null) 220 { 221 $cached = $this->cacheManager->set($content, $uri, $suffix); 222 } 223 224 if (sfConfig::get('sf_logging_active') && $cached) 225 { 226 $this->getContext()->getLogger()->info('{sfCacheFilter} save slot "'.$uri.' - '.$suffix.'" in cache'); 227 } 228 } 229 230 private function getActionCache($uri, $suffix) 231 { 232 // retrieve content from cache 233 $retval = $this->cacheManager->get($uri, $suffix); 234 235 if (sfConfig::get('sf_web_debug') && $retval) 236 { 237 $tmp = unserialize($retval); 238 $tmp['content'] = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $suffix, $tmp['content'], false); 239 $retval = serialize($tmp); 240 } 241 242 $this->response->setParameter('current_key', $uri.'_'.$suffix, 'symfony/cache/current'); 243 $this->response->setParameter($uri.'_'.$suffix, $retval, 'symfony/cache'); 229 244 230 245 if (sfConfig::get('sf_logging_active')) 231 246 { 232 $this->getContext()->getLogger()->info('{sfCacheFilter} save slot "'.$uri.' - '.$suffix.'" in cache'); 233 } 234 } 235 236 private function getActionCache($uri, $suffix) 237 { 238 // ignore cache parameter? (only available in debug mode) 239 if (sfConfig::get('sf_debug') && $this->request->getParameter('ignore_cache', false, 'symfony/request/sfWebRequest') == true) 240 { 241 if (sfConfig::get('sf_logging_active')) 242 { 243 $this->getContext()->getLogger()->info('{sfCacheFilter} discard cache for "'.$uri.'" / '.$suffix.''); 244 } 245 } 246 else 247 { 248 // retrieve content from cache 249 $retval = $this->cacheManager->get($uri, $suffix); 250 251 if ($retval) 252 { 253 $this->response->setParameter($uri.'_'.$suffix, $retval, 'symfony/cache'); 254 } 255 256 if (sfConfig::get('sf_logging_active')) 257 { 258 $this->getContext()->getLogger()->info('{sfCacheFilter} cache for "'.$uri.' - '.$suffix.'" '.($retval !== null ? 'exists' : 'does not exist')); 259 } 260 261 return ($retval ? true : false); 262 } 263 264 return false; 247 $this->getContext()->getLogger()->info('{sfCacheFilter} cache for "'.$uri.' - '.$suffix.'" '.($retval !== null ? 'exists' : 'does not exist')); 248 } 249 250 return ($retval ? true : false); 265 251 } 266 252 } trunk/lib/helper/PartialHelper.php
r1132 r1300 18 18 */ 19 19 20 function include_component_slot($name) 20 function include_component_slot($name, $vars = array()) 21 { 22 echo get_component_slot($name, $vars); 23 } 24 25 function get_component_slot($name, $vars = array()) 21 26 { 22 27 $context = sfContext::getInstance(); … … 36 41 if ($componentSlot = $viewInstance->getComponentSlot($name)) 37 42 { 38 include_component($componentSlot[0], $componentSlot[1]);43 return get_component($componentSlot[0], $componentSlot[1], $vars); 39 44 } 40 45 } … … 42 47 function include_component($moduleName, $componentName, $vars = array()) 43 48 { 44 $context = sfContext::getInstance(); 49 echo get_component($moduleName, $componentName, $vars); 50 } 51 52 function get_component($moduleName, $componentName, $vars = array()) 53 { 54 $context = sfContext::getInstance(); 55 $cacheManager = $context->getViewCacheManager(); 56 57 if (sfConfig::get('sf_cache')) 58 { 59 $actionName = '_'.$componentName; 60 $cacheKey = md5(serialize($vars)); 61 $uri = $moduleName.'/'.$actionName.'?key='.$cacheKey; 62 63 // register our cache configuration 64 $cacheConfigFile = $moduleName.'/'.sfConfig::get('sf_app_module_config_dir_name').'/cache.yml'; 65 if (is_readable(sfConfig::get('sf_app_module_dir').'/'.$cacheConfigFile)) 66 { 67 require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$cacheConfigFile)); 68 } 69 70 $retval = $cacheManager->get($uri, 'slot'); 71 72 if (sfConfig::get('sf_logging_active') && $cacheManager->isCacheable($uri, 'slot')) 73 { 74 $context->getLogger()->info(sprintf('{PartialHelper} cache for "%s" %s', $uri, ($retval !== null ? 'exists' : 'does not exist'))); 75 } 76 77 if ($retval !== null) 78 { 79 if (sfConfig::get('sf_web_debug')) 80 { 81 $retval = sfWebDebug::getInstance()->decorateContentWithDebug($uri, 'slot', $retval, false); 82 } 83 84 return $retval; 85 } 86 } 87 45 88 $controller = $context->getController(); 46 89 … … 58 101 59 102 // initialize the action 60 if ($componentInstance->initialize($context)) 61 { 62 $componentInstance->getVarHolder()->add($vars); 63 64 // dispatch component 65 $componentToRun = 'execute'.ucfirst($componentName); 66 if (!method_exists($componentInstance, $componentToRun)) 67 { 68 if (method_exists($componentInstance, 'execute')) 69 { 70 $componentToRun = 'execute'; 71 } 72 else 73 { 74 // component not found 75 $error = 'sfComponent initialization failed for module "%s", component "%s"'; 76 $error = sprintf($error, $moduleName, $componentName); 77 throw new sfInitializationException($error); 78 } 79 } 80 81 if (sfConfig::get('sf_logging_active')) $context->getLogger()->info('{sfComponent} call "'.$moduleName.'->'.$componentToRun.'()'.'"'); 82 83 // run component 84 $retval = $componentInstance->$componentToRun(); 85 86 if ($retval != sfView::NONE) 87 { 88 // get component vars 89 $componentVars = $componentInstance->getVarHolder()->getAll(); 90 91 // include partial 92 include_partial($moduleName.'/'.$componentName, $componentVars); 93 } 94 } 95 else 103 if (!$componentInstance->initialize($context)) 96 104 { 97 105 // component failed to initialize … … 101 109 throw new sfInitializationException($error); 102 110 } 103 } 104 105 function include_partial($name, $vars = array()) 106 { 111 112 $componentInstance->getVarHolder()->add($vars); 113 114 // dispatch component 115 $componentToRun = 'execute'.ucfirst($componentName); 116 if (!method_exists($componentInstance, $componentToRun)) 117 { 118 if (!method_exists($componentInstance, 'execute')) 119 { 120 // component not found 121 $error = 'sfComponent initialization failed for module "%s", component "%s"'; 122 $error = sprintf($error, $moduleName, $componentName); 123 throw new sfInitializationException($error); 124 } 125 126 $componentToRun = 'execute'; 127 } 128 129 if (sfConfig::get('sf_logging_active')) $context->getLogger()->info('{PartialHelper} call "'.$moduleName.'->'.$componentToRun.'()'.'"'); 130 131 // run component 132 $retval = $componentInstance->$componentToRun(); 133 134 if ($retval != sfView::NONE) 135 { 136 // get component vars 137 $componentVars = $componentInstance->getVarHolder()->getAll(); 138 139 // include partial 140 return get_partial($moduleName.'/'.$componentName, $componentVars); 141 } 142 } 143 144 function include_partial($templateName, $vars = array()) 145 { 146 echo get_partial($templateName, $vars); 147 } 148 149 function get_partial($templateName, $vars = array()) 150 { 151 $context = sfContext::getInstance(); 152 $cacheManager = $context->getViewCacheManager(); 153 107 154 // partial is in another module? 108 $sep = strpos($ name, '/');155 $sep = strpos($templateName, '/'); 109 156 if ($sep) 110 157 { 111 $ type = substr($name, 0, $sep);112 $ filename = '_'.substr($name, $sep + 1).'.php';158 $moduleName = substr($templateName, 0, $sep); 159 $templateName = substr($templateName, $sep + 1); 113 160 } 114 161 else 115 162 { 116 $type = ''; 117 $filename = '_'.$name.'.php'; 118 } 119 120 $context = sfContext::getInstance(); 121 122 $lastActionEntry = $context->getActionStack()->getLastEntry(); 123 $firstActionEntry = $context->getActionStack()->getFirstEntry(); 124 125 // global variables 126 $vars['sf_context'] = $context; 127 $vars['sf_params'] = $context->getRequest()->getParameterHolder(); 128 $vars['sf_request'] = $context->getRequest(); 129 $vars['sf_user'] = $context->getUser(); 130 $vars['sf_last_module'] = $lastActionEntry->getModuleName(); 131 $vars['sf_last_action'] = $lastActionEntry->getActionName(); 132 $vars['sf_first_module'] = $firstActionEntry->getModuleName(); 133 $vars['sf_first_action'] = $firstActionEntry->getActionName(); 134 135 if (sfConfig::get('sf_use_flash')) 136 { 137 $sf_flash = new sfParameterHolder(); 138 $sf_flash->add($context->getUser()->getAttributeHolder()->getAll('symfony/flash')); 139 $vars['sf_flash'] = $sf_flash; 140 } 141 142 // local action variables 143 $action = $context->getActionStack()->getLastEntry()->getActionInstance(); 144 if (method_exists($action, 'getVars')) 145 { 146 $vars = array_merge($vars, $action->getVars()); 147 } 148 149 // render to client 150 if ($sep && $type == 'global') 151 { 152 $partial = sfConfig::get('sf_app_template_dir').DIRECTORY_SEPARATOR.$filename; 153 } 154 else if ($sep) 155 { 156 $partial = sfConfig::get('sf_app_module_dir').DIRECTORY_SEPARATOR.$type.DIRECTORY_SEPARATOR.sfConfig::get('sf_app_module_template_dir_name').DIRECTORY_SEPARATOR.$filename; 157 } 158 else 159 { 160 $current_module = sfContext::getInstance()->getActionStack()->getLastEntry()->getModuleName(); 161 $partial = sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.sfConfig::get('sf_app_module_dir_name').DIRECTORY_SEPARATOR.$current_module.DIRECTORY_SEPARATOR.sfConfig::get('sf_app_module_template_dir_name').DIRECTORY_SEPARATOR.$filename; 162 } 163 164 if (!is_readable($partial)) 165 { 166 $ok = false; 167 168 $current_module = sfContext::getInstance()->getActionStack()->getLastEntry()->getModuleName(); 169 170 // search partial for generated templates in cache 171 $partial = sfConfig::get('sf_module_cache_dir').'/auto'.ucfirst($current_module).'/templates/'.$filename; 172 if (is_readable($partial)) 173 { 174 $ok = true; 175 } 176 else 177 { 178 // search partial in a symfony module directory 179 $partial = sfConfig::get('sf_symfony_data_dir').'/modules/'.$current_module.'/templates/'.$filename; 180 if (is_readable($partial)) 163 $moduleName = $context->getActionStack()->getLastEntry()->getModuleName(); 164 } 165 $actionName = '_'.$templateName; 166 167 if (sfConfig::get('sf_cache')) 168 { 169 $cacheKey = md5(serialize($vars)); 170 $uri = $moduleName.'/'.$actionName.'?key='.$cacheKey; 171 172 // register our cache configuration 173 $cacheConfigFile = $moduleName.'/'.sfConfig::get('sf_app_module_config_dir_name').'/cache.yml'; 174 if (is_readable(sfConfig::get('sf_app_module_dir').'/'.$cacheConfigFile)) 175 { 176 require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$cacheConfigFile)); 177 } 178 179 $retval = $cacheManager->get($uri, 'slot'); 180 181 if (sfConfig::get('sf_logging_active') && $cacheManager->isCacheable($uri, 'slot')) 182 { 183 $context->getLogger()->info(sprintf('{PartialHelper} cache for "%s" %s', $uri, ($retval !== null ? 'exists' : 'does not exist'))); 184 } 185 186 if ($retval !== null) 187 { 188 if (sfConfig::get('sf_web_debug')) 181 189 { 182 $ ok = true;190 $retval = sfWebDebug::getInstance()->decorateContentWithDebug($uri, 'slot', $retval, false); 183 191 } 184 } 185 186 if (!$ok) 187 { 188 // the partial isn't readable 189 $error = sprintf('The partial "%s" does not exist or is unreadable', $filename); 190 throw new sfRenderException($error); 191 } 192 } 193 194 extract($vars); 195 require $partial; 192 193 return $retval; 194 } 195 } 196 197 $viewType = ($moduleName == 'global') ? sfView::GLOBAL_PARTIAL : sfView::PARTIAL; 198 199 $controller = $context->getController(); 200 201 // get original render mode 202 $renderMode = $controller->getRenderMode(); 203 204 // set render mode to var 205 $controller->setRenderMode(sfView::RENDER_VAR); 206 207 // get the view instance 208 $viewName = $templateName.$viewType; 209 $viewInstance = $controller->getView($moduleName, $actionName, $viewName); 210 211 // initialize the view 212 if (!$viewInstance->initialize($context, $moduleName, $viewName)) 213 { 214 // view failed to initialize 215 $error = 'View initialization failed for module "%s", view "%sView"'; 216 $error = sprintf($error, $moduleName, $viewName); 217 218 throw new sfInitializationException($error); 219 } 220 221 // view initialization completed successfully 222 $viewInstance->execute(); 223 224 // no decorator 225 $viewInstance->setDecorator(false); 226 227 // render the partial template 228 $retval = $viewInstance->render($vars); 229 230 // put render mode back 231 $controller->setRenderMode($renderMode); 232 233 if (sfConfig::get('sf_cache')) 234 { 235 if ($retval !== null) 236 { 237 $saved = $cacheManager->set($retval, $uri, 'slot'); 238 239 if (sfConfig::get('sf_web_debug') && $saved) 240 { 241 $retval = sfWebDebug::getInstance()->decorateContentWithDebug($uri, 'slot', $retval, true); 242 } 243 } 244 245 if (sfConfig::get('sf_logging_active') && $saved) 246 { 247 $context->getLogger()->info(sprintf('{PartialHelper} save slot "%s - %s" in cache', $uri, $cacheKey)); 248 } 249 } 250 251 return $retval; 196 252 } 197 253 trunk/lib/request/sfWebRequest.class.php
r1291 r1300 419 419 $this->getParameterHolder()->addByRef($_POST); 420 420 421 // move symfony parameters in a protected namespace (parameters prefixed with sf_) 422 foreach ($this->getParameterHolder()->getAll() as $key => $value) 423 { 424 if (stripos($key, 'sf_') !== false) 425 { 426 $this->getParameterHolder()->remove($key); 427 $this->setParameter($key, $value, 'symfony/request/sfWebRequest'); 428 unset($_GET[$key]); 429 } 430 } 431 421 432 if (sfConfig::get('sf_logging_active')) 422 433 { 423 $parameters = ''; 424 foreach ($this->getParameterHolder()->getAll() as $key => $value) 425 { 426 $parameters .= $key.' => "'.$value.'", '; 427 } 428 429 $this->getContext()->getLogger()->info('{sfWebRequest} request parameters { '.$parameters.'}'); 430 } 431 432 // move some parameters in other namespaces 433 $special_parameters = array( 434 'ignore_cache' => 'symfony/request/sfWebRequest', 435 ); 436 foreach ($special_parameters as $param => $namespace) 437 { 438 if ($this->hasParameter($param)) 439 { 440 $value = $this->getParameterHolder()->remove($param); 441 $this->setParameter($param, $value, $namespace); 442 } 434 $this->getContext()->getLogger()->info(sprintf('{sfWebRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))); 443 435 } 444 436 } trunk/lib/response/sfWebResponse.class.php
r1249 r1300 445 445 } 446 446 447 public function mergeProperties($response) 448 { 449 // add stylesheets 450 foreach (array('first', '', 'last') as $position) 451 { 452 $this->getParameterHolder()->add($response->getStylesheets($position), 'helper/asset/auto/stylesheet'.$position); 453 } 454 455 // add javascripts 456 foreach (array('first', '', 'last') as $position) 457 { 458 $this->getParameterHolder()->add($response->getJavascripts($position), 'helper/asset/auto/javascript'.$position); 459 } 460 461 // add headers 462 foreach ($response->getHttpHeaders() as $name => $values) 463 { 464 foreach ($values as $value) 465 { 466 $this->setHttpHeader($name, $value); 467 } 468 } 469 } 470 447 471 /** 448 472 * Execute the shutdown procedure. trunk/lib/view/sfPHPView.class.php
r1197 r1300 20 20 class sfPHPView extends sfView 21 21 { 22 protected static23 $coreHelpersLoaded = 0;24 25 22 public function execute() 26 23 { … … 28 25 29 26 /** 30 * Assigns some common variablesto the template.27 * Returns an array with some variables that will be accessible to the template. 31 28 */ 32 29 protected function getGlobalVars() … … 61 58 protected function loadCoreAndStandardHelpers() 62 59 { 63 if (self::$coreHelpersLoaded) 60 static $coreHelpersLoaded = 0; 61 62 if ($coreHelpersLoaded) 64 63 { 65 64 return; 66 65 } 67 66 68 self::$coreHelpersLoaded = 1;67 $coreHelpersLoaded = 1; 69 68 70 69 $core_helpers = array('Helper', 'Url', 'Asset', 'Tag', 'Escaping'); … … 154 153 155 154 // store our current view 156 $actionStackEntry->setViewInstance($this); 155 if (!$actionStackEntry->getViewInstance()) 156 { 157 $actionStackEntry->setViewInstance($this); 158 } 159 160 // all directories to look for templates 161 $dirs = array( 162 // application 163 $this->getDirectory(), 164 165 // local plugin 166 sfConfig::get('sf_plugin_data_dir').'/modules/'.$this->moduleName.'/templates', 167 168 // core modules or global plugins 169 sfConfig::get('sf_symfony_data_dir').'/modules/'.$this->moduleName.'/templates', 170 171 // generated templates in cache 172 sfConfig::get('sf_module_cache_dir').'/auto'.ucfirst($this->moduleName).'/templates', 173 ); 157 174 158 175 // require our configuration … … 160 177 require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$viewConfigFile)); 161 178 162 $viewType = sfView::SUCCESS; 163 if (preg_match('/^'.$action->getActionName().'(.+)$/i', $this->viewName, $match)) 164 { 165 $viewType = $match[1]; 166 $templateFile = $templateName.$viewType.$this->extension; 179 if (preg_match('/^(.+?)'.sfView::GLOBAL_PARTIAL.'$/i', $this->viewName, $match)) 180 { 181 // global partial 182 $templateFile = '_'.$match[1].$this->extension; 183 $dirs = array(sfConfig::get('sf_app_template_dir')); 184 } 185 else if (preg_match('/^(.+?)'.sfView::PARTIAL.'$/i', $this->viewName, $match)) 186 { 187 // partial 188 $templateFile = '_'.$match[1].$this->extension; 189 } 190 else if (preg_match('/^'.$action->getActionName().'(.+)$/i', $this->viewName, $match)) 191 { 192 $templateFile = $templateName.$match[1].$this->extension; 167 193 } 168 194 else … … 175 201 176 202 // set template directory 177 178 // all directories to look for templates179 $moduleName = $context->getModuleName();180 $dirs = array(181 // application182 $this->getDirectory(),183 184 // local plugin185 sfConfig::get('sf_plugin_data_dir').'/modules/'.$moduleName.'/templates',186 187 // core modules or global plugins188 sfConfig::get('sf_symfony_data_dir').'/modules/'.$moduleName.'/templates',189 190 // generated templates in cache191 sfConfig::get('sf_module_cache_dir').'/auto'.ucfirst($moduleName).'/templates',192 );193 194 203 foreach ($dirs as $dir) 195 204 { … … 204 213 if (sfConfig::get('sf_logging_active')) 205 214 { 206 $context->getLogger()->info( '{sfPHPView} execute view for template "'.$templateName.$viewType.$this->extension.'"');215 $context->getLogger()->info(sprintf('{sfPHPView} execute view for template "%s"', $templateFile)); 207 216 } 208 217 } … … 243 252 * the controller render mode is sfView::RENDER_VAR, otherwise null. 244 253 */ 245 public function &render() 246 { 247 $template = $this->getDirectory().'/'.$this->getTemplate(); 248 $actionStackEntry = $this->getContext()->getActionStack()->getLastEntry(); 249 $actionInstance = $actionStackEntry->getActionInstance(); 250 251 $moduleName = $actionInstance->getModuleName(); 252 $actionName = $actionInstance->getActionName(); 253 254 public function &render($templateVars = null) 255 { 254 256 $retval = null; 255 257 258 $context = $this->getContext(); 259 256 260 // get the render mode 257 $mode = $ this->getContext()->getController()->getRenderMode();261 $mode = $context->getController()->getRenderMode(); 258 262 259 263 if ($mode != sfView::RENDER_NONE) … … 262 266 if (sfConfig::get('sf_cache')) 263 267 { 264 list($uri, $suffix) = $this->getContext()->getViewCacheManager()->getInternalUri('slot'); 265 $cache = $this->getContext()->getResponse()->getParameter($uri.'_'.$suffix, null, 'symfony/cache'); 268 $response = $context->getResponse(); 269 $key = $response->getParameterHolder()->remove('current_key', 'symfony/cache/current'); 270 $cache = $response->getParameter($key, null, 'symfony/cache'); 266 271 if ($cache !== null) 267 272 { … … 269 274 $retval = $cache['content']; 270 275 $vars = $cache['vars']; 276 $response->mergeProperties($cache['response']); 271 277 } 278 } 279 280 // template variables 281 if ($templateVars === null) 282 { 283 $actionStackEntry = $context->getActionStack()->getLastEntry(); 284 $actionInstance = $actionStackEntry->getActionInstance(); 285 $templateVars = $actionInstance->getVarHolder()->getAll(); 272 286 } 273 287 274 288 // assigns some variables to the template 275 289 $this->attribute_holder->add($this->getGlobalVars()); 276 $this->attribute_holder->add($retval !== null ? $vars : $ actionInstance->getVarHolder()->getAll());290 $this->attribute_holder->add($retval !== null ? $vars : $templateVars); 277 291 278 292 // render template if no cache … … 283 297 284 298 // render template file 299 $template = $this->getDirectory().'/'.$this->getTemplate(); 285 300 $retval = $this->renderFile($template); 286 301 … … 291 306 } 292 307 293 if (sfConfig::get('sf_cache') )308 if (sfConfig::get('sf_cache') && $key !== null) 294 309 { 295 310 $cache = array( 296 311 'content' => $retval, 297 'vars' => $ actionInstance->getVarHolder()->getAll(),312 'vars' => $templateVars, 298 313 'view_name' => $this->viewName, 314 'response' => $context->getResponse(), 299 315 ); 300 $this->getContext()->getResponse()->setParameter($uri.'_'.$suffix, serialize($cache), 'symfony/cache'); 316 $response->setParameter($key, serialize($cache), 'symfony/cache'); 317 318 if (sfConfig::get('sf_web_debug')) 319 { 320 $retval = sfWebDebug::getInstance()->decorateContentWithDebug($key, '', $retval, true); 321 } 301 322 } 302 323 } … … 311 332 if ($mode == sfView::RENDER_CLIENT) 312 333 { 313 $ this->getContext()->getResponse()->setContent($retval);334 $context->getResponse()->setContent($retval); 314 335 } 315 336 } trunk/lib/view/sfView.class.php
r1289 r1300 55 55 56 56 /** 57 * Render a partial template. 58 */ 59 const PARTIAL = 'Partial'; 60 61 /** 62 * Render a global partial template. 63 */ 64 const GLOBAL_PARTIAL = 'GlobalPartial'; 65 66 /** 57 67 * Render the presentation to the client. 58 68 */ … … 352 362 { 353 363 if ($request->hasError($name)) 364 { 354 365 $this->setAttribute($name.'_error', $request->getError($name)); 366 } 355 367 else 356 368 { … … 383 395 384 396 // set the currently executing module's template directory as the default template directory 385 $module = $context->getModuleName(); 386 387 $this->decoratorDirectory = sfConfig::get('sf_app_module_dir').'/'.$module.'/'.sfConfig::get('sf_app_module_template_dir_name'); 397 $this->decoratorDirectory = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/'.sfConfig::get('sf_app_module_template_dir_name'); 388 398 $this->directory = $this->decoratorDirectory; 389 399 … … 442 452 { 443 453 return $this->decorator; 454 } 455 456 public function setDecorator ($boolean) 457 { 458 $this->decorator = (boolean) $boolean; 444 459 } 445 460 … … 495 510 * render the presentation directly to the client and null will be returned. 496 511 * 512 * @param array An array with variables that will be extracted for the template 513 * If empty, the current actions var holder will be extracted. 497 514 * @return string A string representing the rendered presentation, if 498 * the controller render mode is sfView::RENDER_VAR, otherwise 499 * null. 500 */ 501 abstract function & render (); 515 * the controller render mode is sfView::RENDER_VAR, otherwise null. 516 */ 517 abstract function & render ($templateVars = null); 502 518 503 519 /** trunk/lib/view/sfViewCacheManager.class.php
r1024 r1300 10 10 11 11 /** 12 * Cache class to cache the HTML results for Actions and Templates.12 * Cache class to cache the HTML results for actions and templates. 13 13 * 14 * This class is based on the PEAR_Cache_Liste class.14 * This class users viewCacheClassName to serialize cache. 15 15 * All cache files are stored in files in the [sf_root_dir].'/cache/'.[sf_app].'/html' directory. 16 16 * To disable all caching, you can set to false [sf_cache] constant. … … 126 126 // we add cache information based on slot configuration for this module/action 127 127 $lifeTime = $this->getLifeTime($internalUri, 'slot'); 128 if ($lifeTime) 129 { 130 $this->addCache($moduleName, $actionName, $suffix, $lifeTime, $this->getClientLifeTime($internalUri, 'slot'), $this->getVary($internalUri, 'slot')); 131 } 128 $this->addCache($moduleName, $actionName, $suffix, $lifeTime, $this->getClientLifeTime($internalUri, 'slot'), $this->getVary($internalUri, 'slot')); 132 129 } 133 130 … … 185 182 } 186 183 187 public function hasCacheConfig($internalUri, $suffix)184 public function isCacheable($internalUri, $suffix) 188 185 { 189 186 list($route_name, $params) = $this->controller->convertUrlStringToParameters($internalUri); 190 187 $entry = $params['module'].'_'.$params['action'].'_'.$suffix; 191 188 192 if (isset($this->cacheConfig[$entry]) || isset($this->cacheConfig[$params['module'].'_DEFAULT_'.$suffix])) 189 if ( 190 (isset($this->cacheConfig[$entry]) && $this->cacheConfig[$entry]['lifeTime'] > 0) 191 || 192 (isset($this->cacheConfig[$params['module'].'_DEFAULT_'.$suffix]) && $this->cacheConfig[$params['module'].'_DEFAULT_'.$suffix]['lifeTime'] > 0) 193 ) 193 194 { 194 195 return true; … … 201 202 { 202 203 // no cache or no cache set for this action 203 if (!sfConfig::get('sf_cache') || !$this-> hasCacheConfig($internalUri, $suffix))204 if (!sfConfig::get('sf_cache') || !$this->isCacheable($internalUri, $suffix) || $this->ignore()) 204 205 { 205 206 return null; … … 216 217 public function has($internalUri, $suffix = 'slot') 217 218 { 218 if (!sfConfig::get('sf_cache') || !$this-> hasCacheConfig($internalUri, $suffix))219 if (!sfConfig::get('sf_cache') || !$this->isCacheable($internalUri, $suffix) || $this->ignore()) 219 220 { 220 221 return null; … … 229 230 } 230 231 232 protected function ignore() 233 { 234 // ignore cache parameter? (only available in debug mode) 235 if (sfConfig::get('sf_debug') && $this->getContext()->getRequest()->getParameter('sf_ignore_cache', false, 'symfony/request/sfWebRequest') == true) 236 { 237 if (sfConfig::get('sf_logging_active')) 238 { 239 $this->getContext()->getLogger()->info('{sfViewCacheManager} discard cache'); 240 } 241 242 return true; 243 } 244 245 return false; 246 } 247 231 248 public function set($data, $internalUri, $suffix = 'slot') 232 249 { 233 if (!sfConfig::get('sf_cache') || !$this-> hasCacheConfig($internalUri, $suffix))250 if (!sfConfig::get('sf_cache') || !$this->isCacheable($internalUri, $suffix)) 234 251 { 235 252 return false; … … 302 319 public function lastModified($internalUri, $suffix = 'slot') 303 320 { 304 if (!sfConfig::get('sf_cache') || !$this-> hasCacheConfig($internalUri, $suffix))321 if (!sfConfig::get('sf_cache') || !$this->isCacheable($internalUri, $suffix)) 305 322 { 306 323 return null;

