Changeset 500
- Timestamp:
- 04/13/07 16:57:46 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/stubBaseObject.php
r387 r500 16 16 { 17 17 /** 18 * a list of serialized properties 19 * 20 * Do not ever use this property in extended classes. It is only protected 21 * and not private because of some PHP-$§&%&§%&! 22 * 23 * @var array<string,stubSerializedObject> 24 */ 25 protected $_serializedProperties = array(); 26 27 /** 18 28 * returns class informations 19 29 * … … 74 84 $serialized = new stubSerializedObject($this); 75 85 return $serialized; 86 } 87 88 /** 89 * ensure that all instances of stubObject are correctly serialized 90 * 91 * @return array<string> list of properties to serialize 92 */ 93 public function __sleep() 94 { 95 $this->_serializedProperties = array(); 96 $propertiesToSerialize = array(); 97 foreach (get_object_vars($this) as $name => $value) { 98 if ($value instanceof stubObject) { 99 $this->_serializedProperties[$name] = $value->getSerialized(); 100 } else { 101 $propertiesToSerialize[] = $name; 102 } 103 } 104 105 return $propertiesToSerialize; 106 } 107 108 /** 109 * restore all instances that are of type stubObject 110 */ 111 public function __wakeup() 112 { 113 foreach ($this->_serializedProperties as $name => $serializedValue) { 114 $this->$name = $serializedValue->getUnserialized(); 115 } 116 117 $this->_serializedProperties = array(); 76 118 } 77 119 … … 130 172 $string = $object->getClassName() . " {\n"; 131 173 foreach ($properties as $name => $value) { 174 if ('_serializedProperties' == $name) { 175 continue; 176 } 177 132 178 $string .= ' ' . $name . '(' . self::determineType($value) . '): '; 133 179 if (($value instanceof self) == false) { trunk/src/test/php/net/stubbles/stubBaseObjectTestCase.php
r387 r500 26 26 { 27 27 return 'test.stub2stubBaseObject'; 28 } 29 30 public function getSerializedProperties() 31 { 32 return $this->_serializedProperties; 28 33 } 29 34 } … … 104 109 $this->assertEqual((string) $this->stubBaseObject2, "test.stub2stubBaseObject {\n stubBaseObject(test.stub1stubBaseObject): test.stub1stubBaseObject {\n bar(integer): 5\n }\n foo(string): bar\n}\n"); 105 110 } 111 112 /** 113 * assure that the __sleep() method works correct 114 */ 115 public function testSleep() 116 { 117 $this->assertEqual($this->stubBaseObject2->__sleep(), array('foo', '_serializedProperties')); 118 $serializedProperties = $this->stubBaseObject2->getSerializedProperties(); 119 $this->assertTrue(isset($serializedProperties['stubBaseObject'])); 120 $this->assertIsA($serializedProperties['stubBaseObject'], 'stubSerializedObject'); 121 $this->assertEqual($serializedProperties['stubBaseObject']->getSerializedClassName(), 'test.stub1stubBaseObject'); 122 } 106 123 } 107 124 ?>
