Changeset 863
- Timestamp:
- 08/21/07 22:42:31 (1 year ago)
- Files:
-
- trunk/experiments/people/schst/ioc/provider.php (modified) (1 diff)
- trunk/experiments/people/schst/ioc/simple.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ioc/stubBinding.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ioc/stubBindingModule.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ioc/stubBindingScope.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ioc/stubBindingScopeSingleton.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ioc/stubClassBinding.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/ioc/stubConstantBinding.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/experiments/people/schst/ioc/provider.php
r856 r863 61 61 $binder = new stubBinder(); 62 62 63 $binder->bind('Person')->to ('PersonImpl')->toProvider(new MyProvider());63 $binder->bind('Person')->toProvider(new MyProvider()); 64 64 $injector = $binder->getInjector(); 65 65 trunk/experiments/people/schst/ioc/simple.php
r852 r863 117 117 $vehicle->getDriver()->sayHello(); 118 118 $vehicle->moveForward(); 119 120 print_r($vehicle); 119 121 ?> trunk/src/main/php/net/stubbles/ioc/stubBinding.php
r852 r863 13 13 * @package stubbles 14 14 * @subpackage ioc_injection 15 * @todo Introduce providers that create the concrete instances16 15 */ 17 16 interface stubBinding extends stubObject { trunk/src/main/php/net/stubbles/ioc/stubBindingModule.php
r861 r863 13 13 * @package stubbles 14 14 * @subpackage ioc_injection 15 * @todo Introduce providers that create the concrete instances16 15 */ 17 16 interface stubBindingModule extends stubObject { trunk/src/main/php/net/stubbles/ioc/stubBindingScope.php
r855 r863 14 14 */ 15 15 interface stubBindingScope extends stubObject { 16 public function getInstance(stubReflectionClass $type, stubBinding $binding); 17 16 public function getInstance(stubReflectionClass $type, stubReflectionClass $impl, stubInjectionProvider $provider); 18 17 } 19 18 ?> trunk/src/main/php/net/stubbles/ioc/stubBindingScopeSingleton.php
r855 r863 28 28 * Create the instance, if it has not been created before 29 29 * 30 * @param string $key 31 * @param stubBinding $binding 30 * @param stubReflectionClass $type type of the object 31 * @param stubReflectionClass $impl concrete implementation 32 * @param stubInjectionProvider $provider 32 33 * @return object 33 34 */ 34 public function getInstance(stubReflectionClass $type, stub Binding $binding) {35 $key = $ type->getName();35 public function getInstance(stubReflectionClass $type, stubReflectionClass $impl, stubInjectionProvider $provider) { 36 $key = $impl->getName(); 36 37 if (!isset($this->instances[$key])) { 37 $this->instances[$key] = $ binding->create();38 $this->instances[$key] = $provider->get($type); 38 39 } 39 40 return $this->instances[$key]; trunk/src/main/php/net/stubbles/ioc/stubClassBinding.php
r856 r863 14 14 * @package stubbles 15 15 * @subpackage ioc_injection 16 * @todo Introduce providers that create the concrete instances17 16 */ 18 17 class stubClassBinding extends stubBaseObject implements stubBinding { … … 171 170 } 172 171 } 173 if ($this->scope != null) {174 return $this->scope->getInstance($this->impl, $this);175 }176 return $this->create();177 }178 172 179 /**180 * Create an instance181 *182 * @return object183 */184 public function create() {185 if (is_string($this->impl)) {186 $this->impl = new stubReflectionClass($this->impl);187 }188 173 if ($this->provider === null) { 189 174 $this->provider = new stubDefaultInjectionProvider($this->injector, $this->impl); 175 } 176 177 if ($this->scope != null) { 178 return $this->scope->getInstance(new stubReflectionClass($this->type), $this->impl, $this->provider); 190 179 } 191 180 return $this->provider->get(new stubReflectionClass($this->type)); trunk/src/main/php/net/stubbles/ioc/stubConstantBinding.php
r852 r863 13 13 * @package stubbles 14 14 * @subpackage ioc_injection 15 * @todo Introduce providers that create the concrete instances16 15 */ 17 16 class stubConstantBinding extends stubBaseObject implements stubBinding {
