Changeset 491
- Timestamp:
- 04/13/07 13:54:07 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationStateParser.php
r484 r491 141 141 * @param string $value the value of the param 142 142 * @param bool $asString whether the value is a string or not 143 * @throws ReflectionException144 143 */ 145 144 public function registerSingleAnnotationParam($value, $asString = false) … … 158 157 * @param string $value the value of the param 159 158 * @param bool $asString whether the value is a string or not 160 * @throws ReflectionException161 159 */ 162 160 public function setAnnotationParamValue($value, $asString = false) … … 181 179 * @param boolean $asString whether value should be treated as string or not 182 180 * @return mixed 183 * @throws ReflectionException184 * @todo improve type detection and error handling185 181 */ 186 182 protected function convertAnnotationValue($value, $asString) … … 198 194 } 199 195 200 if ('null' === $value || 'NULL' == $value) {196 if ('null' === strtolower($value)) { 201 197 return null; 202 198 } … … 204 200 if (preg_match('/^[+-]?[0-9]+$/', $value) != false) { 205 201 return (integer) $value; 202 } 203 204 if (preg_match('/^[+-]?[0-9]+\.[0-9]+$/', $value) != false) { 205 return (double) $value; 206 206 } 207 207 … … 211 211 } 212 212 213 throw new ReflectionException('Could not determine type of value ' . $value); 213 if (defined($value) == true) { 214 return constant($value); 215 } 216 217 return (string) $value; 214 218 } 215 219 } trunk/src/test/php/net/stubbles/reflection/annotations/parser/stubAnnotationStateParserTestCase.php
r483 r491 9 9 */ 10 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationStateParser'); 11 define('ANNOTATION_TEST_CONSTANT', 'baz'); 11 12 /** 12 13 * This is a test class that has many annotations. … … 20 21 * @InvalidChars(foo='ba@r=,') 21 22 * @SingleValue(42) 23 * @Constant(foo=ANNOTATION_TEST_CONSTANT) 22 24 * @SingleStringValue('This is a string with chars like = or ,') 23 25 * @WithEscaped(foo='This string contains \' and \\, which is possible using escaping...') … … 27 29 * null=null, 28 30 * negInt=-13, 31 * double=2.34, 32 * negDouble=-5.67, 29 33 * string1='true', 30 34 * string2='null', … … 72 76 $this->assertEqual($annotations['SingleValue']['type'], 'SingleValue'); 73 77 $this->assertEqual($annotations['SingleValue']['params'], array('value' => 42)); 78 $this->assertTrue(isset($annotations['Constant'])); 79 $this->assertEqual($annotations['Constant']['type'], 'Constant'); 80 $this->assertEqual($annotations['Constant']['params'], array('foo' => ANNOTATION_TEST_CONSTANT)); 74 81 $this->assertTrue(isset($annotations['SingleStringValue'])); 75 82 $this->assertEqual($annotations['SingleStringValue']['type'], 'SingleStringValue'); … … 86 93 $this->assertFalse($annotations['WithTypes']['params']['false']); 87 94 $this->assertEqual($annotations['WithTypes']['params']['integer'], 4562); 95 $this->assertEqual(gettype($annotations['WithTypes']['params']['integer']), 'integer'); 88 96 $this->assertNull($annotations['WithTypes']['params']['null']); 89 97 $this->assertEqual($annotations['WithTypes']['params']['negInt'], -13); 98 $this->assertEqual(gettype($annotations['WithTypes']['params']['negInt']), 'integer'); 99 $this->assertEqual($annotations['WithTypes']['params']['double'], 2.34); 100 $this->assertEqual(gettype($annotations['WithTypes']['params']['double']), 'double'); 101 $this->assertEqual($annotations['WithTypes']['params']['negDouble'], -5.67); 102 $this->assertEqual(gettype($annotations['WithTypes']['params']['negDouble']), 'double'); 90 103 $this->assertEqual($annotations['WithTypes']['params']['string1'], 'true'); 91 104 $this->assertEqual($annotations['WithTypes']['params']['string2'], 'null');
