Changeset 522

Show
Ignore:
Timestamp:
04/14/07 17:58:46 (1 year ago)
Author:
mikey
Message:

separated serialization stuff from net.stubbles.stubObject into net.stubbles.stubSerializable and from net.stubbles.stubBaseObject into net.stubbles.stubSerializableObject
net.stubbles.reflection.annotations.stubAnnotation extends net.stubbles.stubSerializable

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php

    r407 r522  
    200200    { 
    201201        // This will enable lazy loading for stubObjects that are stored within 
    202         // the session
    203         if ($value instanceof stubObject) { 
     202        // the session and implement the stubSerializable interface
     203        if ($value instanceof stubSerializable) { 
    204204            $this->doPutValue($key, $value->getSerialized()); 
    205205        } else {         
  • trunk/src/main/php/net/stubbles/reflection/annotations/stubAbstractAnnotation.php

    r501 r522  
    1414 * @subpackage  reflection_annotations 
    1515 */ 
    16 abstract class stubAbstractAnnotation extends stubBaseObject implements stubAnnotation 
     16abstract class stubAbstractAnnotation extends stubSerializableObject implements stubAnnotation 
    1717{ 
    1818    /** 
  • trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotation.php

    r501 r522  
    1313 * @subpackage  reflection_annotations 
    1414 */ 
    15 interface stubAnnotation extends stubObject 
     15interface stubAnnotation extends stubSerializable 
    1616{ 
    1717    /** 
  • trunk/src/main/php/net/stubbles/stubBaseObject.php

    r500 r522  
    1515class stubBaseObject implements stubObject 
    1616{ 
    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      
    2717    /** 
    2818     * returns class informations 
     
    7363        return false; 
    7464    } 
    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 
    12066    /** 
    12167     * returns a string representation of the class 
  • trunk/src/main/php/net/stubbles/stubClassLoader.php

    r451 r522  
    8181        $classNames = func_get_args(); 
    8282        if (count($classNames) == 0) { 
    83            // its ok to call this without any arguments, this won't cause any harm 
     83            // its ok to call this without any arguments, this won't cause any harm 
    8484            return; 
    8585        } 
     
    197197 * every other class that should extend it 
    198198 */ 
    199 stubClassLoader::load('net.stubbles.stubObject', 'net.stubbles.stubSerializedObject', 'net.stubbles.stubBaseObject', 'net.stubbles.stubException'); 
     199stubClassLoader::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); 
    200207?> 
  • trunk/src/main/php/net/stubbles/stubException.php

    r387 r522  
    11<?php 
    22/** 
    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. 
    54 *  
    65 * @author   Frank Kleine  <mikey@stubbles.net> 
     
    87 */ 
    98/** 
    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. 
    1210 *  
    1311 * @package  stubbles 
     
    6361        return false; 
    6462    } 
    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 
    7864    /** 
    7965     * returns a string representation of the class 
  • trunk/src/main/php/net/stubbles/stubObject.php

    r387 r522  
    11<?php 
    22/** 
    3  * base class for all other stubbles classes except static ones and classes 
    4  * extending php built-in classes 
     3 * Base interface for all stubbles classes except static ones and classes 
     4 * extending php built-in classes. 
    55 *  
    66 * @author   Frank Kleine  <mikey@stubbles.net> 
     
    88 */ 
    99/** 
    10  * base class for all other stubbles classes except static ones and classes 
    11  * extending php built-in classes 
     10 * Base interface for all stubbles classes except static ones and classes 
     11 * extending php built-in classes. 
    1212 *  
    1313 * @package  stubbles 
     
    2121     */ 
    2222    public function getClass(); 
    23      
     23 
    2424    /** 
    2525     * returns the full qualified class name 
     
    2828     */ 
    2929    public function getClassName(); 
    30      
     30 
    3131    /** 
    3232     * returns a unique hash code for the class 
     
    3535     */ 
    3636    public function hashCode(); 
    37      
     37 
    3838    /** 
    3939     * checks whether a value is equal to the class 
     
    4343     */ 
    4444    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 
    5346    /** 
    5447     * returns a string representation of the class 
  • trunk/src/main/php/net/stubbles/stubSerializedObject.php

    r509 r522  
    5151     * constructor 
    5252     * 
    53      * @param  stubObject  $object  the stubObject instance to serialize 
    54      */ 
    55     public function __construct(stubObject $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(); 
    5858        if (null != $this->fqClassName) { 
    5959            $this->nqClassName = stubClassLoader::getNonQualifiedClassName($this->fqClassName); 
    6060        } 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(); 
    6666    } 
    6767     
     
    8585     * If the class was not loaded before it is loaded before unserialization. 
    8686     * 
    87      * @return  stubObject 
     87     * @return  stubSerializable 
    8888     */ 
    8989    public function getUnserialized() 
  • trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php

    r388 r522  
    99stubClassLoader::load('net.stubbles.ipo.session.stubAbstractSession'); 
    1010Mock::generate('stubRequest'); 
    11 Mock::generate('stubObject'); 
     11Mock::generate('stubSerializableObject'); 
    1212class stubTestSession extends stubAbstractSession 
    1313{ 
     
    204204    public function testStubObjectSerialization() 
    205205    { 
    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); 
     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); 
    213213        $foo = $this->session->getValue('foo'); 
    214         $this->assertReference($foo, $mockstubObject); 
     214        $this->assertReference($foo, $mockSerializableObject); 
    215215    } 
    216216     
     
    220220    public function testStubObjectUnserialization() 
    221221    { 
    222         $mockstubObject = new MockstubObject(); 
    223         $mockstubObject->setReturnValue('getClassName', 'MockstubObject'); 
    224         $mockstubObject->setReturnValue('hashCode', 'mock'); 
    225         $serialized = new stubSerializedObject($mockstubObject); 
     222        $mockSerializableObject = new MockstubSerializableObject(); 
     223        $mockSerializableObject->setReturnValue('getClassName', 'MockstubSerializableObject'); 
     224        $mockSerializableObject->setReturnValue('hashCode', 'mock'); 
     225        $serialized = new stubSerializedObject($mockSerializableObject); 
    226226        $this->session->inject('foo', $serialized); 
    227227        $second = $this->session->getValue('foo'); 
  • trunk/src/test/php/net/stubbles/stubBaseObjectTestCase.php

    r500 r522  
    2626    { 
    2727        return 'test.stub2stubBaseObject'; 
    28     } 
    29      
    30     public function getSerializedProperties() 
    31     { 
    32         return $this->_serializedProperties; 
    3328    } 
    3429} 
     
    9186        $this->assertFalse($this->stubBaseObject2->equals(new stub2stubBaseObject())); 
    9287    } 
    93      
    94     /** 
    95      * assure that serialization delivers the correct class 
    96      */ 
    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 correct 
    105      */ 
    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 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     } 
    12388} 
    12489?> 
  • trunk/src/test/php/net/stubbles/stubExceptionTestCase.php

    r387 r522  
    7979        $this->assertFalse($this->stubException2->equals(new stub2stubException())); 
    8080    } 
    81      
    82     /** 
    83      * assure that serialization delivers the correct class 
    84      */ 
    85     public function testGetSerialized() 
    86     { 
    87         $serialized = $this->stubException1->getSerialized(); 
    88         $this->assertIsA($serialized, 'stubSerializedObject'); 
    89     } 
    9081} 
    9182?> 
  • trunk/src/test/php/net/stubbles/stubSerializedObjectTestCase.php

    r510 r522  
    88 */ 
    99stubClassLoader::load('net.stubbles.stubSerializedObject'); 
    10 class stub3stubBaseObject extends stubBaseObject 
     10class stub3stubSerializableObject extends stubSerializableObject 
    1111{ 
    1212    protected $bar; 
     
    1414    public function getClassname() 
    1515    { 
    16         return 'test.stub3stubBaseObject'; 
     16        return 'test.stub3stubSerializableObject'; 
    1717    } 
    1818     
     
    3838     * instance 1 to be used for tests 
    3939     * 
    40      * @var  stubBaseObject 
     40     * @var  stubSerializableObject 
    4141     */ 
    42     protected $stubBaseObject; 
     42    protected $stubSerializableObject; 
    4343    /** 
    4444     * instance to test 
     
    5353    public function setUp() 
    5454    { 
    55         $this->stubBaseObject   = new stub3stubBaseObject(); 
    56         $this->stubBaseObject->setBar(313); 
    57         $this->serializedObject = new stubSerializedObject($this->stubBaseObject); 
     55        $this->stubSerializableObject   = new stub3stubSerializableObject(); 
     56        $this->stubSerializableObject->setBar(313); 
     57        $this->serializedObject = new stubSerializedObject($this->stubSerializableObject); 
    5858    } 
    5959     
     
    6363    public function testValues() 
    6464    { 
    65         $this->assertEqual($this->serializedObject->getSerializedClassName(), 'test.stub3stubBaseObject'); 
     65        $this->assertEqual($this->serializedObject->getSerializedClassName(), 'test.stub3stubSerializableObject'); 
    6666    } 
    6767     
     
    7272    { 
    7373        $restored = $this->serializedObject->getUnserialized(); 
    74         $this->assertIsA($restored, 'stub3stubBaseObject'); 
     74        $this->assertIsA($restored, 'stub3stubSerializableObject'); 
    7575        $this->assertEqual($restored->getBar(), 313); 
    7676    } 
     
    9292    { 
    9393        $this->assertTrue($this->serializedObject->equals($this->serializedObject)); 
    94         $this->assertTrue($this->serializedObject->equals(new stubSerializedObject($this->stubBaseObject))); 
    95         $this->assertFalse($this->serializedObject->equals($this->stubBaseObject)); 
     94        $this->assertTrue($this->serializedObject->equals(new stubSerializedObject($this->stubSerializableObject))); 
     95        $this->assertFalse($this->serializedObject->equals($this->stubSerializableObject)); 
    9696        $this->assertFalse($this->serializedObject->equals('foo')); 
    9797        $this->assertFalse($this->serializedObject->equals(6)); 
     
    9999        $this->assertFalse($this->serializedObject->equals(false)); 
    100100        $this->assertFalse($this->serializedObject->equals(null)); 
    101         $this->assertFalse($this->serializedObject->equals(new stubSerializedObject(new stub3stubBaseObject()))); 
     101        $this->assertFalse($this->serializedObject->equals(new stubSerializedObject(new stub3stubSerializableObject()))); 
    102102    } 
    103103     
     
    116116    public function testToString() 
    117117    { 
    118         $this->assertEqual((string) $this->serializedObject, "net.stubbles.stubSerializedObject {\n    fqClassName(string): test.stub3stubBaseObject\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"); 
    119119    } 
    120120     
     
    125125    { 
    126126        $stub3 = $this->serializedObject->getUnserialized(); 
    127         $this->assertReference($stub3, $this->stubBaseObject); 
    128         $this->stubBaseObject->setBar(303); 
     127        $this->assertReference($stub3, $this->stubSerializableObject); 
     128        $this->stubSerializableObject->setBar(303); 
    129129         
    130130        // next request 
     
    148148    public function testSerializationIntegrity() 
    149149    { 
    150         $this->stubBaseObject->setBar(808); 
     150        $this->stubSerializableObject->setBar(808); 
    151151        $foo = serialize($this->serializedObject); 
    152152        $bar = unserialize($foo); 
    153153        $baz = serialize($bar); 
    154154        $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); 
    158158    } 
    159159} 
  • trunk/src/test/php/net/stubbles/stubTestSuite.php

    r387 r522  
    2626        $this->addTestFile($dir . '/stubExceptionTestCase.php'); 
    2727        $this->addTestFile($dir . '/stubChainedExceptionTestCase.php'); 
     28        $this->addTestFile($dir . '/stubSerializableObjectTestCase.php'); 
    2829        $this->addTestFile($dir . '/stubSerializedObjectTestCase.php'); 
    2930    }