Changeset 407
- Timestamp:
- 03/21/07 14:46:17 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php
r388 r407 42 42 */ 43 43 private $sessionName = ''; 44 /**45 * list of serialized stubobjects46 *47 * @var array<string,stubObject>48 */49 private $stubObjects = array();50 44 51 45 /** … … 209 203 if ($value instanceof stubObject) { 210 204 $this->doPutValue($key, $value->getSerialized()); 211 $this->stubObjects[$key] = $value;212 205 } else { 213 206 $this->doPutValue($key, $value); … … 238 231 239 232 if ($this->hasValue($key) == true) { 240 if (isset($this->stubObjects[$key]) == true) {241 return $this->stubObjects[$key];242 }243 244 233 $value = $this->doGetValue($key); 245 234 if ($value instanceof stubSerializedObject) { 246 $stubObject = $value->getUnserialized(); 247 $this->stubObjects[$key] = $stubObject; 248 return $stubObject; 235 return $value->getUnserialized(); 249 236 } 250 237 trunk/src/main/php/net/stubbles/stubSerializedObject.php
r387 r407 24 24 protected $className; 25 25 /** 26 * the instance of the serialized class 27 * 28 * @var stubObject 29 */ 30 protected $classInstance; 31 /** 26 32 * hash code of serialized class 27 33 * … … 43 49 public function __construct(stubObject $object) 44 50 { 45 $this->className = $object->getClassName(); 46 $this->hashCode = $object->hashCode(); 47 $this->data = serialize($object); 51 $this->className = $object->getClassName(); 52 $this->classInstance = $object; 53 $this->hashCode = $object->hashCode(); 54 } 55 56 /** 57 * interceptor called before object instance is serialized 58 * 59 * @return array 60 */ 61 public function __sleep() 62 { 63 $this->data = serialize($this->classInstance); 64 return array('className', 'hashCode', 'data'); 48 65 } 49 66 … … 57 74 public function getUnserialized() 58 75 { 76 if (null != $this->classInstance) { 77 return $this->classInstance; 78 } 79 59 80 $nqClassName = stubClassLoader::getNonQualifiedClassName($this->className); 60 81 if (class_exists($nqClassName, false) == false) { … … 62 83 } 63 84 64 return unserialize($this->data); 85 $this->classInstance = unserialize($this->data); 86 return $this->classInstance; 65 87 } 66 88 … … 74 96 return $this->className; 75 97 } 76 77 /** 78 * returns the serialized representation of the class data 79 * 80 * @return string 81 */ 82 public function getSerializedData() 83 { 84 return $this->data; 85 } 86 98 87 99 /** 88 100 * returns class informations … … 166 178 $string = $this->getClassName() . " {\n"; 167 179 $string .= ' class(string): ' . $this->className . "\n"; 168 $string .= ' data(string): ' . $this->data. "\n";180 $string .= ' data(string): ' . serialize($this->classInstance) . "\n"; 169 181 $string .= "}\n"; 170 182 return $string; trunk/src/test/php/net/stubbles/stubSerializedObjectTestCase.php
r387 r407 64 64 { 65 65 $this->assertEqual($this->serializedObject->getSerializedClassName(), 'test.stub3stubBaseObject'); 66 $this->assertEqual($this->serializedObject->getSerializedData(), serialize($this->stubBaseObject));67 66 } 68 67 … … 119 118 $this->assertEqual((string) $this->serializedObject, "net.stubbles.stubSerializedObject {\n class(string): test.stub3stubBaseObject\n data(string): " . serialize($this->stubBaseObject) . "\n}\n"); 120 119 } 120 121 /** 122 * assure that changes to the serialized object are not thrown away 123 */ 124 public function testDataIntegrity() 125 { 126 $stub3 = $this->serializedObject->getUnserialized(); 127 $this->assertReference($stub3, $this->stubBaseObject); 128 $this->stubBaseObject->setBar(303); 129 130 // next request 131 $newSerializedObject = unserialize(serialize($this->serializedObject)); 132 $stub3b = $newSerializedObject->getUnserialized(); 133 $stub3c = $newSerializedObject->getUnserialized(); 134 $this->assertReference($stub3b, $stub3c); 135 $this->assertEqual($stub3b->getBar(), 303); 136 $stub3b->setBar(909); 137 138 // next request 139 $moreSerializedObject = unserialize(serialize($this->serializedObject)); 140 $stub3d = $newSerializedObject->getUnserialized(); 141 $this->assertEqual($stub3d->getBar(), 909); 142 } 121 143 } 122 144 ?>
