Changeset 94

Show
Ignore:
Timestamp:
03/05/07 16:41:37 (2 years ago)
Author:
schst
Message:

Add the possibility to call setter methods with any number of arguments. This fixed ticket #9. But beware: this feature is in alpha stage, it may break existing applications.

Files:

Legend:

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

    r62 r94  
    267267    * @param  TagDefinition  $tagDef 
    268268    */ 
    269     public function setDefinition(TagDefinition $tagDef) 
     269    public function setDefinition(Definition $tagDef) 
    270270    { 
    271271        if ($tagDef instanceof ConcreteTagDefinition) { 
     
    273273            return; 
    274274        } 
    275          
     275 
    276276        $this->tagDef = clone $tagDef; 
    277         $this->tagDef->setType($this->getAttribute($this->tagDef->getConcreteTypeAttributeName())); 
     277        if ($tagDef instanceof TagDefinition) { 
     278            $this->tagDef->setType($this->getAttribute($this->tagDef->getConcreteTypeAttributeName())); 
     279        } 
    278280    } 
    279281 
  • trunk/XJConf/DefinitionParser.php

    r60 r94  
    1111                   'definitions.ConstructorDefinition', 
    1212                   'definitions.FactoryMethodDefinition', 
     13                   'definitions.MethodCallTagDefinition', 
    1314                   'definitions.NamespaceDefinition', 
    1415                   'definitions.NamespaceDefinitions', 
     
    8485     * Sets the node types depending on your PHP version using the constants 
    8586     * defined by the XMLReader PHP extension. 
    86      *  
     87     * 
    8788     * @param  array<String,XJConfClassLoader>  $classLoaders  optional 
    8889     */ 
     
    125126        return $this->defs; 
    126127    } 
    127      
     128 
    128129    /** 
    129130     * check whether a class loader exists for given namespace 
     
    136137        return (isset($this->classLoaders[$namespace])); 
    137138    } 
    138      
     139 
    139140    /** 
    140141     * return the class loader for the given namespace 
     
    145146    public function getClassLoader($namespace) 
    146147    { 
    147          
     148 
    148149        if ($this->hasClassLoader($namespace) == true) { 
    149150            return $this->classLoaders[$namespace]; 
    150151        } 
    151          
     152 
    152153        return null; 
    153154    } 
     
    245246                return; 
    246247        } 
    247          
     248 
    248249        // create the appropriate definition handler and use this 
    249250        // to create the required definition 
  • trunk/XJConf/GenericTag.php

    r14 r94  
    279279                $this->value = $value; 
    280280        } 
     281 
     282        public function getDefinition() { 
     283            return null; 
     284        } 
    281285} 
    282286?> 
  • trunk/XJConf/Tag.php

    r14 r94  
    124124        public function getSetterMethod(); 
    125125 
     126        public function getDefinition(); 
     127 
    126128        /** 
    127129         * Checks, whether the tag supports indexed children 
  • trunk/XJConf/XmlParser.php

    r47 r94  
    250250            } 
    251251 
    252             if ($this->tagDefs->isTagDefined($namespaceURI, $sName) == false) { 
    253                 throw new UnknownTagException('Unknown tag ' . $sName . ' in namespace ' . $namespaceURI); 
     252            $newDef = null; 
     253            $lastTag = end($this->tagStack); 
     254            if ($lastTag != null) { 
     255                $lastDef = $lastTag->getDefinition(); 
     256                if ($lastDef != null) { 
     257                    $newDef = $lastDef->getChildDefinitionByTagName($sName); 
     258                } 
     259            } 
     260            if ($newDef === null) { 
     261                if ($this->tagDefs->isTagDefined($namespaceURI, $sName) == false) { 
     262                    throw new UnknownTagException('Unknown tag ' . $sName . ' in namespace ' . $namespaceURI); 
     263                } 
     264                $newDef = $this->tagDefs->getTagDefinition($namespaceURI, $sName); 
    254265            } 
    255266 
    256267            $tag = new DefinedTag($sName, $atts); 
    257268            // fetch the defintion for this tag 
    258             $tag->setDefinition($this->tagDefs->getTagDefinition($namespaceURI, $sName)); 
     269            $tag->setDefinition($newDef); 
    259270        } 
    260271 
  • trunk/XJConf/converters/AbstractObjectValueConverter.php

    r62 r94  
    2323     */ 
    2424    protected $className; 
     25 
     26    /** 
     27     * Enter description here... 
     28     * 
     29     * @param Tag $tag 
     30     * @param TagDefinition $def 
     31     * @param unknown_type $instance 
     32     */ 
     33    protected function callMethods(Tag $tag, TagDefinition $def, $instance) { 
     34        $children = $tag->getChildren(); 
     35        foreach ($children as $child) { 
     36                if (!$child instanceof ValueModifier) { 
     37                    continue; 
     38                } 
     39        } 
     40    } 
    2541 
    2642    /** 
     
    7187        $class = new ReflectionClass(get_class($instance)); 
    7288        foreach ($children as $child) { 
     89 
    7390            if (in_array($child->getName(), $ignore) == true) { 
     91                continue; 
     92            } 
     93 
     94            $childDef = $child->getDefinition(); 
     95            if ($childDef instanceof ValueModifier) { 
     96                $childDef->modifyValue($instance, $child); 
    7497                continue; 
    7598            } 
  • trunk/XJConf/definitions/AttributeDefinition.php

    r59 r94  
    131131        } 
    132132 
     133 
     134 
    133135        if (null === $value) { 
    134136            if ($this->isRequired() == true) { 
     
    289291        return $this->valueConverter; 
    290292    } 
     293 
     294    /** 
     295     * This definition does not support named child definitions 
     296     * 
     297     * @param string $name 
     298     * @return Definition 
     299     */ 
     300    public function getChildDefinitionByTagName($name) { 
     301        return null; 
     302    } 
    291303} 
    292304?> 
  • trunk/XJConf/definitions/CDataDefinition.php

    r63 r94  
    178178        return $this->valueConverter; 
    179179    } 
     180 
     181    /** 
     182     * This definition does not support named child definitions 
     183     * 
     184     * @param string $name 
     185     * @return Definition 
     186     */ 
     187    public function getChildDefinitionByTagName($name) { 
     188        return null; 
     189    } 
    180190} 
    181191?> 
  • trunk/XJConf/definitions/ChildDefinition.php

    r43 r94  
    143143    } 
    144144 
    145  
     145    /** 
     146     * This definition does not support named child definitions 
     147     * 
     148     * @param string $name 
     149     * @return Definition 
     150     */ 
     151    public function getChildDefinitionByTagName($name) { 
     152        return null; 
     153    } 
    146154} 
    147155?> 
  • trunk/XJConf/definitions/ConstructorDefinition.php

    r65 r94  
    160160        return $this->params; 
    161161    } 
     162 
     163    /** 
     164     * This definition does not support named child definitions 
     165     * 
     166     * @param string $name 
     167     * @return Definition 
     168     */ 
     169    public function getChildDefinitionByTagName($name) { 
     170        return null; 
     171    } 
    162172} 
    163173?> 
  • trunk/XJConf/definitions/Definition.php

    r43 r94  
    8282         */ 
    8383        public function getChildDefinitions(); 
     84 
     85        public function getChildDefinitionByTagName($name); 
    8486} 
    8587?> 
  • trunk/XJConf/definitions/FactoryMethodDefinition.php

    r66 r94  
    179179        return $this->params; 
    180180    } 
     181 
     182    /** 
     183     * This definition does not support named child definitions 
     184     * 
     185     * @param string $name 
     186     * @return Definition 
     187     */ 
     188    public function getChildDefinitionByTagName($name) { 
     189        return null; 
     190    } 
    181191} 
    182192?> 
  • trunk/XJConf/definitions/TagDefinition.php

    r93 r94  
    7878     */ 
    7979    protected $valueConverter; 
     80 
     81    /** 
     82     * Methods to call on this tag 
     83     * 
     84     * @var array 
     85     */ 
     86    protected $methods = array(); 
     87 
     88    protected $childDefs = array(); 
     89 
    8090    /** 
    8191     * definition of tag content 
     
    271281            return; 
    272282        } 
     283        $this->childDefs[] = $def; 
    273284    } 
    274285 
     
    420431        $this->classLoader = $classLoader; 
    421432    } 
    422      
     433 
    423434    /** 
    424435     * extends itsself from another tag definition 
    425      *  
     436     * 
    426437     * @param  TagDefinition  $tagDefinition  the tag definition to extend from 
    427438     */ 
     
    438449 
    439450    /** 
     451     * Get the methods 
     452     * 
     453     * @return array 
     454     */ 
     455    public function getMethods() { 
     456        return $this->methods; 
     457    } 
     458 
     459    /** 
    440460     * Get the value converter for this tag 
    441461     * 
     
    458478        return $this->valueConverter; 
    459479    } 
     480 
     481    public function getChildDefinitionByTagName($name) { 
     482        foreach ($this->childDefs as $childDef) { 
     483            if ($childDef->getName() == $name) { 
     484                return $childDef; 
     485            } 
     486        } 
     487        return null; 
     488    } 
    460489} 
    461490?>