Changeset 12
- Timestamp:
- 08/27/06 00:32:20 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/XJConf/converters/factories/ValueConverterFactoryChain.php
r6 r12 1 1 <?php 2 /** 3 * Factory to create the correct ValueConverterFactory. 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 2 8 XJConfLoader::load('converters.factories.ValueConverterFactory', 3 9 'converters.factories.PrimitiveValueConverterFactory', 10 'converters.factories.ArrayValueConverterFactory', 4 11 'converters.factories.ObjectValueConverterFactory', 5 'converters.factories.FactoryMethodValueConverterFactory'); 6 7 class ValueConverterFactoryChain { 12 'converters.factories.FactoryMethodValueConverterFactory', 13 'definitions.Definition' 14 ); 15 /** 16 * Factory to create the correct ValueConverterFactory. 17 * 18 * @package XJConf 19 * @subpackage converters 20 */ 21 class ValueConverterFactoryChain 22 { 23 /** 24 * contains a list of all available ValueConverterFactorys 25 * 26 * @var array<ValueConverterFactory> 27 */ 8 28 private static $factories = array(); 9 10 public static function push(ValueConverterFactory $factory) { 29 30 /** 31 * add a ValueConverterFactory to list of known ValueConverterFactorys 32 * 33 * @param ValueConverterFactory $factory 34 */ 35 public static function push(ValueConverterFactory $factory) 36 { 11 37 array_push(self::$factories, $factory); 12 38 } 13 14 public static function getFactory(Definition $def) { 39 40 /** 41 * return the correct ValueConverterFactory depending on the given definition 42 * 43 * @param Definition $def 44 * @return ValueConverterFactory 45 */ 46 public static function getFactory(Definition $def) 47 { 15 48 foreach (self::$factories as $factory) { 16 if ($factory->isResponsible($def) ) {49 if ($factory->isResponsible($def) == true) { 17 50 return $factory; 18 51 } 19 52 } 53 20 54 return null; 21 55 } 22 56 23 57 } 24 58 // initialize the ValueConverterFactoryChain 25 59 ValueConverterFactoryChain::push(new PrimitiveValueConverterFactory()); 60 ValueConverterFactoryChain::push(new ArrayValueConverterFactory()); 26 61 ValueConverterFactoryChain::push(new ObjectValueConverterFactory()); 27 62 ValueConverterFactoryChain::push(new FactoryMethodValueConverterFactory());
