Changeset 90

Show
Ignore:
Timestamp:
02/15/07 15:49:13 (2 years ago)
Author:
mikey
Message:

bugfix: need to change concrete tag definition class in case a ConcreteTagDefinition? extends an AbstractTagDefinition? and vice versa
replaced tabs

Files:

Legend:

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

    r86 r90  
    2929     * @var  string 
    3030     */ 
    31        protected  $name           = null; 
    32        /** 
     31    protected  $name           = null; 
     32    /** 
    3333     * the name of the tag 
    3434     * 
    3535     * @var  string 
    3636     */ 
    37        protected $tagName        = null; 
    38        /** 
     37    protected $tagName        = null; 
     38    /** 
    3939     * type of the tag 
    4040     * 
    4141     * @var  string 
    4242     */ 
    43        protected $type           = null; 
    44        /** 
     43    protected $type           = null; 
     44    /** 
    4545     * list of attribute definitions 
    4646     * 
    4747     * @var  array<AttributeDefinition> 
    4848     */ 
    49        protected $atts           = array(); 
    50        /** 
     49    protected $atts           = array(); 
     50    /** 
    5151     * name of the setter 
    5252     * 
    5353     * @var  string 
    5454     */ 
    55        protected $setter         = null; 
    56        /** 
    57         * name of attribute that contains the name 
    58        
    59         * @var  string 
    60         */ 
    61        protected $nameAttribute  = null; 
    62        /** 
    63         * definition of how to construct the object 
    64        
    65         * @var  ConstructorDefinition 
    66         */ 
     55    protected $setter         = null; 
     56    /** 
     57    * name of attribute that contains the name 
     58   
     59    * @var  string 
     60    */ 
     61    protected $nameAttribute  = null; 
     62    /** 
     63    * definition of how to construct the object 
     64   
     65    * @var  ConstructorDefinition 
     66    */ 
    6767    protected $constructor    = null; 
    6868    /** 
     
    8484     * @todo  Eventually call the setter method for the cdata 
    8585     */ 
    86        protected $cdata          = null; 
    87        /** 
    88         * the class loader to use 
    89        
    90         * @var  XJConfClassLoader 
    91         */ 
    92        protected $classLoader    = null; 
    93        /** 
    94         * list of simple types where the class loader can not be applied to 
    95        
    96         * @var  array<string> 
    97         */ 
    98        protected $simpleTypes    = array('boolean', 'bool', 'integer', 'int', 'double', 'float', 'string', 'array'); 
    99        /** 
    100         * Whether the calls should be made statically or not 
    101        
    102         * @var  boolean 
    103         */ 
    104        protected $static = false; 
    105  
    106        /** 
    107         * set the name of the value 
    108        
    109         * @param  string  $name 
    110         */ 
    111        public function setName($name) 
    112        
    113                $this->name = $name; 
    114        
    115  
    116        /** 
    117         * get the name of the value 
    118        
    119         * @return  string 
    120         */ 
    121        public function getName() 
    122        
    123                return $this->name; 
    124        
    125  
    126        /** 
    127         * Set the type of the tag 
    128        
    129         * @param  string  $type 
    130         */ 
    131        public function setType($type) 
    132        
    133                $this->type = $type; 
    134        
    135  
    136        /** 
    137         * get the type of the tag 
    138        
    139         * @return  string 
    140         */ 
    141        public function getType() 
    142        
    143            if (null != $this->classLoader) { 
    144                return $this->classLoader->getType($this->type); 
    145            } 
    146  
    147                return $this->type; 
    148        
    149  
    150        /** 
    151         * Set whether calls should be made statically (true) 
    152         * or an instance of the class should be created (false) 
    153        
    154         * @param boolean $static 
    155         */ 
    156        public function setStatic($static) { 
    157            $this->static = $static; 
    158        
    159  
    160        /** 
    161         * get the type of the tag 
    162        
    163         * @return  string 
    164         */ 
    165        public function isStatic() 
    166        
    167                return $this->static; 
    168        
    169  
    170        /** 
    171         * Convert the value of the tag. 
    172        
    173         * @param   Tag    $tag  tag that will be converted 
    174         * @return  mixed  converted value 
    175         * @throws  ValueConversionException 
    176         */ 
    177        public function convertValue(Tag $tag) 
    178     { 
    179                // get the data 
    180                $data = $tag->getContent(); 
    181                if (null == $data) { 
    182                        $data = ''; 
    183                
     86    protected $cdata          = null; 
     87    /** 
     88    * the class loader to use 
     89   
     90    * @var  XJConfClassLoader 
     91    */ 
     92    protected $classLoader    = null; 
     93    /** 
     94    * list of simple types where the class loader can not be applied to 
     95   
     96    * @var  array<string> 
     97    */ 
     98    protected $simpleTypes    = array('boolean', 'bool', 'integer', 'int', 'double', 'float', 'string', 'array'); 
     99    /** 
     100    * Whether the calls should be made statically or not 
     101   
     102    * @var  boolean 
     103    */ 
     104    protected $static = false; 
     105 
     106    /** 
     107    * set the name of the value 
     108   
     109    * @param  string  $name 
     110    */ 
     111    public function setName($name) 
     112   
     113        $this->name = $name; 
     114   
     115 
     116    /** 
     117    * get the name of the value 
     118   
     119    * @return  string 
     120    */ 
     121    public function getName() 
     122   
     123        return $this->name; 
     124   
     125 
     126    /** 
     127    * Set the type of the tag 
     128   
     129    * @param  string  $type 
     130    */ 
     131    public function setType($type) 
     132   
     133        $this->type = $type; 
     134   
     135 
     136    /** 
     137    * get the type of the tag 
     138   
     139    * @return  string 
     140    */ 
     141    public function getType() 
     142   
     143        if (null != $this->classLoader) { 
     144            return $this->classLoader->getType($this->type); 
     145        } 
     146 
     147        return $this->type; 
     148   
     149 
     150    /** 
     151    * Set whether calls should be made statically (true) 
     152    * or an instance of the class should be created (false) 
     153   
     154    * @param boolean $static 
     155    */ 
     156    public function setStatic($static) { 
     157        $this->static = $static; 
     158   
     159 
     160    /** 
     161    * get the type of the tag 
     162   
     163    * @return  string 
     164    */ 
     165    public function isStatic() 
     166   
     167        return $this->static; 
     168   
     169 
     170    /** 
     171    * Convert the value of the tag. 
     172   
     173    * @param   Tag    $tag  tag that will be converted 
     174    * @return  mixed  converted value 
     175    * @throws  ValueConversionException 
     176    */ 
     177    public function convertValue(Tag $tag) 
     178    { 
     179        // get the data 
     180        $data = $tag->getContent(); 
     181        if (null == $data) { 
     182            $data = ''; 
     183       
    184184 
    185185        // no constructor definition has been set, 
     
    191191 
    192192        $instance = $this->getValueConverter()->convertValue($tag, $this); 
    193                return $instance; 
    194        
    195  
    196        /** 
     193        return $instance; 
     194   
     195 
     196    /** 
    197197     * Get the type of the tag 
    198198     * 
     
    205205 
    206206    /** 
    207         * Set the setter method 
    208        
    209         * @param  string  $setter  name of the setter method 
    210         */ 
    211        public function setSetterMethod($setter) 
    212        
    213                $this->setter = $setter; 
    214        
    215  
    216        /** 
    217         * Get the name of the setter method that should be used 
    218        
    219         * @return  string 
    220         */ 
    221        public function getSetterMethod(Tag $tag) 
    222        
    223                if (null != $this->setter) { 
    224                        return $this->setter; 
    225                
    226  
    227                // no name, the parent should be a collection 
    228                if ('__none' == $this->name) { 
    229                        return null; 
    230                
    231  
    232                return 'set' . ucfirst($this->getKey($tag)); 
    233        
     207    * Set the setter method 
     208   
     209    * @param  string  $setter  name of the setter method 
     210    */ 
     211    public function setSetterMethod($setter) 
     212   
     213        $this->setter = $setter; 
     214   
     215 
     216    /** 
     217    * Get the name of the setter method that should be used 
     218   
     219    * @return  string 
     220    */ 
     221    public function getSetterMethod(Tag $tag) 
     222   
     223        if (null != $this->setter) { 
     224            return $this->setter; 
     225       
     226 
     227        // no name, the parent should be a collection 
     228        if ('__none' == $this->name) { 
     229            return null; 
     230       
     231 
     232        return 'set' . ucfirst($this->getKey($tag)); 
     233   
    234234 
    235235    /** 
     
    332332    } 
    333333 
    334         /** 
    335          * Add an attribute to the tag 
    336          * 
    337          * @param  AttributeDefinition  $att 
    338          */ 
    339         public function addAttribute(AttributeDefinition $att) 
    340         { 
    341                 array_push($this->atts, $att); 
    342         } 
    343  
    344         /** 
    345          * Return list of attributes for this tag 
    346          * 
    347          * @return  array 
    348          */ 
    349         public function getAttributes() { 
    350             return $this->atts; 
    351         } 
    352  
    353         /** 
    354          * Set the name of the tag 
    355          * 
    356          * @param name 
    357          */ 
    358         public function setTagName($name) 
    359         { 
    360                 $this->tagName = $name; 
    361         } 
    362  
    363         /** 
    364          * Set the attribute that will be used as key. 
    365      * 
    366          * @return   name of the value 
    367          */ 
    368         public function setKeyAttribute($att) 
    369         { 
     334    /** 
     335     * Add an attribute to the tag 
     336     * 
     337     * @param  AttributeDefinition  $att 
     338     */ 
     339    public function addAttribute(AttributeDefinition $att) 
     340    { 
     341        array_push($this->atts, $att); 
     342    } 
     343 
     344    /** 
     345     * Return list of attributes for this tag 
     346     * 
     347     * @return  array 
     348     */ 
     349    public function getAttributes() 
     350    { 
     351        return $this->atts; 
     352    } 
     353 
     354    /** 
     355     * Set the name of the tag 
     356     * 
     357     * @param name 
     358     */ 
     359    public function setTagName($name) 
     360    { 
     361        $this->tagName = $name; 
     362    } 
     363 
     364    /** 
     365     * Set the attribute that will be used as key. 
     366     * 
     367     * @return   name of the value 
     368     */ 
     369    public function setKeyAttribute($att) 
     370    { 
    370371        $this->name          = '__attribute'; 
    371                $this->nameAttribute = $att; 
    372        
    373  
    374        /** 
    375         * get the name of the tag 
    376        
    377         * @return  string 
    378         */ 
    379        public function getTagName() 
    380        
    381                return $this->tagName; 
    382        
    383  
    384        /** 
    385         * get the name of the tag 
    386        
    387         * @return  string 
    388         */ 
    389        public function getKey(DefinedTag $tag) 
    390        
    391                if ('__attribute' == $this->name) { 
    392                return $tag->getAttribute($this->nameAttribute); 
     372        $this->nameAttribute = $att; 
     373   
     374 
     375    /** 
     376    * get the name of the tag 
     377   
     378    * @return  string 
     379    */ 
     380    public function getTagName() 
     381   
     382        return $this->tagName; 
     383   
     384 
     385    /** 
     386    * get the name of the tag 
     387   
     388    * @return  string 
     389    */ 
     390    public function getKey(DefinedTag $tag) 
     391   
     392        if ('__attribute' == $this->name) { 
     393            return $tag->getAttribute($this->nameAttribute); 
    393394        } 
    394395 
    395396        return $this->name; 
    396        
     397   
    397398 
    398399    /** 
    399400     * Check, whether the value supports indexed children 
    400401     * 
    401      * @return  boolean 
    402      */ 
    403         public function supportsIndexedChildren() 
    404         { 
    405                 if ($this->getType() == 'array') { 
    406                         return true; 
    407                 } 
    408  
    409                 return false; 
    410         } 
    411  
    412         /** 
    413          * set the class loader for this tag 
    414          * 
    415          * @param  XJConfClassLoader  $classLoader 
    416          */ 
    417         public function setClassLoader(XJConfClassLoader $classLoader) 
    418         { 
    419             $this->classLoader = $classLoader; 
    420         } 
     402     * @return  boolean 
     403     */ 
     404    public function supportsIndexedChildren() 
     405    { 
     406        if ($this->getType() == 'array') { 
     407            return true; 
     408        } 
     409 
     410        return false; 
     411    } 
     412 
     413    /** 
     414     * set the class loader for this tag 
     415     * 
     416     * @param  XJConfClassLoader  $classLoader 
     417     */ 
     418    public function setClassLoader(XJConfClassLoader $classLoader) 
     419    { 
     420        $this->classLoader = $classLoader; 
     421    } 
     422     
     423    /** 
     424     * extends itsself from another tag definition 
     425     *  
     426     * @param  TagDefinition  $tagDefinition  the tag definition to extend from 
     427     */ 
     428    public function extend(self $tagDefinition) 
     429    { 
     430        $this->atts = $tagDefinition->getAttributes(); 
     431        $childDefs  = $tagDefinition->getChildDefinitions(); 
     432        foreach ($childDefs as $childDef) { 
     433            $this->addChildDefinition($childDef); 
     434        } 
     435    } 
    421436 
    422437    /** 
     
    432447 
    433448        if (null != $this->classLoader && in_array($this->type, $this->simpleTypes) == false) { 
    434                    $this->classLoader->loadClass($this->type); 
    435                
     449            $this->classLoader->loadClass($this->type); 
     450       
    436451 
    437452        if (null == $this->valueConverter) { 
  • trunk/XJConf/definitions/handler/AbstractTagDefinitionHandler.php

    r77 r90  
    4848        // ensure that the name has been set 
    4949        if (isset($atts['name']) == false) { 
    50                throw new InvalidTagDefinitionException('The <abstractTag> tag is missing the name attribute.'); 
     50            throw new InvalidTagDefinitionException('The <abstractTag> tag is missing the name attribute.'); 
    5151        } 
    5252 
    5353        if (isset($atts['abstractType']) == false) { 
    54                throw new InvalidTagDefinitionException('The <abstractTag> tag is missing the abstractType attribute.'); 
     54            throw new InvalidTagDefinitionException('The <abstractTag> tag is missing the abstractType attribute.'); 
    5555        } 
    5656 
    5757        if (isset($atts['concreteTypeAttribute']) == false) { 
    58                throw new InvalidTagDefinitionException('The <abstractTag> tag is missing the concreteTypeAttribute attribute.'); 
     58            throw new InvalidTagDefinitionException('The <abstractTag> tag is missing the concreteTypeAttribute attribute.'); 
    5959        } 
    6060 
     
    6363            $nsDef = $this->defParser->getNamespaceDefinitions()->getNamespaceDefinition($this->defParser->getCurrentNamespace()); 
    6464            $extendedDef = $nsDef->getDefinition($atts['extends']); 
    65                 $def = clone $extendedDef; 
    66                 $def->setName($atts['name']); 
    67                 $def->setTagName($atts['name']); 
    68             if (null == $atts['type']) { 
    69                 $def->setType($atts['type']); 
     65            if ($extendedDef instanceof AbstractTagDefinition) { 
     66                $def = clone $extendedDef; 
     67                $def->setName($atts['name']); 
     68                $def->setTagName($atts['name']); 
     69            } else { 
     70                $def = new AbstractTagDefinition($atts['name'], $atts['abstractType'], $atts['concreteTypeAttribute']); 
     71                $def->extend($extendedDef); 
    7072            } 
    7173        } else { 
    72                $def = new AbstractTagDefinition($atts['name'], $atts['abstractType'], $atts['concreteTypeAttribute']); 
     74            $def = new AbstractTagDefinition($atts['name'], $atts['abstractType'], $atts['concreteTypeAttribute']); 
    7375        } 
    7476 
  • trunk/XJConf/definitions/handler/ConcreteTagDefinitionHandler.php

    r77 r90  
    4848        // ensure that the name has been set 
    4949        if (isset($atts['name']) == false) { 
    50                throw new InvalidTagDefinitionException('The <tag> tag is missing the name attribute.'); 
     50            throw new InvalidTagDefinitionException('The <tag> tag is missing the name attribute.'); 
    5151        } 
    5252 
    5353        // 
    5454        if (isset($atts['type']) == false) { 
    55                $atts['type'] = $atts['primitive']; 
     55            $atts['type'] = $atts['primitive']; 
    5656        } 
    5757 
     
    6060            $nsDef = $this->defParser->getNamespaceDefinitions()->getNamespaceDefinition($this->defParser->getCurrentNamespace()); 
    6161            $extendedDef = $nsDef->getDefinition($atts['extends']); 
    62                 $def = clone $extendedDef; 
    63                 $def->setName($atts['name']); 
    64                 $def->setTagName($atts['name']); 
    65             if (null == $atts['type']) { 
    66                 $def->setType($atts['type']); 
     62            if ($extendedDef instanceof ConcreteTagDefinition) { 
     63                $def = clone $extendedDef; 
     64                $def->setName($atts['name']); 
     65                $def->setTagName($atts['name']); 
     66                if (null == $atts['type']) { 
     67                    $def->setType($atts['type']); 
     68                } 
     69            } else { 
     70                $def = new ConcreteTagDefinition($atts['name'], $atts['type']); 
     71                $def->extend($extendedDef); 
    6772            } 
    6873        } else { 
    69                // Create a definition from scratch 
    70                if (null == $atts['type']) { 
    71                        $atts['type'] = 'string'; 
    72               
     74            // Create a definition from scratch 
     75            if (null == $atts['type']) { 
     76                $atts['type'] = 'string'; 
     77           
    7378 
    74                $def = new ConcreteTagDefinition($atts['name'], $atts['type']); 
     79            $def = new ConcreteTagDefinition($atts['name'], $atts['type']); 
    7580        } 
    7681