Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
--- /tmp/agavi0.11.1/filter/AgaviExecutionFilter.class.php	2008-05-02 12:34:58.000000000 +0300
+++ /opt/workspace/x/app/lib/MyExecutionFilter.class.php	2009-01-25 00:25:30.000000000 +0200
@@ -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