Changeset 529

Show
Ignore:
Timestamp:
04/14/07 22:29:04 (1 year ago)
Author:
schst
Message:

Added ability to request features when creating an XMLStreamWriter via the factory (closes ticket #26), whitespace fixes

Files:

Legend:

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

    r428 r529  
    1616interface stubXMLStreamWriter { 
    1717 
    18    /** 
    19     * Is able to import an stubXMLStreamWriter 
    20    
    21     * @var int 
    22     */ 
    23    const FEATURE_IMPORT_WRITER = 1; 
    24      
    25    /** 
    26     * Is able to export as DOM 
    27    
    28     * @var int 
    29     */ 
    30    const FEATURE_AS_DOM = 2; 
    31          
     18    /** 
     19    * Is able to import an stubXMLStreamWriter 
     20   
     21    * @var int 
     22    */ 
     23    const FEATURE_IMPORT_WRITER = 1; 
     24 
     25    /** 
     26    * Is able to export as DOM 
     27   
     28    * @var int 
     29    */ 
     30    const FEATURE_AS_DOM = 2; 
     31 
    3232    /** 
    3333     * Create a new writer 
     
    4545     */ 
    4646    public function hasFeature($feature); 
    47          
     47 
    4848    /** 
    4949     * Clear all data, that has been written 
  • trunk/src/main/php/net/stubbles/xml/stubXMLStreamWriterFactory.php

    r293 r529  
    4545    /** 
    4646     * creates a xml stream writer depending on available xml extensions 
    47      *  
     47     * 
    4848     * If an order is submitted it will use this order, else it uses the default order. 
    4949     * 
    50      * @param   array                $order  optional  extensions in order to use 
     50     * @param   array                $order     optional  extensions in order to use 
     51     * @param   array                $features  optional  features the implementation must provide 
    5152     * @return  stubXMLStreamWriter 
    5253     */ 
    53     public static function createAsAvailable(array $order = null
     54    public static function createAsAvailable(array $order = null, $features = array()
    5455    { 
    5556        if (null == $order) { 
    5657            $order = array_keys(self::$types); 
    5758        } 
    58          
     59 
    5960        foreach ($order as $xmlExtension) { 
    6061            if (extension_loaded($xmlExtension) == true) { 
    6162                if (isset(self::$types[$xmlExtension]) == true) { 
    62                     return self::create(self::$types[$xmlExtension]); 
     63                    $name = self::$types[$xmlExtension]; 
     64                } else { 
     65                    $name = $xmlExtension; 
    6366                } 
    64                  
    65                 return self::create($xmlExtension); 
     67                $writer = self::create($name); 
     68                foreach ($features as $feature) { 
     69                    if (!$writer->hasFeature($feature)) { 
     70                        continue 2; 
     71                    } 
     72                } 
     73                return $writer; 
    6674            } 
    6775        } 
    68          
    69         throw new stubXMLException('Not any single xml extension available, can not create a xml stream writer!'); 
     76 
     77        throw new stubXMLException('Not any single xml extension available that provides the requested features, can not create a xml stream writer!'); 
    7078    } 
    7179} 
  • trunk/src/test/php/net/stubbles/xml/stubXMLStreamWriterFactoryTestCase.php

    r293 r529  
    3535       $this->assertIsA(stubXMLStreamWriterFactory::createAsAvailable(), 'stubDomXMLStreamWriter'); 
    3636       $this->assertIsA(stubXMLStreamWriterFactory::createAsAvailable(array('xmlwriter', 'Dom')), 'stubLibXmlXMLStreamWriter'); 
     37       $this->assertIsA(stubXMLStreamWriterFactory::createAsAvailable(array('xmlwriter', 'Dom'), array(stubXMLStreamWriter::FEATURE_IMPORT_WRITER)), 'stubDomXMLStreamWriter'); 
    3738       $this->expectException('stubXMLException'); 
    3839       stubXMLStreamWriterFactory::createAsAvailable(array('ExtensionDoesNotExist'));