Changeset 407

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

bugfix to keep data integrity between requests

Files:

Legend:

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

    r388 r407  
    4242     */ 
    4343    private $sessionName = ''; 
    44     /** 
    45      * list of serialized stubobjects 
    46      * 
    47      * @var  array<string,stubObject> 
    48      */ 
    49     private $stubObjects = array(); 
    5044     
    5145    /** 
     
    209203        if ($value instanceof stubObject) { 
    210204            $this->doPutValue($key, $value->getSerialized()); 
    211             $this->stubObjects[$key] = $value; 
    212205        } else {         
    213206            $this->doPutValue($key, $value); 
     
    238231         
    239232        if ($this->hasValue($key) == true) { 
    240             if (isset($this->stubObjects[$key]) == true) { 
    241                 return $this->stubObjects[$key]; 
    242             } 
    243              
    244233            $value = $this->doGetValue($key); 
    245234            if ($value instanceof stubSerializedObject) { 
    246                 $stubObject = $value->getUnserialized(); 
    247                 $this->stubObjects[$key] = $stubObject; 
    248                 return $stubObject; 
     235                return $value->getUnserialized(); 
    249236            } 
    250237             
  • trunk/src/main/php/net/stubbles/stubSerializedObject.php

    r387 r407  
    2424    protected $className; 
    2525    /** 
     26     * the instance of the serialized class 
     27     * 
     28     * @var  stubObject 
     29     */ 
     30    protected $classInstance; 
     31    /** 
    2632     * hash code of serialized class 
    2733     * 
     
    4349    public function __construct(stubObject $object) 
    4450    { 
    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'); 
    4865    } 
    4966     
     
    5774    public function getUnserialized() 
    5875    { 
     76        if (null != $this->classInstance) { 
     77            return $this->classInstance; 
     78        } 
     79         
    5980        $nqClassName = stubClassLoader::getNonQualifiedClassName($this->className); 
    6081        if (class_exists($nqClassName, false) == false) { 
     
    6283        } 
    6384         
    64         return unserialize($this->data); 
     85        $this->classInstance = unserialize($this->data); 
     86        return $this->classInstance; 
    6587    } 
    6688     
     
    7496        return $this->className; 
    7597    } 
    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 
    8799    /** 
    88100     * returns class informations 
     
    166178        $string  = $this->getClassName() . " {\n"; 
    167179        $string .= '    class(string): ' . $this->className . "\n"; 
    168         $string .= '    data(string): ' . $this->data . "\n"; 
     180        $string .= '    data(string): ' . serialize($this->classInstance) . "\n"; 
    169181        $string .= "}\n"; 
    170182        return $string; 
  • trunk/src/test/php/net/stubbles/stubSerializedObjectTestCase.php

    r387 r407  
    6464    { 
    6565        $this->assertEqual($this->serializedObject->getSerializedClassName(), 'test.stub3stubBaseObject'); 
    66         $this->assertEqual($this->serializedObject->getSerializedData(), serialize($this->stubBaseObject)); 
    6766    } 
    6867     
     
    119118        $this->assertEqual((string) $this->serializedObject, "net.stubbles.stubSerializedObject {\n    class(string): test.stub3stubBaseObject\n    data(string): " . serialize($this->stubBaseObject) . "\n}\n"); 
    120119    } 
     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    } 
    121143} 
    122144?>