Changeset 725

Show
Ignore:
Timestamp:
06/10/07 12:17:02 (1 year ago)
Author:
mikey
Message:

take care that no instances of stubReflectionClass are serialized but the required information to restore all instances after unserializing (fixes ticket #63)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/reflection/annotations/stubAbstractAnnotation.php

    r722 r725  
    2222     */ 
    2323    protected $annotationName; 
     24    /** 
     25     * a list of reflected class instances used in the annotation 
     26     *  
     27     * This property should only be used by this class. We can not make this 
     28     * property private because the serializung mechanism will not work then. 
     29     * 
     30     * @var  array<string,string> 
     31     */ 
     32    protected $reflectedClasses = array(); 
    2433 
    2534    /** 
     
    4958    { 
    5059        foreach (get_object_vars($this) as $name => $value) { 
    51             if (is_object($value) == true && $value instanceof stubClonable) { 
     60            if ($value instanceof stubClonable) { 
    5261                $this->$name = clone $this->$name; 
    5362            } 
    5463        } 
    5564    } 
     65 
     66    /** 
     67     * store only the names of the property and the reflected class names, 
     68     * not the reflection class itself because it can not be serialized 
     69     * 
     70     * @return  array<string> 
     71     */ 
     72    public function __sleep() 
     73    { 
     74        $propertiesToSerialize = array(); 
     75        foreach (get_object_vars($this) as $name => $value) { 
     76            if ($value instanceof stubReflectionClass) { 
     77                $this->reflectedClasses[$name] = $value->getFullQualifiedClassName(); 
     78            } else { 
     79                $propertiesToSerialize[] = $name; 
     80            } 
     81        } 
     82         
     83        return $propertiesToSerialize; 
     84    } 
     85 
     86    /** 
     87     * restore all properties containing an instance of a reflection class 
     88     */ 
     89    public function __wakeup() 
     90    { 
     91        foreach ($this->reflectedClasses as $propertyName => $reflectedClasses) { 
     92            $this->$propertyName = new stubReflectionClass($reflectedClasses); 
     93        } 
     94         
     95        $this->reflectedClasses = array(); 
     96    } 
    5697} 
    5798?> 
  • trunk/src/test/runIntegration.php

    r589 r725  
    3131        $testSuite = new TestSuite('All tests.'); 
    3232         
     33        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/AnnotationTestCase.php'); 
    3334        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/DatabaseTestCase.php'); 
    3435        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/InterceptorTestCase.php');