Changeset 43

Show
Ignore:
Timestamp:
11/21/06 20:45:41 (2 years ago)
Author:
schst
Message:

New feature: It is now possible to use dynamic setter methods based on the value of an attribute of a tag.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/XJConf/DefinedTag.php

    r14 r43  
    249249    public function getSetterMethod() 
    250250    { 
    251         return $this->tagDef->getSetterMethod(); 
     251        return $this->tagDef->getSetterMethod($this); 
    252252    } 
    253253 
  • trunk/XJConf/converters/AbstractObjectValueConverter.php

    r29 r43  
    2323     */ 
    2424    protected $className; 
    25      
     25 
    2626    /** 
    2727     * Add all attributes using the appropriate setter methods 
     
    4545 
    4646            try { 
    47                 $method = $class->getMethod($att->getSetterMethod()); 
     47                $method = $class->getMethod($att->getSetterMethod($tag)); 
    4848                $method->invoke($instance, $val); 
    4949            } catch (ReflectionException $re) { 
  • trunk/XJConf/definitions/AttributeDefinition.php

    r29 r43  
    8585                } 
    8686        } 
    87          
     87 
    8888        /** 
    8989         * Get the name of the attribute. 
     
    9595                return $this->name; 
    9696        } 
    97          
     97 
    9898        /** 
    9999         * Get the type of the attribute 
     
    105105                return $this->type; 
    106106        } 
    107          
     107 
    108108        /** 
    109109         * Convert a value to the defined type 
     
    143143                return $instance; 
    144144        } 
    145          
     145 
    146146        /** 
    147147     * Get the type of the attribute 
     
    154154        return $this->valueConverter->getType(); 
    155155    } 
    156      
     156 
    157157    /** 
    158158         * Set the setter method 
     
    176176     * @see     setSetterMethod() 
    177177         */ 
    178         public function getSetterMethod(
     178        public function getSetterMethod(Tag $tag
    179179        { 
    180180                if (null == $this->setter) { 
     
    184184                return $this->setter; 
    185185        } 
    186      
     186 
    187187    /** 
    188188     * Add a child definition 
     
    196196        // attributes can not have any children. 
    197197    } 
    198      
     198 
    199199    /** 
    200200     * Checks whether this definition has a specific child condition 
     
    207207        return false; 
    208208    } 
    209      
     209 
    210210    /** 
    211211     * Returns the first found definition of type $def 
     
    262262        return $this->required; 
    263263    } 
    264      
     264 
    265265    /** 
    266266     * set if attribute is required 
     
    272272        $this->required = $required; 
    273273    } 
    274      
     274 
    275275    /** 
    276276     * Get the value converter for this tag 
     
    283283            $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 
    284284        } 
    285          
     285 
    286286        return $this->valueConverter; 
    287287    } 
  • trunk/XJConf/definitions/CDataDefinition.php

    r36 r43  
    5252        $this->type = $type; 
    5353    } 
    54      
     54 
    5555    /** 
    5656     * get the name under which the data will be stored 
     
    7272                return $this->type; 
    7373        } 
    74          
     74 
    7575    /** 
    7676     * Convert the character data to any type 
     
    115115     * @see     setSetterMethod() 
    116116     */ 
    117     public function getSetterMethod(
     117    public function getSetterMethod(Tag $tag
    118118    { 
    119119        return $this->setter; 
     
    129129        // Character data can not have any children. 
    130130    } 
    131          
     131 
    132132        /** 
    133133     * Checks whether this definition has a specific child condition 
     
    140140        return false; 
    141141    } 
    142      
     142 
    143143    /** 
    144144     * Returns the first found definition of type $def 
     
    164164        return array(); 
    165165    } 
    166      
     166 
    167167    /** 
    168168     * Get the value converter for this character data 
     
    175175            $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 
    176176        } 
    177          
     177 
    178178        return $this->valueConverter; 
    179179    } 
  • trunk/XJConf/definitions/ChildDefinition.php

    r21 r43  
    4444                return $this->name; 
    4545        } 
    46          
     46 
    4747        /** 
    4848         * get the type of the child 
     
    9494     * @return  null 
    9595     */ 
    96     public function getSetterMethod(
     96    public function getSetterMethod(Tag $tag
    9797    { 
    9898        return null; 
     
    108108        // Character data can not have any children. 
    109109    } 
    110      
     110 
    111111    /** 
    112112     * Checks whether this definition has a specific child condition 
     
    119119        return false; 
    120120    } 
    121      
     121 
    122122    /** 
    123123     * Returns the first found definition of type $def 
     
    143143    } 
    144144 
    145          
     145 
    146146} 
    147147?> 
  • trunk/XJConf/definitions/ConstructorDefinition.php

    r21 r43  
    2121     */ 
    2222    private $params = array(); 
    23      
     23 
    2424    /** 
    2525    * Get the name under which it will be stored 
     
    3131        return '__constructor'; 
    3232    } 
    33      
     33 
    3434    /** 
    3535         * get the type of the constructor 
     
    4141                return null; 
    4242        } 
    43          
     43 
    4444        /** 
    4545     * Convert the constructor. 
     
    6565        return null; 
    6666    } 
    67      
     67 
    6868    /** 
    6969     * Get the setter method 
     
    7171     * @return  null 
    7272     */ 
    73     public function getSetterMethod(
     73    public function getSetterMethod(Tag $tag
    7474    { 
    7575        return null; 
     
    8585        array_push($this->params, $def); 
    8686    } 
    87      
     87 
    8888    /** 
    8989     * Checks whether this definition has a specific child condition 
     
    9999            } 
    100100        } 
    101          
     101 
    102102        return false; 
    103103    } 
    104      
     104 
    105105    /** 
    106106     * Returns the first found definition of type $def 
     
    116116            } 
    117117        } 
    118          
     118 
    119119        return null; 
    120120    } 
    121      
     121 
    122122    /** 
    123123     * Return all child definitions. 
     
    149149        return $childrenNames; 
    150150    } 
    151      
     151 
    152152    /** 
    153153     * Get the parameters of the constructor 
  • trunk/XJConf/definitions/Definition.php

    r21 r43  
    2121     */ 
    2222        public function getName(); 
    23          
     23 
    2424        /** 
    2525     * Get the type of the definition 
     
    5151     * @return  string 
    5252     */ 
    53     public function getSetterMethod(); 
     53    public function getSetterMethod(Tag $tag); 
    5454 
    5555    /** 
     
    5959     */ 
    6060    public function addChildDefinition(Definition $def); 
    61      
     61 
    6262    /** 
    6363     * Checks whether this definition has a specific child condition 
     
    6767     */ 
    6868    public function hasChildDefinition($def); 
    69      
     69 
    7070    /** 
    7171     * Returns the first found definition of type $def 
     
    7575     */ 
    7676    public function getChildDefinition($def); 
    77      
     77 
    7878    /** 
    7979         * Get all child definitions of the definition 
  • trunk/XJConf/definitions/FactoryMethodDefinition.php

    r22 r43  
    4242                $this->name = $name; 
    4343        } 
    44          
     44 
    4545        /** 
    4646     * Get the name under which it will be stored 
     
    5252                return $this->name; 
    5353        } 
    54          
     54 
    5555        /** 
    5656         * get the type of the factory method 
     
    6262                return null; 
    6363        } 
    64          
     64 
    6565        /** 
    6666     * Convert the factory method. 
     
    8484                throw new UnsupportedOperationException(); 
    8585        } 
    86          
     86 
    8787        /** 
    8888     * Get the setter method 
     
    9090     * @throws  UnsupportedOperationException 
    9191     */ 
    92         public function getSetterMethod(
     92        public function getSetterMethod(Tag $tag
    9393        { 
    9494                throw new UnsupportedOperationException(); 
    9595        } 
    96          
     96 
    9797    /** 
    9898     * Add a new child definition (equals a parameter of the factory method) 
     
    104104        array_push($this->params, $def); 
    105105    } 
    106      
     106 
    107107    /** 
    108108     * Checks whether this definition has a specific child condition 
     
    118118            } 
    119119        } 
    120          
     120 
    121121        return false; 
    122122    } 
    123      
     123 
    124124    /** 
    125125     * Returns the first found definition of type $def 
     
    135135            } 
    136136        } 
    137          
     137 
    138138        return null; 
    139139    } 
    140      
     140 
    141141    /** 
    142142     * Return all child definitions. 
     
    147147        return $this->params; 
    148148    } 
    149      
     149 
    150150    /** 
    151151     * Get the names of all child elements that are used in 
     
    168168        return $childrenNames; 
    169169    } 
    170          
     170 
    171171    /** 
    172172     * Get the parameters of the factory method 
  • trunk/XJConf/definitions/TagDefinition.php

    r36 r43  
    105105                $this->setType($type); 
    106106        } 
    107          
     107 
    108108        /** 
    109109         * set the name of the value 
     
    115115                $this->name = $name; 
    116116        } 
    117          
     117 
    118118        /** 
    119119         * get the name of the value 
     
    135135                $this->type = $type; 
    136136        } 
    137          
     137 
    138138        /** 
    139139         * get the type of the tag 
     
    145145                return $this->type; 
    146146        } 
    147          
     147 
    148148        /** 
    149149         * Convert the value of the tag. 
     
    171171                return $instance; 
    172172        } 
    173          
     173 
    174174        /** 
    175175     * Get the type of the tag 
     
    181181        return $this->getValueConverter()->getType(); 
    182182    } 
    183      
     183 
    184184    /** 
    185185         * Set the setter method 
     
    197197         * @return  string 
    198198         */ 
    199         public function getSetterMethod(
     199        public function getSetterMethod(Tag $tag
    200200        { 
    201201                if (null != $this->setter) { 
     
    208208                } 
    209209 
    210                 return 'set' . ucfirst($this->name); 
     210                return 'set' . ucfirst($this->getKey($tag)); 
    211211        } 
    212212 
     
    244244        } 
    245245    } 
    246      
     246 
    247247    /** 
    248248     * Checks whether this definition has a specific child condition 
     
    259259            } 
    260260        } 
    261          
     261 
    262262        return false; 
    263263    } 
    264      
     264 
    265265    /** 
    266266     * Returns the first found definition of type $def 
     
    277277            } 
    278278        } 
    279          
     279 
    280280        return null; 
    281281    } 
    282      
     282 
    283283    /** 
    284284     * Return all child definitions. 
     
    313313                array_push($this->atts, $att); 
    314314        } 
    315      
     315 
    316316        /** 
    317317         * Return list of attributes for this tag 
     
    381381                return false; 
    382382        } 
    383      
     383 
    384384    /** 
    385385     * Get the value converter for this tag 
     
    392392            $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 
    393393        } 
    394          
     394 
    395395        return $this->valueConverter; 
    396396    } 
  • trunk/examples/Color.php

    r27 r43  
    22/** 
    33 * example class 
    4  *  
     4 * 
    55 * @author  Stephan Schmidt <stephan.schmidt@schlund.de> 
    66 * @author  Frank Kleine <frank.kleine@schlund.de> 
     
    88/** 
    99 * example class 
    10  *  
     10 * 
    1111 * @package     XJConf 
    1212 * @subpackage  examples 
     
    5050     * @var  string  $name  name of the color 
    5151     */ 
    52     public function  __construct($name
     52    public function  __construct($name = null
    5353    { 
    5454        $this->name = $name; 
    5555    } 
    56      
     56 
    5757    /** 
    5858     * set the red part 
     
    6464        $this->red = $val; 
    6565    } 
    66      
     66 
    6767    /** 
    6868     * set the green part 
     
    7474        $this->green = $val; 
    7575    } 
    76      
     76 
    7777    /** 
    7878     * set the blue part 
     
    8484        $this->blue = $val; 
    8585    } 
    86      
     86 
    8787    /** 
    8888     * set the title of the color 
     
    9494        $this->colorTitle = $title; 
    9595    } 
    96      
     96 
    9797    /** 
    9898     * get the rgb value as hex 
     
    104104        return '#' . dechex($this->red) . dechex($this->green) . dechex($this->blue); 
    105105    } 
    106      
     106 
    107107    /** 
    108108     * return the name of the color 
     
    114114        return $this->name; 
    115115    } 
    116      
     116 
    117117    /** 
    118118     * return the title of the color 
     
    124124        return $this->colorTitle; 
    125125    } 
    126      
     126 
    127127    /** 
    128128     * returns string representation 
    129      *  
     129     * 
    130130     * @return  string 
    131131     */ 
  • trunk/examples/TestAttributesRequired.php

    r35 r43  
    22/** 
    33 * Example that shows the effect of required attributes that have not been set. 
    4  *  
     4 * 
    55 * @author  Stephan Schmidt <stephan.schmidt@schlund.de> 
    66 * @author  Frank Kleine <frank.kleine@schlund.de> 
     
    1414/** 
    1515 * Example that shows the effect of required attributes that have not been set. 
    16  *  
     16 * 
    1717 * @package     XJConf 
    1818 * @subpackage  examples 
     
    2424        $tagParser = new DefinitionParser(); 
    2525        $defs      = $tagParser->parse(getcwd() . '/xml/defines-attributes-required.xml'); 
    26          
     26 
    2727        $conf      = new XmlParser(); 
    2828                try { 
     
    3232            var_dump($color); 
    3333        } catch (Exception $e) { 
    34             echo 'Catched expected Exception with message: "' . $e->getMessage() . '", showing trace: '; 
     34            echo 'Caught expected Exception with message: "' . $e->getMessage() . '", showing trace: '; 
    3535            var_dump($e->getTrace()); 
    3636            exit(0); 
    37         }         
     37        } 
    3838    } 
    3939}