Changeset 1080
- Timestamp:
- 11/28/07 14:02:20 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/stubReflectionParameter.php
r1072 r1080 21 21 { 22 22 /** 23 * name of reflected function23 * name of reflected routine 24 24 * 25 25 * @var string 26 26 */ 27 protected $functionName; 27 protected $routineName; 28 /** 29 * reflection instance of routine containing this parameter 30 * 31 * @var stubReflectionRoutine 32 */ 33 protected $refRoutine; 28 34 /** 29 35 * name of reflected parameter … … 32 38 */ 33 39 protected $paramName; 34 /**35 * doc block of method or function where this param belongs to36 *37 * @var string38 */39 protected $docComment;40 40 41 41 /** 42 42 * constructor 43 43 * 44 * @param string $functionName name of function to reflect 45 * @param string $paramName name of parameter to reflect 46 */ 47 public function __construct($functionName, $paramName) 48 { 49 $this->functionName = $functionName; 50 $this->paramName = $paramName; 51 parent::__construct($functionName, $paramName); 44 * @param string $routine name of function to reflect 45 * @param string $paramName name of parameter to reflect 46 */ 47 public function __construct($routine, $paramName) 48 { 49 if ($routine instanceof stubReflectionMethod) { 50 $this->refRoutine = $routine; 51 $this->routineName = array($routine->getDeclaringClass()->getName(), $routine->getName()); 52 } elseif ($routine instanceof stubReflectionFunction) { 53 $this->refRoutine = $routine; 54 $this->routineName = $routine->getName(); 55 } else { 56 $this->routineName = $routine; 57 } 58 59 $this->paramName = $paramName; 60 parent::__construct($this->routineName, $paramName); 52 61 } 53 62 … … 60 69 public function hasAnnotation($annotationName) 61 70 { 62 if (is_array($this->functionName) === true) { 63 $targetName = $this->functionName[0] . '::' . $this->functionName[1] . '()'; 64 $ref = new stubReflectionMethod($this->functionName[0], $this->functionName[1]); 65 } else { 66 $targetName = $this->functionName; 67 $ref = new stubReflectionFunction($this->functionName); 68 } 69 70 return stubAnnotationFactory::has($ref->getDocComment(), $annotationName . '#' . $this->paramName, stubAnnotation::TARGET_PARAM, $targetName, $ref->getFileName()); 71 $refRoutine = $this->getRefRoutine(); 72 $targetName = ((is_array($this->routineName) === true) ? ($this->routineName[0] . '::' . $this->routineName[1] . '()') : ($this->routineName)); 73 return stubAnnotationFactory::has($refRoutine->getDocComment(), $annotationName . '#' . $this->paramName, stubAnnotation::TARGET_PARAM, $targetName, $refRoutine->getFileName()); 71 74 } 72 75 … … 80 83 public function getAnnotation($annotationName) 81 84 { 82 if (is_array($this->functionName) === true) { 83 $targetName = $this->functionName[0] . '::' . $this->functionName[1] . '()'; 84 $ref = new stubReflectionMethod($this->functionName[0], $this->functionName[1]); 85 } else { 86 $targetName = $this->functionName; 87 $ref = new stubReflectionFunction($this->functionName); 88 } 89 90 return stubAnnotationFactory::create($ref->getDocComment(), $annotationName . '#' . $this->paramName, stubAnnotation::TARGET_PARAM, $targetName, $ref->getFileName()); 85 $refRoutine = $this->getRefRoutine(); 86 $targetName = ((is_array($this->routineName) === true) ? ($this->routineName[0] . '::' . $this->routineName[1] . '()') : ($this->routineName)); 87 return stubAnnotationFactory::create($refRoutine->getDocComment(), $annotationName . '#' . $this->paramName, stubAnnotation::TARGET_PARAM, $targetName, $refRoutine->getFileName()); 88 } 89 90 /** 91 * helper method to return the reflection routine defining this parameter 92 * 93 * @return stubReflectionRoutine 94 * @todo replace by getDeclaringFunction() as soon as Stubbles requires at least PHP 5.2.3 95 */ 96 protected function getRefRoutine() 97 { 98 if (null === $this->refRoutine) { 99 if (is_array($this->routineName) === true) { 100 $this->refRoutine = new stubReflectionMethod($this->routineName[0], $this->routineName[1]); 101 } else { 102 $this->refRoutine = new stubReflectionFunction($this->routineName); 103 } 104 } 105 106 return $this->refRoutine; 91 107 } 92 108 … … 110 126 111 127 if (null == $class) { 112 return ($compare-> functionName == $this->functionName && $compare->paramName == $this->paramName);113 } 114 115 return ($compareClass->getName() == $class->getName() && $compare-> functionName == $this->functionName && $compare->paramName == $this->paramName);128 return ($compare->routineName == $this->routineName && $compare->paramName == $this->paramName); 129 } 130 131 return ($compareClass->getName() == $class->getName() && $compare->routineName == $this->routineName && $compare->paramName == $this->paramName); 116 132 } 117 133 … … 133 149 public function __toString() 134 150 { 135 if (is_array($this-> functionName) == false) {136 return 'net.stubbles.reflection.stubReflectionParameter[' . $this-> functionName . '(): Argument ' . $this->paramName . "] {\n}\n";137 } 138 139 return 'net.stubbles.reflection.stubReflectionParameter[' . $this-> functionName[0] . '::' . $this->functionName[1] . '(): Argument ' . $this->paramName . "] {\n}\n";151 if (is_array($this->routineName) == false) { 152 return 'net.stubbles.reflection.stubReflectionParameter[' . $this->routineName . '(): Argument ' . $this->paramName . "] {\n}\n"; 153 } 154 155 return 'net.stubbles.reflection.stubReflectionParameter[' . $this->routineName[0] . '::' . $this->routineName[1] . '(): Argument ' . $this->paramName . "] {\n}\n"; 140 156 } 141 157 … … 162 178 public function getDeclaringClass() 163 179 { 164 $refClass = parent::getDeclaringClass(); 165 if (null === $refClass) { 180 if (is_array($this->routineName) === false) { 166 181 return null; 167 182 } 168 183 184 $refClass = parent::getDeclaringClass(); 169 185 $stubRefClass = new stubReflectionClass($refClass->getName()); 170 186 return $stubRefClass; trunk/src/test/php/net/stubbles/reflection/stubReflectionParameterTestCase.php
r1072 r1080 1 1 <?php 2 2 /** 3 * Test for stubReflectionParameter.3 * Test for net::stubbles::reflection::stubReflectionParameter. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 88 88 } 89 89 /** 90 * Test for stubReflectionParameter.90 * Test for net::stubbles::reflection::stubReflectionParameter. 91 91 * 92 92 * @package stubbles … … 245 245 $this->assertIsA($refClass, 'stubReflectionClass'); 246 246 $this->assertEqual($refClass->getName(), 'stubParamTest'); 247 # currently not possible, see http://bugs.php.net/bug.php?id=39884 248 # $refClass = $this->stubRefParamMethod4->getClass(); 249 # $this->assertIsA($refClass, 'stubReflectionClass'); 250 # $this->assertEqual($refClass->getName(), 'stubParamTest2'); 247 $refClass = $this->stubRefParamMethod4->getClass(); 248 $this->assertIsA($refClass, 'stubReflectionClass'); 249 $this->assertEqual($refClass->getName(), 'stubParamTest2'); 251 250 } 252 251 }
