Changeset 1178
- Timestamp:
- 12/23/07 00:05:32 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ioc/stubInjector.php
r1176 r1178 18 18 * @package stubbles 19 19 * @subpackage ioc 20 * @todo Improve the check for the index update21 20 */ 22 21 class stubInjector extends stubBaseObject implements stubClonable … … 27 26 * @var array<stubBinding> 28 27 */ 29 protected $bindings = array();28 protected $bindings = array(); 30 29 /** 31 30 * index for faster access to bindings 32 31 * 33 * @var array<string,stubBinding> 32 * Do not access this array directly, use getIndex() instead. 33 * 34 * @var array<string,stubBinding> 35 * @see stubInjector::getIndex() 34 36 */ 35 pr otected$bindingIndex = array();37 private $bindingIndex = array(); 36 38 37 39 /** … … 44 46 public function getInstance($type, $name = null) 45 47 { 46 if (empty($this->bindings) === false) {47 $this->updateIndex();48 }49 50 48 $binding = $this->getBinding($type, $name); 51 49 if (null !== $binding) { … … 75 73 76 74 /** 77 * updates the binding index78 */79 protected function updateIndex()80 {81 foreach ($this->bindings as $binding) {82 $this->bindingIndex[$binding->getKey()] = $binding;83 }84 85 $this->bindings = array();86 }87 88 /**89 75 * adds a new binding to the injector 90 76 * … … 106 92 protected function getBinding($type, $name = null) 107 93 { 94 $bindingIndex = $this->getIndex(); 108 95 if (null !== $name) { 109 if (isset($ this->bindingIndex[$type.'#'.$name]) === true) {110 return $ this->bindingIndex[$type.'#'.$name];96 if (isset($bindingIndex[$type.'#'.$name]) === true) { 97 return $bindingIndex[$type.'#'.$name]; 111 98 } 112 99 } 113 100 114 if (isset($ this->bindingIndex[$type]) === true) {115 return $ this->bindingIndex[$type];101 if (isset($bindingIndex[$type]) === true) { 102 return $bindingIndex[$type]; 116 103 } 117 104 118 105 return null; 106 } 107 108 /** 109 * returns the binding index 110 * 111 * @return array<string,stubBinding> 112 */ 113 protected function getIndex() 114 { 115 if (empty($this->bindings) === true) { 116 return $this->bindingIndex; 117 } 118 119 foreach ($this->bindings as $binding) { 120 $this->bindingIndex[$binding->getKey()] = $binding; 121 } 122 123 $this->bindings = array(); 124 return $this->bindingIndex; 119 125 } 120 126 … … 128 134 public function hasBinding($type, $name = null) 129 135 { 130 if (empty($this->bindings) === false) {131 $this->updateIndex();132 }133 134 136 return ($this->getBinding($type, $name) != null); 135 137 }
