Changeset 388
- Timestamp:
- 03/15/07 21:22:54 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/ipo/session/stubPHPSession.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/ipo/session/stubSession.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/util/log/stubBaseLogData.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/websites/stubFrontControllerInjectionMapTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php
r377 r388 42 42 */ 43 43 private $sessionName = ''; 44 /** 45 * list of serialized stubobjects 46 * 47 * @var array<string,stubObject> 48 */ 49 private $stubObjects = array(); 44 50 45 51 /** … … 56 62 if ($this->hasValue(stubSession::START_TIME) == false) { 57 63 // prevent session fixation 58 $this->regenerateI D();64 $this->regenerateId(); 59 65 } else { 60 66 // prevent session hijacking … … 192 198 193 199 /** 200 * stores a value associated with the key 201 * 202 * @param string $key key to store value under 203 * @param mixed $value data to store 204 */ 205 public function putValue($key, $value) 206 { 207 // This will enable lazy loading for stubObjects that are stored within 208 // the session. 209 if ($value instanceof stubObject) { 210 $this->doPutValue($key, $value->getSerialized()); 211 $this->stubObjects[$key] = $value; 212 } else { 213 $this->doPutValue($key, $value); 214 } 215 } 216 217 /** 218 * returns a value associated with the key or the default value 219 * 220 * @param string $key key to store value under 221 * @param mixed $value data to store 222 */ 223 protected abstract function doPutValue($key, $value); 224 225 /** 194 226 * returns a value associated with the key or the default value 195 227 * … … 206 238 207 239 if ($this->hasValue($key) == true) { 208 return $this->doGetValue($key); 240 if (isset($this->stubObjects[$key]) == true) { 241 return $this->stubObjects[$key]; 242 } 243 244 $value = $this->doGetValue($key); 245 if ($value instanceof stubSerializedObject) { 246 $stubObject = $value->getUnserialized(); 247 $this->stubObjects[$key] = $stubObject; 248 return $stubObject; 249 } 250 251 return $value; 209 252 } 210 253 trunk/src/main/php/net/stubbles/ipo/session/stubPHPSession.php
r376 r388 58 58 * @return string the session id 59 59 */ 60 public function getI D()60 public function getId() 61 61 { 62 62 return session_id(); … … 66 66 * regenerates the session id but leaves session data 67 67 */ 68 public function regenerateI D()68 public function regenerateId() 69 69 { 70 70 @session_regenerate_id(true); … … 87 87 * @param mixed $value data to store 88 88 */ 89 p ublic function putValue($key, $value)89 protected function doPutValue($key, $value) 90 90 { 91 91 $_SESSION[$key] = $value; trunk/src/main/php/net/stubbles/ipo/session/stubSession.php
r377 r388 52 52 * @return string the session id 53 53 */ 54 public function getI D();54 public function getId(); 55 55 56 56 /** … … 64 64 * regenerates the session id but leaves session data 65 65 */ 66 public function regenerateI D();66 public function regenerateId(); 67 67 68 68 /** trunk/src/main/php/net/stubbles/util/log/stubBaseLogData.php
r372 r388 62 62 $this->level = $level; 63 63 $this->logData = array(date('Y-m-d H:i:s'), 64 $session->getI D()64 $session->getId() 65 65 ); 66 66 } trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php
r377 r388 9 9 stubClassLoader::load('net.stubbles.ipo.session.stubAbstractSession'); 10 10 Mock::generate('stubRequest'); 11 Mock::generate('stubObject'); 11 12 class stubTestSession extends stubAbstractSession 12 13 { … … 32 33 protected function getFingerprint() { return 'foobarbaz'; } 33 34 34 public function getI D() { return $this->id; }35 36 public function regenerateI D() { $this->id = 'foo'; }35 public function getId() { return $this->id; } 36 37 public function regenerateId() { $this->id = 'foo'; } 37 38 38 39 public function invalidate() { $this->data = array(); } 39 40 public function putValue($key, $value) { $this->data[$key] = $value; } 40 41 public function inject($key, $value) { $this->data[$key] = $value; } 42 43 protected function doPutValue($key, $value) { $this->data[$key] = $value; } 41 44 42 45 public function hasValue($key) { return isset($this->data[$key]); } … … 195 198 $this->assertFalse($this->session->hasValue('foo')); 196 199 } 200 201 /** 202 * assure that instances of stubObject are handled correct 203 */ 204 public function testStubObjectSerialization() 205 { 206 $mockstubObject = new MockstubObject(); 207 $mockstubObject->setReturnValue('getClassName', 'MockstubObject'); 208 $mockstubObject->setReturnValue('hashCode', 'mock'); 209 $serialized = new stubSerializedObject($mockstubObject); 210 $mockstubObject->setReturnValue('getSerialized', $serialized); 211 $mockstubObject->expectOnce('getSerialized'); 212 $this->session->putValue('foo', $mockstubObject); 213 $foo = $this->session->getValue('foo'); 214 $this->assertReference($foo, $mockstubObject); 215 } 216 217 /** 218 * assure that instances of stubObject are handled correct 219 */ 220 public function testStubObjectUnserialization() 221 { 222 $mockstubObject = new MockstubObject(); 223 $mockstubObject->setReturnValue('getClassName', 'MockstubObject'); 224 $mockstubObject->setReturnValue('hashCode', 'mock'); 225 $serialized = new stubSerializedObject($mockstubObject); 226 $this->session->inject('foo', $serialized); 227 $second = $this->session->getValue('foo'); 228 $third = $this->session->getValue('foo'); 229 $this->assertReference($second, $third); 230 } 197 231 } 198 232 ?> trunk/src/test/php/net/stubbles/websites/stubFrontControllerInjectionMapTestCase.php
r385 r388 34 34 public function invalidate() {} 35 35 public function reset() {} 36 p ublic function putValue($key, $value) {}36 protected function doPutValue($key, $value) {} 37 37 protected function doGetValue($key) {} 38 38 public function hasValue($key) {}
