Changeset 353
- Timestamp:
- 03/09/07 20:05:28 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ioc/injection/stubInjectAnnotation.php
r313 r353 16 16 * @package stubbles 17 17 * @subpackage ioc_injection 18 * @todo think about a public static addPrefix() method that will 19 * discard prefixes from injections for method and property names 18 20 */ 19 21 class stubInjectAnnotation extends stubAbstractAnnotation … … 68 70 foreach ($this->injections as $injection) { 69 71 if ($injectionProvider->hasInjection($injection) == false) { 70 throw new stubInjectionException('Injectible needs ' . $injection . ' but it was not given in list of injected classes.'); 72 $className = ($injectible instanceof stubObject) ? ($injectible->getClassName()) : (get_class($injectible)); 73 throw new stubInjectionException('Injectible ' . $className . ' needs ' . $injection . ' but it was not given in list of injected classes.'); 71 74 } 72 75 73 $methodName = 'set' . ucfirst($injection); 76 if (substr($injection, 0, 4) == 'stub') { 77 $injectionShort = substr($injection, 4); 78 } else { 79 $injectionShort = $injection; 80 } 81 82 $methodName = 'set' . ucfirst($injectionShort); 74 83 if ($refClass->hasMethod($methodName) == true && $refClass->getMethod($methodName)->isPublic() == true) { 75 84 try { … … 78 87 throw new stubInjectionException('Could not inject ' . $injection . ': ' . $re->getMessage()); 79 88 } 80 } elseif ($refClass->hasProperty($injection ) == true && $refClass->getProperty($injection)->isPublic() == true) {81 $refClass->getProperty($injection )->setValue($injectible, $injectionProvider->getInjection($injection));89 } elseif ($refClass->hasProperty($injectionShort) == true && $refClass->getProperty($injectionShort)->isPublic() == true) { 90 $refClass->getProperty($injectionShort)->setValue($injectible, $injectionProvider->getInjection($injection)); 82 91 } elseif ($refClass->hasMethod('__set') == true && $refClass->getMethod('__set')->isPublic() == true) { 83 92 $refClass->getMethod('__set')->invoke($injectible, $injection, $injectionProvider->getInjection($injection)); 84 93 } else { 85 throw new stubInjectionException('Given injectible has no method or property that accepts injection ' . $injection); 94 $className = ($injectible instanceof stubObject) ? ($injectible->getClassName()) : (get_class($injectible)); 95 throw new stubInjectionException('Injectible ' . $className . ' has no method or property that accepts injection ' . $injection); 86 96 } 87 97 } trunk/src/test/php/net/stubbles/ioc/injection/stubInjectAnnotationTestCase.php
r308 r353 11 11 class TestInjection2 extends stubBaseObject {} 12 12 class TestInjection3 extends stubBaseObject {} 13 class stubTestInjection4 extends stubBaseObject {} 13 14 /** 14 15 * class for testing injections … … 45 46 } 46 47 /** 48 * class for testing injections 49 * 50 * @Inject(stubTestInjection4:stubTestInjection5) 51 */ 52 class TestInjectible3 53 { 54 protected $TestInjection4; 55 public $TestInjection5; 56 57 public function setTestInjection4($i) 58 { 59 $this->TestInjection4 = $i; 60 } 61 62 public function getTestInjection4() 63 { 64 return $this->TestInjection4; 65 } 66 } 67 /** 47 68 * Test for net.stubbles.ioc.injection.stubInjectAnnotation 48 69 * … … 68 89 $this->injectionMap->addInjection('TestInjection2', new TestInjection2()); 69 90 $this->injectionMap->addInjection('TestInjection3', new TestInjection3()); 91 $this->injectionMap->addInjection('stubTestInjection4', new stubTestInjection4()); 92 $this->injectionMap->addInjection('stubTestInjection5', new stubTestInjection4()); 70 93 } 71 94 /** … … 131 154 stubInjectAnnotation::factory($this->injectionMap, 'foo'); 132 155 } 156 157 public function testStubPrefix() 158 { 159 $testInjectible = new TestInjectible3(); 160 stubInjectAnnotation::factory($this->injectionMap, $testInjectible); 161 $test4a = $this->injectionMap->getInjection('stubTestInjection4'); 162 $test4b = $testInjectible->getTestInjection4(); 163 $this->assertReference($test4a, $test4b); 164 $test5a = $this->injectionMap->getInjection('stubTestInjection5'); 165 $test5b = $testInjectible->TestInjection5; 166 $this->assertReference($test5a, $test5b); 167 } 133 168 } 134 169 ?>
