Changeset 914
- Timestamp:
- 09/12/07 14:41:30 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/session/resourcemanager/stubSessionResourceManager.php
r909 r914 104 104 if ($this->session->hasValue($sessionKey)) { 105 105 $this->resources[$implementation] = $this->session->getValue($sessionKey); 106 $this->session->putValue($sessionKey, $this->resources[$implementation]);107 106 return $this->resources[$implementation]; 108 107 } trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php
r522 r914 42 42 */ 43 43 private $sessionName = ''; 44 44 /** 45 * cache for objects 46 * 47 * @var array<string,object> 48 */ 49 private $objectCache = array(); 50 45 51 /** 46 52 * constructor … … 72 78 $this->putValue(stubSession::NEXT_TOKEN, md5(uniqid(rand()))); 73 79 } 74 80 75 81 /** 76 82 * template method for child classes to do the real construction … … 80 86 */ 81 87 protected abstract function doConstruct(stubRequest $request, $sessionName); 82 88 89 /** 90 * clear up object cache (make sure that changed objects are written into session store) 91 */ 92 public final function __destruct() 93 { 94 foreach ($this->objectCache as $key => $value) { 95 $this->managePutValue($key, $value); 96 } 97 } 98 83 99 /** 84 100 * returns fingerprint for user: has to use same user agent all over the session … … 97 113 throw new stubSessionException('Cloning the session is somewhat... useless.'); 98 114 } 99 115 100 116 /** 101 117 * checks whether session has been started … … 125 141 return $this->getValue(stubSession::START_TIME); 126 142 } 127 143 128 144 /** 129 145 * returns the name of the session … … 145 161 return $this->token; 146 162 } 147 163 148 164 /** 149 165 * returns token for next request … … 155 171 return $this->getValue(stubSession::NEXT_TOKEN); 156 172 } 157 173 158 174 /** 159 175 * checks if this session is valid … … 165 181 return $this->hasValue(stubSession::START_TIME); 166 182 } 167 168 /**183 184 /** 169 185 * resets the session and deletes all session data 170 186 * … … 173 189 public function reset() 174 190 { 175 $valueKeys = $this->getValueKeys(); 176 $count = 0; 191 $this->objectCache = array(); 192 $valueKeys = $this->getValueKeys(); 193 $count = 0; 177 194 foreach ($valueKeys as $valueKey) { 178 195 if (stubSession::NEXT_TOKEN == $valueKey || stubSession::FINGERPRINT == $valueKey) { … … 190 207 return $count; 191 208 } 192 209 193 210 /** 194 211 * stores a value associated with the key … … 198 215 */ 199 216 public function putValue($key, $value) 217 { 218 $this->managePutValue($key, $value); 219 if (is_object($value) === true) { 220 $this->objectCache[$key] = $value; 221 } 222 } 223 224 /** 225 * helper method for storing the value into the session 226 * 227 * @param string $key key to store value under 228 * @param mixed $value data to store 229 */ 230 protected function managePutValue($key, $value) 200 231 { 201 232 // This will enable lazy loading for stubObjects that are stored within … … 207 238 } 208 239 } 209 240 210 241 /** 211 242 * returns a value associated with the key or the default value … … 215 246 */ 216 247 protected abstract function doPutValue($key, $value); 217 248 218 249 /** 219 250 * returns a value associated with the key or the default value … … 230 261 } 231 262 263 if (isset($this->objectCache[$key]) === true) { 264 return $this->objectCache[$key]; 265 } 266 232 267 if ($this->hasValue($key) == true) { 233 268 $value = $this->doGetValue($key); 234 269 if ($value instanceof stubSerializedObject) { 235 return $value->getUnserialized(); 270 $this->objectCache[$key] = $value->getUnserialized(); 271 return $this->objectCache[$key]; 236 272 } 237 273 274 if (is_object($value) === true) { 275 $this->objectCache[$key] = $value; 276 } 277 238 278 return $value; 239 279 } … … 241 281 return $default; 242 282 } 243 283 244 284 /** 245 285 * returns a value associated with the key or the default value … … 249 289 */ 250 290 protected abstract function doGetValue($key); 251 291 252 292 /** 253 293 * removes a value from the session … … 263 303 } 264 304 305 if (isset($this->objectCache[$key]) === true) { 306 unset($this->objectCache[$key]); 307 } 308 265 309 if ($this->hasValue($key) == true) { 266 310 return $this->doRemoveValue($key); … … 269 313 return false; 270 314 } 271 315 272 316 /** 273 317 * removes a value from the session … … 277 321 */ 278 322 protected abstract function doRemoveValue($key); 279 323 280 324 /** 281 325 * return an array of all keys registered in this session … … 292 336 return $this->doGetValueKeys(); 293 337 } 294 338 295 339 /** 296 340 * return an array of all keys registered in this session
