Changeset 56
- Timestamp:
- 11/29/06 23:07:49 (2 years ago)
- Files:
-
- trunk/XJConf/converters/AbstractObjectValueConverter.php (modified) (1 diff)
- trunk/XJConf/converters/ConstructorValueConverter.php (modified) (2 diffs)
- trunk/XJConf/converters/FactoryMethodValueConverter.php (modified) (3 diffs)
- trunk/examples/xml/defines-set-cdata.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/XJConf/converters/AbstractObjectValueConverter.php
r43 r56 83 83 84 84 /** 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 /** 85 109 * returns the type of the converter 86 110 * trunk/XJConf/converters/ConstructorValueConverter.php
r49 r56 48 48 $cParams[] = $conParam->convertValue($tag); 49 49 } 50 50 51 51 // try to create a new instance 52 52 try { … … 72 72 if ($def instanceof TagDefinition) { 73 73 $this->addAttributesToValue($tag, $def, $instance); 74 $this->addCDataToValue($tag, $def, $instance); 74 75 } 75 76 $this->addChildrenToValue($tag, $def, $instance, $constructor->getUsedChildrenNames()); trunk/XJConf/converters/FactoryMethodValueConverter.php
r22 r56 49 49 throw new ValueConversionException('Class "' . $this->className . '" does not exist.'); 50 50 } 51 51 52 52 $factoryMethod = $def->getChildDefinition('FactoryMethodDefinition'); 53 53 $tmpParams = $factoryMethod->getParams(); … … 57 57 $cParams[] = $conParam->convertValue($tag); 58 58 } 59 59 60 60 try { 61 61 $refClass = new ReflectionClass($this->className); … … 71 71 throw new ValueConversionException('Could not create instance of "' . $this->className . '" using the factory method "' . $this->methodName . '": ' . $re->getMessage()); 72 72 } 73 73 74 74 // add attributes and child elements 75 75 if ($def instanceof TagDefinition) { 76 76 $this->addAttributesToValue($tag, $def, $instance); 77 $this->addCDataToValue($tag, $def, $instance); 77 78 } 78 79 $this->addChildrenToValue($tag, $def, $instance, $factoryMethod->getUsedChildrenNames()); 79 80 80 81 81 return $instance; trunk/examples/xml/defines-set-cdata.xml
r37 r56 1 1 <defines> 2 2 <tag name="complex" type="Complex2"> 3 <constructor/> 3 4 <cdata type="integer" setter="setSize"/> 4 5 <attribute name="color" type="string" setter="setColorString"/>
