Changeset 1062

Show
Ignore:
Timestamp:
11/22/07 21:55:55 (11 months ago)
Author:
schst
Message:

Fixed bug #108

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php

    r730 r1062  
    3636 
    3737    /** 
     38     * Option to define the strategy 
     39     */ 
     40    const OPT_STATIC      = 'static'; 
     41 
     42    /** 
    3843     * Do not export any properties or methods 
    3944     */ 
     
    6267    private $defaultOpts = array( 
    6368                      self::OPT_ROOT_TAG    => null, 
    64                       self::OPT_STRATEGY    => self::STRATEGY_ALL 
     69                      self::OPT_STRATEGY    => self::STRATEGY_ALL, 
     70                      self::OPT_STATIC      => false 
    6571                    ); 
    6672 
     
    214220                        continue; 
    215221                    } 
     222                    if ($property->isStatic() && $this->opts[self::OPT_STATIC] === false) { 
     223                        continue; 
     224                    } 
    216225                    $tagName = $property->getName(); 
    217226                } 
     
    287296                        continue; 
    288297                    } 
     298                    if ($method->isStatic() && $this->opts[self::OPT_STATIC] === false) { 
     299                        continue; 
     300                    } 
     301 
    289302                    $tagName = $method->getName(); 
    290303                } 
  • trunk/src/test/php/net/stubbles/xml/serializer/stubXMLSerializerTestCase.php

    r1017 r1062  
    232232 
    233233} 
     234 
     235/** 
     236 * Simple Test class to test the XMLSerializer and static properties/methods 
     237 */ 
     238class stubXMLSerializerTestCase_Static { 
     239    public static $foo = 'foo'; 
     240 
     241    public static function getBar() { 
     242        return 'bar'; 
     243    } 
     244} 
     245 
    234246 
    235247/** 
     
    422434 
    423435    /** 
     436     * Test serializing an object with static properties and methods 
     437     */ 
     438    public function testObjectStatic() { 
     439        $writer = new stubDomXMLStreamWriter(); 
     440        $obj = new stubXMLSerializerTestCase_Static(); 
     441        $this->serializer->serialize($obj, $writer, array(stubXMLSerializer::OPT_STATIC => true)); 
     442        $this->assertEqual('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<stubXMLSerializerTestCase_Static><foo>foo</foo><getBar>bar</getBar></stubXMLSerializerTestCase_Static>', $writer->asXML()); 
     443 
     444        $writer = new stubDomXMLStreamWriter(); 
     445        $this->serializer->serialize($obj, $writer); 
     446        $this->assertEqual('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<stubXMLSerializerTestCase_Static/>', $writer->asXML()); 
     447    } 
     448 
     449    /** 
    424450     * Test serializing an object with umlauts 
    425451     */