Changeset 498

Show
Ignore:
Timestamp:
04/13/07 16:21:22 (2 years ago)
Author:
mikey
Message:

ensure that there is always a non-qualified class name available

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/stubSerializedObject.php

    r407 r498  
    2222     * @var  string 
    2323     */ 
    24     protected $className; 
     24    protected $fqClassName; 
     25    /** 
     26     * non qualified class name 
     27     * 
     28     * @var  string 
     29     */ 
     30    protected $nqClassName; 
    2531    /** 
    2632     * the instance of the serialized class 
     
    4955    public function __construct(stubObject $object) 
    5056    { 
    51         $this->className     = $object->getClassName(); 
     57        $this->fqClassName = $object->getClassName(); 
     58        if (null != $this->fqClassName) { 
     59            $this->nqClassName = stubClassLoader::getNonQualifiedClassName($this->fqClassName); 
     60        } else { 
     61            $this->nqClassName = get_class($object); 
     62        } 
     63         
    5264        $this->classInstance = $object; 
    5365        $this->hashCode      = $object->hashCode(); 
     
    6274    { 
    6375        $this->data = serialize($this->classInstance); 
    64         return array('className', 'hashCode', 'data'); 
     76        return array('fqClassName', 'nqClassName', 'hashCode', 'data'); 
    6577    } 
    6678     
     
    7890        } 
    7991         
    80         $nqClassName = stubClassLoader::getNonQualifiedClassName($this->className); 
    81         if (class_exists($nqClassName, false) == false) { 
    82             stubClassLoader::load($this->className); 
     92        if (class_exists($this->nqClassName, false) == false) { 
     93            stubClassLoader::load($this->fqClassName); 
    8394        } 
    8495         
     
    94105    public function getSerializedClassName() 
    95106    { 
    96         return $this->className; 
     107        return $this->fqClassName; 
    97108    } 
    98109 
     
    117128    public function getClassName() 
    118129    { 
    119         return stubClassLoader::getFullQualifiedClassName(get_class($this)); 
     130        return stubClassLoader::getFullQualifiedClassName(__CLASS__); 
    120131    } 
    121132     
     
    155166    { 
    156167        // do not throw a stubException to prevent cirular references 
    157         throw new Exception('Can not serialize a serialized ' . $this->getClassName() . ' representation of ' . $this->className); 
     168        throw new Exception('Can not serialize a serialized ' . $this->getClassName() . ' representation of ' . $this->fqClassName); 
    158169    } 
    159170     
     
    177188    { 
    178189        $string  = $this->getClassName() . " {\n"; 
    179         $string .= '    class(string): ' . $this->className . "\n"; 
     190        $string .= '    fqClassName(string): ' . $this->fqClassName . "\n"; 
     191        $string .= '    nqClassName(string): ' . $this->nqClassName . "\n"; 
    180192        $string .= '    data(string): ' . serialize($this->classInstance) . "\n"; 
    181193        $string .= "}\n"; 
  • trunk/src/test/php/net/stubbles/stubSerializedObjectTestCase.php

    r407 r498  
    116116    public function testToString() 
    117117    { 
    118         $this->assertEqual((string) $this->serializedObject, "net.stubbles.stubSerializedObject {\n    class(string): test.stub3stubBaseObject\n    data(string): " . serialize($this->stubBaseObject) . "\n}\n"); 
     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"); 
    119119    } 
    120120