@@ -30,7 +30,7 @@
*
* @version $Id: AgaviExecutionFilter.class.php 2449 2008-05-02 09:34:58Z david $
*/
-class AgaviExecutionFilter extends AgaviFilter implements AgaviIActionFilter
+class MyExecutionFilter extends AgaviFilter implements AgaviIActionFilter
{
/*
* The directory inside %core.cache_dir% where cached stuff is stored.
@@ -304,7 +304,7 @@
// $lm->log('Action not cached, executing...');
// execute the Action and get the View to execute
- list($actionCache['view_module'], $actionCache['view_name']) = $this->runAction($container);
+ list($actionCache['view_module'], $actionCache['view_name'], $actionCache['return_code'], $actionCache['action_name']) = $this->runAction($container);
// check if we've just run the action again after a previous cache read revealed that the view is not cached for this output type and we need to go back to square one due to the lack of action attribute caching configuration...
// if yes: is the view module/name that we got just now different from what was in the cache?
@@ -349,7 +349,7 @@
$key = $request->toggleLock();
try {
// get the view instance
- $viewInstance = $controller->createViewInstance($actionCache['view_module'], $actionCache['view_name']);
+ $viewInstance = $controller->createViewInstance($actionCache['view_module'], $actionCache['action_name']);
// initialize the view
$viewInstance->initialize($container);
} catch(Exception $e) {
@@ -403,13 +403,19 @@
// $lm->log('View is not cached, executing...');
// view initialization completed successfully
- $executeMethod = 'execute' . $outputType;
- if(!method_exists($viewInstance, $executeMethod)) {
- $executeMethod = 'execute';
+ $executeMethod = strtolower($actionCache['return_code']) . $outputType;
+ $setupMethod = 'setup' . $outputType;
+ if(!method_exists($viewInstance, $executeMethod)) {
+ $executeMethod = 'execute';
}
$key = $request->toggleLock();
try {
- $viewCache['next'] = $viewInstance->$executeMethod($container->getRequestData());
+ $viewCachePartial = '';
+ if($executeMethod != 'execute') {
+ $viewCachePartial = $viewInstance->$setupMethod($container->getRequestData());
+ }
+ #error_log($viewCachePartial." + ".get_class($viewInstance)."->".$executeMethod,0);
+ $viewCache['next'] = $viewCachePartial + $viewInstance->$executeMethod($container->getRequestData());
} catch(Exception $e) {
// we caught an exception... unlock the request and rethrow!
$request->toggleLock($key);
@@ -686,23 +692,54 @@
}
$request->toggleLock($key);
}
- }
-
+ }
+
if(is_array($viewName)) {
- // we're going to use an entirely different action for this view
+ // we're going to use an entirely different action for this view
+ $parts = $this->unCamelCase($viewName[1]);
+ $returnCode = array_pop($parts);
$viewModule = $viewName[0];
- $viewName = $viewName[1];
+ $viewName = $viewName[1];
+
+ $realActionName = '';
+ foreach($parts as $p) {
+ $realActionName .= $p;
+ }
+ $actionName = $realActionName;
} elseif($viewName !== AgaviView::NONE) {
// use a view related to this action
- $viewName = $actionName . $viewName;
+ $returnCode = $viewName;
+ $viewName = $actionName . $returnCode;
$viewModule = $moduleName;
} else {
+ $returnCode = null;
$viewName = AgaviView::NONE;
$viewModule = AgaviView::NONE;
- }
+ }
- return array($viewModule, $viewName);
+ return array($viewModule, $viewName, $returnCode, $actionName);
}
+
+ # split camel cased words by their caps
+ # http://fi.php.net/manual/en/function.ucwords.php#49303
+ public function unCamelCase($str)
+ {
+ # if lowercase first char, skip unCamelCasing (as there are none). return str in array.
+ if($str[0] !== ucfirst($str[0])) {
+ return array($str);
+ }
+
+ $bits = preg_split('/([A-Z])/',$str,false,PREG_SPLIT_DELIM_CAPTURE);
+ $a = array();
+ array_shift($bits);
+ for($i=0; $i<count($bits); ++$i) {
+ if($i%2) {
+ $a[] = $bits[$i - 1].$bits[$i];
+ }
+ }
+ return $a;
+ }
+
}
?>
\ No newline at end of file