Changeset 56

Show
Ignore:
Timestamp:
11/29/06 23:07:49 (2 years ago)
Author:
schst
Message:

It is now possible to define an explicit type and setter method to treat cdata in a tag (fixes bug #4)

Files:

Legend:

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

    r43 r56  
    8383 
    8484    /** 
     85     * Add the CData to the value 
     86     * 
     87     * @param   Tag         $tag 
     88     * @param   Definition  $def 
     89     * @param   object      $instance 
     90     * @throws  ValueConversionException 
     91     */ 
     92    protected function addCDataToValue(Tag $tag, Definition $def, $instance, $ignore = array()) 
     93    { 
     94        // check, whether the CData has been specifically defined 
     95        if (!$def->hasChildDefinition('CDataDefinition')) { 
     96            return; 
     97        } 
     98        $cDataDefinition = $def->getChildDefinition('CDataDefinition'); 
     99        $value = $cDataDefinition->convertValue($tag); 
     100        try { 
     101            $class = new ReflectionClass(get_class($instance)); 
     102            $class->getMethod($cDataDefinition->getSetterMethod($tag))->invoke($instance, $value); 
     103        } catch (ReflectionException $re) { 
     104            throw new ValueConversionException('Could not add cdata to "' . $this->getType() . '" using "' . $cDataDefinition->getSetterMethod($tag) . '()", exception message: "' . $re->getMessage() . '".'); 
     105        } 
     106    } 
     107 
     108    /** 
    85109     * returns the type of the converter 
    86110     * 
  • trunk/XJConf/converters/ConstructorValueConverter.php

    r49 r56  
    4848            $cParams[] = $conParam->convertValue($tag); 
    4949        } 
    50          
     50 
    5151        // try to create a new instance 
    5252        try { 
     
    7272        if ($def instanceof TagDefinition) { 
    7373            $this->addAttributesToValue($tag, $def, $instance); 
     74            $this->addCDataToValue($tag, $def, $instance); 
    7475        } 
    7576        $this->addChildrenToValue($tag, $def, $instance, $constructor->getUsedChildrenNames()); 
  • trunk/XJConf/converters/FactoryMethodValueConverter.php

    r22 r56  
    4949                throw new ValueConversionException('Class "' . $this->className . '" does not exist.'); 
    5050            } 
    51          
     51 
    5252            $factoryMethod = $def->getChildDefinition('FactoryMethodDefinition'); 
    5353            $tmpParams     = $factoryMethod->getParams(); 
     
    5757            $cParams[] = $conParam->convertValue($tag); 
    5858        } 
    59          
     59 
    6060        try { 
    6161            $refClass  = new ReflectionClass($this->className); 
     
    7171                throw new ValueConversionException('Could not create instance of "' . $this->className . '" using the factory method "' . $this->methodName . '": ' . $re->getMessage()); 
    7272        } 
    73          
     73 
    7474        // add attributes and child elements 
    7575        if ($def instanceof TagDefinition) { 
    7676            $this->addAttributesToValue($tag, $def, $instance); 
     77            $this->addCDataToValue($tag, $def, $instance); 
    7778        } 
    7879        $this->addChildrenToValue($tag, $def, $instance, $factoryMethod->getUsedChildrenNames()); 
    79  
    8080 
    8181        return $instance; 
  • trunk/examples/xml/defines-set-cdata.xml

    r37 r56  
    11<defines> 
    22        <tag name="complex" type="Complex2"> 
     3            <constructor/> 
    34                <cdata type="integer" setter="setSize"/> 
    45                <attribute name="color" type="string" setter="setColorString"/>