Changeset 522
- Timestamp:
- 04/14/07 17:58:46 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAbstractAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/stubBaseObject.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/stubClassLoader.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/stubException.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/stubObject.php (modified) (6 diffs)
- trunk/src/main/php/net/stubbles/stubSerializable.php (added)
- trunk/src/main/php/net/stubbles/stubSerializableObject.php (added)
- trunk/src/main/php/net/stubbles/stubSerializedObject.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/stubBaseObjectTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/stubExceptionTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/stubSerializableObjectTestCase.php (added)
- trunk/src/test/php/net/stubbles/stubSerializedObjectTestCase.php (modified) (11 diffs)
- trunk/src/test/php/net/stubbles/stubTestSuite.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php
r407 r522 200 200 { 201 201 // This will enable lazy loading for stubObjects that are stored within 202 // the session .203 if ($value instanceof stub Object) {202 // the session and implement the stubSerializable interface. 203 if ($value instanceof stubSerializable) { 204 204 $this->doPutValue($key, $value->getSerialized()); 205 205 } else { trunk/src/main/php/net/stubbles/reflection/annotations/stubAbstractAnnotation.php
r501 r522 14 14 * @subpackage reflection_annotations 15 15 */ 16 abstract class stubAbstractAnnotation extends stub BaseObject implements stubAnnotation16 abstract class stubAbstractAnnotation extends stubSerializableObject implements stubAnnotation 17 17 { 18 18 /** trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotation.php
r501 r522 13 13 * @subpackage reflection_annotations 14 14 */ 15 interface stubAnnotation extends stub Object15 interface stubAnnotation extends stubSerializable 16 16 { 17 17 /** trunk/src/main/php/net/stubbles/stubBaseObject.php
r500 r522 15 15 class stubBaseObject implements stubObject 16 16 { 17 /**18 * a list of serialized properties19 *20 * Do not ever use this property in extended classes. It is only protected21 * and not private because of some PHP-$§&%&§%&!22 *23 * @var array<string,stubSerializedObject>24 */25 protected $_serializedProperties = array();26 27 17 /** 28 18 * returns class informations … … 73 63 return false; 74 64 } 75 76 /** 77 * returns a serialized representation of the class 78 * 79 * @return stubSerializedObject 80 * @XMLIgnore 81 */ 82 public function getSerialized() 83 { 84 $serialized = new stubSerializedObject($this); 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(); 118 } 119 65 120 66 /** 121 67 * returns a string representation of the class trunk/src/main/php/net/stubbles/stubClassLoader.php
r451 r522 81 81 $classNames = func_get_args(); 82 82 if (count($classNames) == 0) { 83 // its ok to call this without any arguments, this won't cause any harm83 // its ok to call this without any arguments, this won't cause any harm 84 84 return; 85 85 } … … 197 197 * every other class that should extend it 198 198 */ 199 stubClassLoader::load('net.stubbles.stubObject', 'net.stubbles.stubSerializedObject', 'net.stubbles.stubBaseObject', 'net.stubbles.stubException'); 199 stubClassLoader::load('net.stubbles.stubObject', 200 'net.stubbles.stubBaseObject', 201 'net.stubbles.stubException', 202 'net.stubbles.stubSerializable', 203 'net.stubbles.stubSerializableObject', 204 'net.stubbles.stubSerializedObject' 205 206 ); 200 207 ?> trunk/src/main/php/net/stubbles/stubException.php
r387 r522 1 1 <?php 2 2 /** 3 * base class for all other stubbles classes except static ones and classes 4 * extending php built-in classes 3 * Base exception class for all stubbles exceptions. 5 4 * 6 5 * @author Frank Kleine <mikey@stubbles.net> … … 8 7 */ 9 8 /** 10 * base class for all other stubbles classes except static ones and classes 11 * extending php built-in classes 9 * Base exception class for all stubbles exceptions. 12 10 * 13 11 * @package stubbles … … 63 61 return false; 64 62 } 65 66 /** 67 * returns a serialized representation of the class 68 * 69 * @return stubSerializedObject 70 * @XMLIgnore 71 */ 72 public function getSerialized() 73 { 74 $serialized = new stubSerializedObject($this); 75 return $serialized; 76 } 77 63 78 64 /** 79 65 * returns a string representation of the class trunk/src/main/php/net/stubbles/stubObject.php
r387 r522 1 1 <?php 2 2 /** 3 * base class for all otherstubbles classes except static ones and classes4 * extending php built-in classes 3 * Base interface for all stubbles classes except static ones and classes 4 * extending php built-in classes. 5 5 * 6 6 * @author Frank Kleine <mikey@stubbles.net> … … 8 8 */ 9 9 /** 10 * base class for all otherstubbles classes except static ones and classes11 * extending php built-in classes 10 * Base interface for all stubbles classes except static ones and classes 11 * extending php built-in classes. 12 12 * 13 13 * @package stubbles … … 21 21 */ 22 22 public function getClass(); 23 23 24 24 /** 25 25 * returns the full qualified class name … … 28 28 */ 29 29 public function getClassName(); 30 30 31 31 /** 32 32 * returns a unique hash code for the class … … 35 35 */ 36 36 public function hashCode(); 37 37 38 38 /** 39 39 * checks whether a value is equal to the class … … 43 43 */ 44 44 public function equals($compare); 45 46 /** 47 * returns a serialized representation of the class 48 * 49 * @return stubSerializedObject 50 */ 51 public function getSerialized(); 52 45 53 46 /** 54 47 * returns a string representation of the class trunk/src/main/php/net/stubbles/stubSerializedObject.php
r509 r522 51 51 * constructor 52 52 * 53 * @param stub Object $object the stubObjectinstance to serialize54 */ 55 public function __construct(stub Object $object)56 { 57 $this->fqClassName = $ object->getClassName();53 * @param stubSerializable $serializable the instance to serialize 54 */ 55 public function __construct(stubSerializable $serializable) 56 { 57 $this->fqClassName = $serializable->getClassName(); 58 58 if (null != $this->fqClassName) { 59 59 $this->nqClassName = stubClassLoader::getNonQualifiedClassName($this->fqClassName); 60 60 } else { 61 $this->nqClassName = get_class($ object);62 } 63 64 $this->classInstance = $ object;65 $this->hashCode = $ object->hashCode();61 $this->nqClassName = get_class($serializable); 62 } 63 64 $this->classInstance = $serializable; 65 $this->hashCode = $serializable->hashCode(); 66 66 } 67 67 … … 85 85 * If the class was not loaded before it is loaded before unserialization. 86 86 * 87 * @return stub Object87 * @return stubSerializable 88 88 */ 89 89 public function getUnserialized() trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php
r388 r522 9 9 stubClassLoader::load('net.stubbles.ipo.session.stubAbstractSession'); 10 10 Mock::generate('stubRequest'); 11 Mock::generate('stub Object');11 Mock::generate('stubSerializableObject'); 12 12 class stubTestSession extends stubAbstractSession 13 13 { … … 204 204 public function testStubObjectSerialization() 205 205 { 206 $mock stubObject = new MockstubObject();207 $mock stubObject->setReturnValue('getClassName', 'MockstubObject');208 $mock stubObject->setReturnValue('hashCode', 'mock');209 $serialized = new stubSerializedObject($mock stubObject);210 $mock stubObject->setReturnValue('getSerialized', $serialized);211 $mock stubObject->expectOnce('getSerialized');212 $this->session->putValue('foo', $mock stubObject);206 $mockSerializableObject = new MockstubSerializableObject(); 207 $mockSerializableObject->setReturnValue('getClassName', 'MockstubSerializableObject'); 208 $mockSerializableObject->setReturnValue('hashCode', 'mock'); 209 $serialized = new stubSerializedObject($mockSerializableObject); 210 $mockSerializableObject->setReturnValue('getSerialized', $serialized); 211 $mockSerializableObject->expectOnce('getSerialized'); 212 $this->session->putValue('foo', $mockSerializableObject); 213 213 $foo = $this->session->getValue('foo'); 214 $this->assertReference($foo, $mock stubObject);214 $this->assertReference($foo, $mockSerializableObject); 215 215 } 216 216 … … 220 220 public function testStubObjectUnserialization() 221 221 { 222 $mock stubObject = new MockstubObject();223 $mock stubObject->setReturnValue('getClassName', 'MockstubObject');224 $mock stubObject->setReturnValue('hashCode', 'mock');225 $serialized = new stubSerializedObject($mock stubObject);222 $mockSerializableObject = new MockstubSerializableObject(); 223 $mockSerializableObject->setReturnValue('getClassName', 'MockstubSerializableObject'); 224 $mockSerializableObject->setReturnValue('hashCode', 'mock'); 225 $serialized = new stubSerializedObject($mockSerializableObject); 226 226 $this->session->inject('foo', $serialized); 227 227 $second = $this->session->getValue('foo'); trunk/src/test/php/net/stubbles/stubBaseObjectTestCase.php
r500 r522 26 26 { 27 27 return 'test.stub2stubBaseObject'; 28 }29 30 public function getSerializedProperties()31 {32 return $this->_serializedProperties;33 28 } 34 29 } … … 91 86 $this->assertFalse($this->stubBaseObject2->equals(new stub2stubBaseObject())); 92 87 } 93 94 /**95 * assure that serialization delivers the correct class96 */97 public function testGetSerialized()98 {99 $serialized = $this->stubBaseObject1->getSerialized();100 $this->assertIsA($serialized, 'stubSerializedObject');101 }102 103 /**104 * assure that the __toString() method works correct105 */106 public function testToString()107 {108 $this->assertEqual((string) $this->stubBaseObject1, "test.stub1stubBaseObject {\n bar(integer): 5\n}\n");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");110 }111 112 /**113 * assure that the __sleep() method works correct114 */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 }123 88 } 124 89 ?> trunk/src/test/php/net/stubbles/stubExceptionTestCase.php
r387 r522 79 79 $this->assertFalse($this->stubException2->equals(new stub2stubException())); 80 80 } 81 82 /**83 * assure that serialization delivers the correct class84 */85 public function testGetSerialized()86 {87 $serialized = $this->stubException1->getSerialized();88 $this->assertIsA($serialized, 'stubSerializedObject');89 }90 81 } 91 82 ?> trunk/src/test/php/net/stubbles/stubSerializedObjectTestCase.php
r510 r522 8 8 */ 9 9 stubClassLoader::load('net.stubbles.stubSerializedObject'); 10 class stub3stub BaseObject extends stubBaseObject10 class stub3stubSerializableObject extends stubSerializableObject 11 11 { 12 12 protected $bar; … … 14 14 public function getClassname() 15 15 { 16 return 'test.stub3stub BaseObject';16 return 'test.stub3stubSerializableObject'; 17 17 } 18 18 … … 38 38 * instance 1 to be used for tests 39 39 * 40 * @var stub BaseObject40 * @var stubSerializableObject 41 41 */ 42 protected $stub BaseObject;42 protected $stubSerializableObject; 43 43 /** 44 44 * instance to test … … 53 53 public function setUp() 54 54 { 55 $this->stub BaseObject = new stub3stubBaseObject();56 $this->stub BaseObject->setBar(313);57 $this->serializedObject = new stubSerializedObject($this->stub BaseObject);55 $this->stubSerializableObject = new stub3stubSerializableObject(); 56 $this->stubSerializableObject->setBar(313); 57 $this->serializedObject = new stubSerializedObject($this->stubSerializableObject); 58 58 } 59 59 … … 63 63 public function testValues() 64 64 { 65 $this->assertEqual($this->serializedObject->getSerializedClassName(), 'test.stub3stub BaseObject');65 $this->assertEqual($this->serializedObject->getSerializedClassName(), 'test.stub3stubSerializableObject'); 66 66 } 67 67 … … 72 72 { 73 73 $restored = $this->serializedObject->getUnserialized(); 74 $this->assertIsA($restored, 'stub3stub BaseObject');74 $this->assertIsA($restored, 'stub3stubSerializableObject'); 75 75 $this->assertEqual($restored->getBar(), 313); 76 76 } … … 92 92 { 93 93 $this->assertTrue($this->serializedObject->equals($this->serializedObject)); 94 $this->assertTrue($this->serializedObject->equals(new stubSerializedObject($this->stub BaseObject)));95 $this->assertFalse($this->serializedObject->equals($this->stub BaseObject));94 $this->assertTrue($this->serializedObject->equals(new stubSerializedObject($this->stubSerializableObject))); 95 $this->assertFalse($this->serializedObject->equals($this->stubSerializableObject)); 96 96 $this->assertFalse($this->serializedObject->equals('foo')); 97 97 $this->assertFalse($this->serializedObject->equals(6)); … … 99 99 $this->assertFalse($this->serializedObject->equals(false)); 100 100 $this->assertFalse($this->serializedObject->equals(null)); 101 $this->assertFalse($this->serializedObject->equals(new stubSerializedObject(new stub3stub BaseObject())));101 $this->assertFalse($this->serializedObject->equals(new stubSerializedObject(new stub3stubSerializableObject()))); 102 102 } 103 103 … … 116 116 public function testToString() 117 117 { 118 $this->assertEqual((string) $this->serializedObject, "net.stubbles.stubSerializedObject {\n fqClassName(string): test.stub3stub BaseObject\n nqClassName(string): stub3stubBaseObject\n data(string): " . serialize($this->stubBaseObject) . "\n}\n");118 $this->assertEqual((string) $this->serializedObject, "net.stubbles.stubSerializedObject {\n fqClassName(string): test.stub3stubSerializableObject\n nqClassName(string): stub3stubSerializableObject\n data(string): " . serialize($this->stubSerializableObject) . "\n}\n"); 119 119 } 120 120 … … 125 125 { 126 126 $stub3 = $this->serializedObject->getUnserialized(); 127 $this->assertReference($stub3, $this->stub BaseObject);128 $this->stub BaseObject->setBar(303);127 $this->assertReference($stub3, $this->stubSerializableObject); 128 $this->stubSerializableObject->setBar(303); 129 129 130 130 // next request … … 148 148 public function testSerializationIntegrity() 149 149 { 150 $this->stub BaseObject->setBar(808);150 $this->stubSerializableObject->setBar(808); 151 151 $foo = serialize($this->serializedObject); 152 152 $bar = unserialize($foo); 153 153 $baz = serialize($bar); 154 154 $test = unserialize($baz); 155 $ baseObject = $test->getUnserialized();156 $this->assertIsA($ baseObject, 'stub3stubBaseObject');157 $this->assertEqual($ baseObject->getBar(), 808);155 $serializableObject = $test->getUnserialized(); 156 $this->assertIsA($serializableObject, 'stub3stubSerializableObject'); 157 $this->assertEqual($serializableObject->getBar(), 808); 158 158 } 159 159 } trunk/src/test/php/net/stubbles/stubTestSuite.php
r387 r522 26 26 $this->addTestFile($dir . '/stubExceptionTestCase.php'); 27 27 $this->addTestFile($dir . '/stubChainedExceptionTestCase.php'); 28 $this->addTestFile($dir . '/stubSerializableObjectTestCase.php'); 28 29 $this->addTestFile($dir . '/stubSerializedObjectTestCase.php'); 29 30 }
