Changeset 393
- Timestamp:
- 03/16/07 21:51:56 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMatcherAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMethodsAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLPropertiesAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/xml/stubXMLSerializerTestCase.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMatcherAnnotation.php
r223 r393 40 40 41 41 /** 42 * Check, whether the method or property name matches42 * Get the name of the tag to use for a property 43 43 * 44 * @return string 44 * @param stubReflectionProperty $property 45 * @param mixed $propertyValue 46 * @return string|false 45 47 */ 46 public function matches($string) { 47 return preg_match($this->pattern, $string); 48 public function getTagnameForProperty(stubReflectionProperty $property, $propertyValue) { 49 $matches = array(); 50 if (!preg_match($this->pattern, $property->getName(), $matches)) { 51 return false; 52 } 53 if (isset($matches[1])) { 54 return $matches[1]; 55 } 56 return $matches[0]; 57 } 58 59 /** 60 * Get the name of the tag to use for a method 61 * 62 * @param stubReflectionMethod $method 63 * @param mixed $returnValue 64 */ 65 public function getTagnameForMethod(stubReflectionMethod $method, $returnValue) { 66 $matches = array(); 67 if (!preg_match($this->pattern, $method->getName(), $matches)) { 68 return false; 69 } 70 if (isset($matches[1])) { 71 $name = $matches[1]; 72 } else { 73 $name = $matches[0]; 74 } 75 return strtolower($name{0}) . substr($name, 1); 48 76 } 49 77 trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMethodsAnnotation.php
r223 r393 17 17 * @subpackage xml_serializer 18 18 */ 19 interface stubXMLMethodsAnnotation extends stubXMLPropertiesAnnotation { 19 interface stubXMLMethodsAnnotation { 20 21 /** 22 * Get the name of the tag to use for a method 23 * 24 * @param stubReflectionMethod $method 25 * @param mixed $returnValue 26 * @return string|false 27 */ 28 public function getTagnameForMethod(stubReflectionMethod $method, $returnValue); 20 29 } 21 30 ?> trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLPropertiesAnnotation.php
r223 r393 19 19 */ 20 20 interface stubXMLPropertiesAnnotation { 21 public function matches($string); 21 22 /** 23 * Get the name of the tag to use for a property 24 * 25 * @param stubReflectionProperty $property 26 * @param mixed $propertyValue 27 * @return string|false 28 */ 29 public function getTagnameForProperty(stubReflectionProperty $property, $propertyValue); 22 30 } 23 31 ?> trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php
r251 r393 142 142 continue; 143 143 } 144 if (null !== $matcher && !$matcher->matches($property->getName())) {145 continue;146 }147 148 144 $propValue = $property->getValue($object); 145 149 146 if ($property->hasAnnotation('XMLAttribute')) { 150 147 $xmlAttribute = $property->getAnnotation('XMLAttribute'); … … 157 154 $elementName = $xmlTag->getElementTagName(); 158 155 } else { 159 $tagName = $property->getName(); 156 if (null !== $matcher) { 157 $tagName = $matcher->getTagnameForProperty($property, $propValue); 158 if ($tagName === false) { 159 continue; 160 } 161 } else { 162 $tagName = $property->getName(); 163 } 160 164 $elementName = null; 161 165 } … … 177 181 $matcher = null; 178 182 } 179 180 183 foreach ($methods as $method) { 181 184 if (!$method->isPublic()) { … … 192 195 } 193 196 if ($method->hasAnnotation('XMLIgnore')) { 194 continue;195 }196 if (null !== $matcher && !$matcher->matches($method->getName())) {197 197 continue; 198 198 } … … 210 210 $elementName = $xmlTag->getElementTagName(); 211 211 } else { 212 $tagName = $method->getName(); 212 if (null !== $matcher) { 213 $tagName = $matcher->getTagnameForMethod($method, $returnValue); 214 if ($tagName === false) { 215 continue; 216 } 217 } else { 218 $tagName = $method->getName(); 219 } 213 220 $elementName = null; 214 221 } trunk/src/test/php/net/stubbles/xml/stubXMLSerializerTestCase.php
r210 r393 100 100 * 101 101 * @XMLTag(tagName=testObject) 102 * @XMLProperties[XMLMatcher](pattern=/^ [a-zA-Z]{3}$/)102 * @XMLProperties[XMLMatcher](pattern=/^([a-zA-Z]{3})$/) 103 103 */ 104 104 class XMLSerializerPropertyMatcher { … … 113 113 * 114 114 * @XMLTag(tagName=testObject) 115 * @XMLMethods[XMLMatcher](pattern=/^get F/)115 * @XMLMethods[XMLMatcher](pattern=/^get(F.+)/) 116 116 */ 117 117 class XMLSerializerMethodMatcher { … … 284 284 $obj = new XMLSerializerMethodMatcher(); 285 285 $this->serializer->serialize($obj, $writer); 286 $this->assertEqual('<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n" . '<testObject>< getFoo>foo</getFoo></testObject>', $writer->asXML());286 $this->assertEqual('<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n" . '<testObject><foo>foo</foo></testObject>', $writer->asXML()); 287 287 } 288 288
