Changeset 1370
- Timestamp:
- 02/25/08 18:56:55 (3 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ioc/stubBinding.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) (2 diffs)
- trunk/src/main/php/net/stubbles/ioc/stubClassBinding.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ioc/stubConstantBinding.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/ioc/stubDefaultInjectionProvider.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/ioc/stubInjectionProvider.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/ioc/stubInjector.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ioc/stubValueInjectionProvider.php (added)
- trunk/src/main/php/net/stubbles/ipo/session/resourcemanager/stubSessionResourceManager.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/rdbms/stubDatabaseConnectionProvider.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ioc/stubBinding.php
r1222 r1370 25 25 26 26 /** 27 * get the instance for this binding27 * returns the provider that has or creates the required instance 28 28 * 29 * @return object29 * @return stubInjectionProvider 30 30 */ 31 public function get Instance();31 public function getProvider(); 32 32 33 33 /** trunk/src/main/php/net/stubbles/ioc/stubBindingScope.php
r1222 r1370 19 19 { 20 20 /** 21 * returns the instance from the scope21 * returns the provider that has or creates the required instance 22 22 * 23 23 * @param stubBaseReflectionClass $type type of the object 24 24 * @param stubBaseReflectionClass $impl concrete implementation 25 25 * @param stubInjectionProvider $provider 26 * @return object26 * @return stubInjectionProvider 27 27 */ 28 public function get Instance(stubBaseReflectionClass $type, stubBaseReflectionClass $impl, stubInjectionProvider $provider);28 public function getProvider(stubBaseReflectionClass $type, stubBaseReflectionClass $impl, stubInjectionProvider $provider); 29 29 } 30 30 ?> trunk/src/main/php/net/stubbles/ioc/stubBindingScopeSingleton.php
r1296 r1370 8 8 */ 9 9 stubClassLoader::load('net::stubbles::ioc::stubBindingScope', 10 'net::stubbles:: reflection::stubBaseReflectionClass'10 'net::stubbles::ioc::stubValueInjectionProvider' 11 11 ); 12 12 /** … … 19 19 { 20 20 /** 21 * Instances in this scope21 * instances in this scope 22 22 * 23 * @var array<string, object>23 * @var array<string,stubValueInjectionProvider> 24 24 */ 25 25 protected $instances = array(); 26 26 27 27 /** 28 * Create the instance, if it has not been created before28 * returns the provider that has or creates the required instance 29 29 * 30 30 * @param stubBaseReflectionClass $type type of the object 31 31 * @param stubBaseReflectionClass $impl concrete implementation 32 32 * @param stubInjectionProvider $provider 33 * @return object33 * @return stubInjectionProvider 34 34 */ 35 public function get Instance(stubBaseReflectionClass $type, stubBaseReflectionClass $impl, stubInjectionProvider $provider)35 public function getProvider(stubBaseReflectionClass $type, stubBaseReflectionClass $impl, stubInjectionProvider $provider) 36 36 { 37 37 $key = $impl->getName(); 38 if ( !isset($this->instances[$key])) {39 $this->instances[$key] = $provider->get($type);38 if (isset($this->instances[$key]) === false) { 39 $this->instances[$key] = new stubValueInjectionProvider($provider->get($type)); 40 40 } 41 41 trunk/src/main/php/net/stubbles/ioc/stubClassBinding.php
r1296 r1370 143 143 144 144 /** 145 * Get the instance for this binding. 146 * 147 * This method will at first look for an existing 148 * instance in the scope and then create the instance 149 * using the injection provider. 150 * 151 * @return object 152 */ 153 public function getInstance() 154 { 155 if (null !== $this->instance) { 156 return $this->instance; 157 } 158 159 if (is_string($this->impl) === true) { 160 $this->impl = new stubReflectionClass($this->impl); 161 } 162 163 if (null === $this->scope) { 164 if ($this->impl->hasAnnotation('Singleton') === true) { 165 $this->scope = stubBindingScopes::$SINGLETON; 145 * returns the provider that has or creates the required instance 146 * 147 * This method will at first look for an existing instance in the scope and 148 * then create the instance using the injection provider. 149 * 150 * @return stubInjectionProvider 151 */ 152 public function getProvider() 153 { 154 if (null === $this->instance) { 155 if (is_string($this->impl) === true) { 156 $this->impl = new stubReflectionClass($this->impl); 166 157 } 167 } 168 169 if (null === $this->provider) { 170 $this->provider = new stubDefaultInjectionProvider($this->injector, $this->impl); 158 159 if (null === $this->scope) { 160 if ($this->impl->hasAnnotation('Singleton') === true) { 161 $this->scope = stubBindingScopes::$SINGLETON; 162 } 163 } 164 165 if (null === $this->provider) { 166 $this->provider = new stubDefaultInjectionProvider($this->injector, $this->impl); 167 } 168 } else { 169 $this->provider = new stubValueInjectionProvider($this->instance); 171 170 } 172 171 173 172 if (null !== $this->scope) { 174 return $this->scope->get Instance(new stubReflectionClass($this->type), $this->impl, $this->provider);173 return $this->scope->getProvider(new stubReflectionClass($this->type), $this->impl, $this->provider); 175 174 } 176 175 177 return $this->provider ->get(new stubReflectionClass($this->type));176 return $this->provider; 178 177 } 179 178 trunk/src/main/php/net/stubbles/ioc/stubConstantBinding.php
r1301 r1370 7 7 * @subpackage ioc 8 8 */ 9 stubClassLoader::load('net::stubbles::ioc::exceptions::stubBinding'); 9 stubClassLoader::load('net::stubbles::ioc::stubBinding', 10 'net::stubbles::ioc::stubValueInjectionProvider' 11 ); 10 12 /** 11 13 * Binding to bind a property to a constant value. … … 33 35 protected $name = null; 34 36 /** 35 * instance this type is bound to37 * provider that holds the binded value 36 38 * 37 * @var object39 * @var stubValueInjectionProvider 38 40 */ 39 protected $value = null;41 protected $valueProvider; 40 42 41 43 /** … … 46 48 public function __construct($injector) 47 49 { 48 $this->injector = $injector; 50 $this->injector = $injector; 51 $this->valueProvider = new stubValueInjectionProvider(); 49 52 } 50 53 … … 57 60 public function to($value) 58 61 { 59 $this->value = $value;62 $this->valueProvider->setValue($value); 60 63 return $this; 61 64 } … … 74 77 75 78 /** 76 * get the instance for this binding79 * returns the provider that has or creates the required instance 77 80 * 78 * @return object81 * @return stubInjectionProvider 79 82 */ 80 public function get Instance()83 public function getProvider() 81 84 { 82 return $this->value ;85 return $this->valueProvider; 83 86 } 84 87 trunk/src/main/php/net/stubbles/ioc/stubDefaultInjectionProvider.php
r1222 r1370 9 9 */ 10 10 stubClassLoader::load('net::stubbles::ioc::stubInjectionProvider', 11 'net::stubbles::ioc::stubInjector', 12 'net::stubbles::reflection::stubBaseReflectionClass' 11 'net::stubbles::ioc::stubInjector' 13 12 ); 14 13 /** … … 49 48 50 49 /** 51 * returns the object50 * returns the value to provide 52 51 * 53 * @param stubBaseReflectionClass $type 54 * @return object 52 * @param string $type 53 * @param string $name 54 * @return mixed 55 55 */ 56 public function get( stubBaseReflectionClass $type)56 public function get($type, $name = null) 57 57 { 58 58 $constructor = $this->impl->getConstructor(); trunk/src/main/php/net/stubbles/ioc/stubInjectionProvider.php
r1222 r1370 8 8 * @subpackage ioc 9 9 */ 10 stubClassLoader::load('net::stubbles::reflection::stubBaseReflectionClass');11 10 /** 12 11 * Interface for providers that create objects that are required by the … … 19 18 { 20 19 /** 21 * returns the object20 * returns the value to provide 22 21 * 23 * @param stubReflectionClass $type 24 * @return object 22 * @param string $type 23 * @param string $name 24 * @return mixed 25 25 */ 26 public function get( stubBaseReflectionClass $type);26 public function get($type, $name = null); 27 27 } 28 28 ?> trunk/src/main/php/net/stubbles/ioc/stubInjector.php
r1301 r1370 50 50 { 51 51 $binding = $this->getBinding($type, $name); 52 if (null !== $binding) {53 return $binding->getInstance();52 if (null === $binding) { 53 throw new stubBindingException('No binding for ' . $type . ' defined'); 54 54 } 55 55 56 throw new stubBindingException('No binding for ' . $type . ' defined');56 return $binding->getProvider()->get($type, $name); 57 57 } 58 58 trunk/src/main/php/net/stubbles/ipo/session/resourcemanager/stubSessionResourceManager.php
r1311 r1370 72 72 * are no two interfaces with the same name. 73 73 * 74 * @param stubBaseReflectionClass $type 74 * @param string $type 75 * @param string $name 75 76 * @return object 76 77 * @see net::stubbles::ioc::stubInjectionProvider::get() 77 78 */ 78 public function get(stubBaseReflectionClass $type) 79 { 80 $typeName = $type->getName(); 79 public function get($type, $name = null) 80 { 81 81 foreach (array_keys($this->resourceDefinitions) as $interface) { 82 82 $localName = stubClassLoader::getNonQualifiedClassName($interface); 83 if ($localName === $type Name) {83 if ($localName === $type) { 84 84 return $this->getResource($interface); 85 85 } trunk/src/main/php/net/stubbles/rdbms/stubDatabaseConnectionProvider.php
r1225 r1370 39 39 * returns the connection to be injected 40 40 * 41 * @param stubReflectionClass $type 41 * @param string $type 42 * @param string $name 42 43 * @return stubDatabaseConnection 43 44 */ 44 public function get( stubBaseReflectionClass $type)45 public function get($type, $name = null) 45 46 { 46 47 return stubDatabaseConnectionPool::getConnection($this->connectionId);
