Changeset 529
- Timestamp:
- 04/14/07 22:29:04 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/xml/stubXMLStreamWriter.php
r428 r529 16 16 interface stubXMLStreamWriter { 17 17 18 /**19 * Is able to import an stubXMLStreamWriter20 *21 * @var int22 */23 const FEATURE_IMPORT_WRITER = 1;24 25 /**26 * Is able to export as DOM27 *28 * @var int29 */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 32 32 /** 33 33 * Create a new writer … … 45 45 */ 46 46 public function hasFeature($feature); 47 47 48 48 /** 49 49 * Clear all data, that has been written trunk/src/main/php/net/stubbles/xml/stubXMLStreamWriterFactory.php
r293 r529 45 45 /** 46 46 * creates a xml stream writer depending on available xml extensions 47 * 47 * 48 48 * If an order is submitted it will use this order, else it uses the default order. 49 49 * 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 51 52 * @return stubXMLStreamWriter 52 53 */ 53 public static function createAsAvailable(array $order = null )54 public static function createAsAvailable(array $order = null, $features = array()) 54 55 { 55 56 if (null == $order) { 56 57 $order = array_keys(self::$types); 57 58 } 58 59 59 60 foreach ($order as $xmlExtension) { 60 61 if (extension_loaded($xmlExtension) == true) { 61 62 if (isset(self::$types[$xmlExtension]) == true) { 62 return self::create(self::$types[$xmlExtension]); 63 $name = self::$types[$xmlExtension]; 64 } else { 65 $name = $xmlExtension; 63 66 } 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; 66 74 } 67 75 } 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!'); 70 78 } 71 79 } trunk/src/test/php/net/stubbles/xml/stubXMLStreamWriterFactoryTestCase.php
r293 r529 35 35 $this->assertIsA(stubXMLStreamWriterFactory::createAsAvailable(), 'stubDomXMLStreamWriter'); 36 36 $this->assertIsA(stubXMLStreamWriterFactory::createAsAvailable(array('xmlwriter', 'Dom')), 'stubLibXmlXMLStreamWriter'); 37 $this->assertIsA(stubXMLStreamWriterFactory::createAsAvailable(array('xmlwriter', 'Dom'), array(stubXMLStreamWriter::FEATURE_IMPORT_WRITER)), 'stubDomXMLStreamWriter'); 37 38 $this->expectException('stubXMLException'); 38 39 stubXMLStreamWriterFactory::createAsAvailable(array('ExtensionDoesNotExist'));
