Changeset 62

Show
Ignore:
Timestamp:
12/04/06 22:34:24 (2 years ago)
Author:
mikey
Message:

Cleaned mess with (Base)TagDefinition?: base is now TagDefinition?, while a new ConcreteTagDefinition? is introduced. For the sake of backward compatibility and usability the old definitions.handler.TagDefinitionHandler? has been kept and creates definitions.ConcreteTagDefinition?. This allows further usage of <tag> within xml defines which is equivalent to the use of <concreteTag>.

Files:

Legend:

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

    r61 r62  
    77 */ 
    88XJConfLoader::load('Tag', 
    9                    'definitions.BaseTagDefinition' 
     9                   'definitions.TagDefinition' 
    1010); 
    1111/** 
     
    5555         * value of the tag 
    5656         * 
    57          * @var  BaseTagDefinition 
     57         * @var  TagDefinition 
    5858         */ 
    5959        private $tagDef = null; 
     
    265265    * Set the tag definition object used for this tag 
    266266    * 
    267     * @param  BaseTagDefinition  $tagDef 
     267    * @param  TagDefinition  $tagDef 
    268268    */ 
    269     public function setDefinition(BaseTagDefinition $tagDef) 
    270     { 
    271         if ($tagDef instanceof TagDefinition) { 
     269    public function setDefinition(TagDefinition $tagDef) 
     270    { 
     271        if ($tagDef instanceof ConcreteTagDefinition) { 
    272272                $this->tagDef = $tagDef; 
    273273            return; 
     
    281281     * get the tag definition object used for this tag 
    282282     * 
    283      * @return  BaseTagDefinition 
     283     * @return  TagDefinition 
    284284     */ 
    285285    public function getDefinition() 
  • trunk/XJConf/converters/AbstractObjectValueConverter.php

    r61 r62  
    2727     * Add all attributes using the appropriate setter methods 
    2828     * 
    29      * @param   Tag                $tag 
    30      * @param   BaseTagDefinition  $def 
    31      * @param   object             $instance 
     29     * @param   Tag            $tag 
     30     * @param   TagDefinition  $def 
     31     * @param   object         $instance 
    3232     * @throws  ValueConversionException 
    3333     */ 
    34     protected function addAttributesToValue(Tag $tag, BaseTagDefinition $def, $instance) 
     34    protected function addAttributesToValue(Tag $tag, TagDefinition $def, $instance) 
    3535    { 
    3636        $class = new ReflectionClass(get_class($instance)); 
  • trunk/XJConf/converters/ArrayValueConverter.php

    r61 r62  
    77XJConfLoader::load('converters.ValueConverter', 
    88                   'definitions.Definition', 
    9                    'definitions.BaseTagDefinition' 
     9                   'definitions.TagDefinition' 
    1010); 
    1111/** 
     
    4444     * Add all attributes using the appropriate setter methods 
    4545     * 
    46      * @param   Tag         $tag 
    47      * @param   Definition  $def 
    48      * @param   array       $array 
     46     * @param   Tag            $tag 
     47     * @param   TagDefinition  $def 
     48     * @param   array          $array 
    4949     */ 
    50     protected function addAttributesToValue(Tag $tag, BaseTagDefinition $def, $array) 
     50    protected function addAttributesToValue(Tag $tag, TagDefinition $def, $array) 
    5151    { 
    5252        // set all attributes 
  • trunk/XJConf/converters/ConstructorValueConverter.php

    r61 r62  
    7070 
    7171        // add attributes and child elements 
    72         if ($def instanceof BaseTagDefinition) { 
     72        if ($def instanceof TagDefinition) { 
    7373            $this->addAttributesToValue($tag, $def, $instance); 
    7474            $this->addCDataToValue($tag, $def, $instance); 
  • trunk/XJConf/converters/FactoryMethodValueConverter.php

    r61 r62  
    7373 
    7474        // add attributes and child elements 
    75         if ($def instanceof BaseTagDefinition) { 
     75        if ($def instanceof TagDefinition) { 
    7676            $this->addAttributesToValue($tag, $def, $instance); 
    7777            $this->addCDataToValue($tag, $def, $instance); 
  • trunk/XJConf/definitions/AbstractTagDefinition.php

    r61 r62  
    55 * @author  Frank Kleine <mikey@xjconf.net> 
    66 */ 
    7 XJConfLoader::load('definitions.BaseTagDefinition', 
     7XJConfLoader::load('definitions.TagDefinition', 
    88                   'exceptions.ValueConversionException' 
    99); 
     
    1414 * @subpackage  definitions 
    1515 */ 
    16 class AbstractTagDefinition extends BaseTagDefinition 
     16class AbstractTagDefinition extends TagDefinition 
    1717{ 
    1818        /** 
  • trunk/XJConf/definitions/ConcreteTagDefinition.php

    r61 r62  
    66 * @author  Frank Kleine <frank.kleine@schlund.de> 
    77 */ 
    8 XJConfLoader::load('definitions.BaseTagDefinition'); 
     8XJConfLoader::load('definitions.TagDefinition'); 
    99/** 
    1010 * Definition of an XML tag. 
     
    1313 * @subpackage  definitions 
    1414 */ 
    15 class TagDefinition extends BaseTagDefinition 
     15class ConcreteTagDefinition extends TagDefinition 
    1616{ 
    1717    /** 
  • trunk/XJConf/definitions/NamespaceDefinition.php

    r61 r62  
    1111     * list of tag definitions 
    1212     *  
    13      * @var  array<String,BaseTagDefinition> 
     13     * @var  array<String,TagDefinition> 
    1414     */ 
    1515        private $tagDefinitions = array(); 
     
    3535    * Add a new tag definition 
    3636    *  
    37     * @param  BaseTagDefinition  $tagDefinition 
     37    * @param  TagDefinition  $tagDefinition 
    3838    */ 
    39     public function addTagDefinition(BaseTagDefinition $tagDefinition) 
     39    public function addTagDefinition(TagDefinition $tagDefinition) 
    4040    { 
    4141        $this->tagDefinitions[$tagDefinition->getTagName()] = $tagDefinition; 
     
    6767    *  
    6868    * @param   tagName name of the tag 
    69     * @return  BaseTagDefinition 
     69    * @return  TagDefinition 
    7070    */ 
    7171    public function getDefinition($tagName) 
  • trunk/XJConf/definitions/NamespaceDefinitions.php

    r61 r62  
    8181     * Get the definition of a single tag 
    8282     *  
    83      * @param   string             $namespace  namespace URI 
    84      * @param   string             $tagName    local tag name 
    85      * @return  BaseTagDefinition 
     83     * @param   string         $namespace  namespace URI 
     84     * @param   string         $tagName    local tag name 
     85     * @return  TagDefinition 
    8686     */ 
    8787    public function getTagDefinition($namespace, $tagName) 
  • trunk/XJConf/definitions/TagDefinition.php

    r61 r62  
    2222 * @subpackage  definitions 
    2323 */ 
    24 abstract class BaseTagDefinition implements Definition 
     24abstract class TagDefinition implements Definition 
    2525{ 
    2626    /** 
  • trunk/XJConf/definitions/handler/TagDefinitionHandler.php

    r46 r62  
    11<?php 
    22/** 
    3  * Creates a TagDefinition from given xml data. 
     3 * Creates a ConcreteTagDefinition from given xml data. 
     4 *  
     5 * Used for backward compatibility and usage of <tag> in definition files  
     6 * instead of <concreteTag>. 
    47 * 
    58 * @author  Frank Kleine <frank@kl-s.com> 
    69 */ 
    7 XJConfLoader::load('definitions.handler.DefinitionHandler', 
    8                    'definitions.TagDefinition', 
    9                    'definitions.NamespaceDefinition', 
    10                    'exceptions.InvalidTagDefinitionException' 
    11 ); 
     10XJConfLoader::load('definitions.handler.ConcreteTagDefinitionHandler'); 
    1211/** 
    13  * Creates a TagDefinition from given xml data. 
     12 * Creates a ConcreteTagDefinition from given xml data. 
     13 *  
     14 * Used for backward compatibility and usage of <tag> in definition files  
     15 * instead of <concreteTag>. 
    1416 * 
    1517 * @package     XJConf 
    1618 * @subpackage  definitions 
    1719 */ 
    18 class TagDefinitionHandler implements DefinitionHandler 
     20class TagDefinitionHandler extends ConcreteTagDefinitionHandler 
    1921{ 
    20     /** 
    21      * the definition parser 
    22      * 
    23      * @var  DefinitionParser 
    24      */ 
    25     private $defParser; 
    26  
    27     /** 
    28      * init the handler 
    29      * 
    30      * @param  DefinitionParser  $defParser 
    31      */ 
    32     public function init(DefinitionParser $defParser) 
    33     { 
    34         $this->defParser = $defParser; 
    35     } 
    36  
    37     /** 
    38      * Start Element handler 
    39      * 
    40      * @param   string      $namespaceURI  namespace of start tag 
    41      * @param   string      $sName         name of start tag 
    42      * @param   array       $atts          attributes of tag 
    43      * @return  Definition 
    44      * @throws  InvalidTagDefinitionException 
    45      */ 
    46     public function startElement($namespaceURI, $sName, $atts) 
    47     { 
    48         // ensure that the name has been set 
    49         if (isset($atts['name']) == false) { 
    50                 throw new InvalidTagDefinitionException('The <tag> tag is missing the name attribute.'); 
    51         } 
    52  
    53         // 
    54         if (isset($atts['type']) == false) { 
    55                 $atts['type'] = $atts['primitive']; 
    56         } 
    57  
    58         // The definition extends another definition 
    59         if (isset($atts['extends']) != false) { 
    60             $nsDef = $this->defParser->getNamespaceDefinitions()->getNamespaceDefinition($this->defParser->getCurrentNamespace()); 
    61             $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']); 
    67             } 
    68         } else { 
    69                 // Create a definition from scratch 
    70                 if (null == $atts['type']) { 
    71                         $atts['type'] = 'string'; 
    72                 } 
    73  
    74                 $def = new TagDefinition($atts['name'], $atts['type']); 
    75         } 
    76  
    77         // key attribute 
    78         if (isset($atts['keyAttribute']) == true) { 
    79             $def->setKeyAttribute($atts['keyAttribute']); 
    80         } elseif (isset($atts['key']) == true) { 
    81             $def->setName($atts['key']); 
    82         } 
    83  
    84         // setter 
    85         if (isset($atts['setter']) == true) { 
    86             $def->setSetterMethod($atts['setter']); 
    87         } 
    88          
    89         // give definition the correct class loader 
    90         if ($this->defParser->hasClassLoader($this->defParser->getCurrentNamespace()) == true) { 
    91             $def->setClassLoader($this->defParser->getClassLoader($this->defParser->getCurrentNamespace())); 
    92         } 
    93  
    94         return $def; 
    95     } 
    96  
    97     /** 
    98      * End Element handler 
    99      * 
    100      * @param   string  $namespaceURI  namespace of end tag 
    101      * @param   string  $sName         name of end tag 
    102      * @throws  XJConfException 
    103      */ 
    104     public function endElement($namespaceURI, $sName) 
    105     { 
    106         $defStack =& $this->defParser->getDefStack(); 
    107         $def      = array_pop($defStack); 
    108  
    109         $nsDefs = $this->defParser->getNamespaceDefinitions(); 
    110  
    111         if ($nsDefs->isNamespaceDefined($this->defParser->getCurrentNamespace()) == false) { 
    112             $nsDefs->addNamespaceDefinition($this->defParser->getCurrentNamespace(), new NamespaceDefinition($this->defParser->getCurrentNamespace())); 
    113         } 
    114  
    115         $nsDef = $nsDefs->getNamespaceDefinition($this->defParser->getCurrentNamespace()); 
    116         $nsDef->addTagDefinition($def); 
    117     } 
     22     
    11823} 
    11924?>