Changeset 12

Show
Ignore:
Timestamp:
08/27/06 00:32:20 (2 years ago)
Author:
mikey
Message:

added first draft for ArrayValueConverter?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/XJConf/converters/factories/ValueConverterFactoryChain.php

    r6 r12  
    11<?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 */ 
    28XJConfLoader::load('converters.factories.ValueConverterFactory', 
    39                   'converters.factories.PrimitiveValueConverterFactory', 
     10                   'converters.factories.ArrayValueConverterFactory', 
    411                   '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 */ 
     21class ValueConverterFactoryChain 
     22
     23    /** 
     24     * contains a list of all available ValueConverterFactorys 
     25     * 
     26     * @var  array<ValueConverterFactory> 
     27     */ 
    828    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    { 
    1137        array_push(self::$factories, $factory); 
    1238    } 
    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    { 
    1548        foreach (self::$factories as $factory) { 
    16             if ($factory->isResponsible($def)) { 
     49            if ($factory->isResponsible($def) == true) { 
    1750                return $factory; 
    1851            } 
    1952        } 
     53         
    2054        return null; 
    2155    } 
    2256 
    2357} 
    24  
     58// initialize the ValueConverterFactoryChain 
    2559ValueConverterFactoryChain::push(new PrimitiveValueConverterFactory()); 
     60ValueConverterFactoryChain::push(new ArrayValueConverterFactory()); 
    2661ValueConverterFactoryChain::push(new ObjectValueConverterFactory()); 
    2762ValueConverterFactoryChain::push(new FactoryMethodValueConverterFactory());