Changeset 211
- Timestamp:
- 02/05/07 20:56:17 (2 years ago)
- Files:
-
- trunk/src/main/php/net/stubbles/reflection/stubAnnotationFactory.php (modified) (11 diffs)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/XMLAttribute.php (deleted)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/XMLIgnore.php (deleted)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/XMLMatcher.php (deleted)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/XMLTag.php (deleted)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLAttributeAnnotation.php (added)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLIgnoreAnnotation.php (added)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMatcherAnnotation.php (added)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLTagAnnotation.php (added)
- trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/stubAnnotationFactory.php
r155 r211 20 20 { 21 21 /** 22 * Prefixes that can be prepended to class names 23 * 24 * @var array 25 */ 26 private static $prefixes = array('stub'); 27 28 /** 22 29 * Creates an annotation from the given docblock comment. 23 30 * … … 34 41 return $cachedAnnotation = stubAnnotationCache::get($target, $targetName, $annotationName); 35 42 } 36 43 37 44 // Fast annotation check 38 45 $start = stripos($comment, '@' . $annotationName); … … 42 49 43 50 list($annotationClass,$data) = self::parseAnnotation($comment, $annotationName); 44 if (class_exists($annotationClass) == false) {45 throw new ReflectionException('Error parsing annotation: Class ' . $annotationClass . ' does not exist');46 }47 48 51 if (false === $data) { 49 52 throw new ReflectionException('Error evaluating annotation: ' . $annotationName . substr($comment, $start, $strlen)); 50 53 } 54 55 $annotationClass = self::findAnnotationClass($annotationClass); 51 56 52 57 $annotation = new $annotationClass(); … … 57 62 throw new ReflectionException('The annotation: ' . $annotationName . ' is not applicable for the given type.'); 58 63 } 59 64 60 65 $annotation = self::build($annotation, $data); 61 66 $annotation->setAnnotationName($annotationName); … … 70 75 * @param string $annotationName 71 76 * @return array 72 * 77 * 73 78 * @todo Speed up parsing 74 79 */ … … 76 81 // remove start and end of the comment 77 82 $comment = trim(str_replace(array('/**', '*/'), '', $comment)); 78 83 79 84 $parts = explode('@', $comment); 80 85 $annoLength = strlen($annotationName); … … 97 102 $annotationClass = $annotationName; 98 103 } 99 100 104 105 101 106 // check for empty annotation 102 107 $params = trim(str_replace(array('*', '(', ')'), '', $params)); … … 109 114 return array($annotationClass, array('value' => trim($tmpParams[0]))); 110 115 } 111 116 112 117 $params = array(); 113 118 foreach ($tmpParams as $param) { … … 124 129 } 125 130 return array($annotationClass, $params); 126 } 127 } 128 131 } 132 } 133 129 134 /** 130 135 * Checks whether an annotation is applicable for the given type or not. … … 138 143 return (($annotation->getAnnotationTarget() & $target) != 0); 139 144 } 140 145 141 146 /** 142 147 * builds the annotation by setting its values from given data … … 184 189 } catch (ReflectionException $e) { 185 190 } 186 191 187 192 return (null != $annotation); 193 } 194 195 /** 196 * Add a new annotation prefix 197 * 198 * @param string $prefix 199 */ 200 public static function addAnnotationPrefix($prefix) { 201 self::$prefixes[] = $prefix; 202 } 203 204 /** 205 * Try to find the annotation class 206 * 207 * This method checks, whether there is a class named exactly as the annotation class 208 * or a method that has one of the prefixes defined in $prefixes and the postfix 'Annotation'. 209 * 210 * @param string $annotationClass 211 * @return string 212 * @see addAnnotationPrefix() 213 */ 214 private static function findAnnotationClass($annotationClass) { 215 if (class_exists($annotationClass, false) == true) { 216 return $annotationClass; 217 } 218 $annotationClass = $annotationClass . 'Annotation'; 219 foreach (self::$prefixes as $prefix) { 220 if (class_exists($prefix . $annotationClass)) { 221 return $prefix . $annotationClass; 222 } 223 } 224 throw new ReflectionException('Error parsing annotation: Class ' . $annotationClass . ' does not exist'); 188 225 } 189 226 } trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php
r210 r211 7 7 * @subpackage xml_serializer 8 8 */ 9 stubClassLoader::load('net.stubbles.xml.serializer.annotations. XMLTag',10 'net.stubbles.xml.serializer.annotations. XMLAttribute',11 'net.stubbles.xml.serializer.annotations. XMLIgnore',12 'net.stubbles.xml.serializer.annotations. XMLMatcher',9 stubClassLoader::load('net.stubbles.xml.serializer.annotations.stubXMLTagAnnotation', 10 'net.stubbles.xml.serializer.annotations.stubXMLAttributeAnnotation', 11 'net.stubbles.xml.serializer.annotations.stubXMLIgnoreAnnotation', 12 'net.stubbles.xml.serializer.annotations.stubXMLMatcherAnnotation', 13 13 'net.stubbles.relection.stubReflection'); 14 14
