| 40 | | foreach ($this->bindings as $binding) { |
|---|
| 41 | | if ($binding->getKey() === $key) { |
|---|
| 42 | | $scope = $binding->getScope(); |
|---|
| 43 | | if ($scope != null) { |
|---|
| 44 | | return $scope->getInstance($key, $binding); |
|---|
| 45 | | } else { |
|---|
| 46 | | return $binding->getInstance(); |
|---|
| 47 | | } |
|---|
| | 47 | if (!empty($this->bindings)) { |
|---|
| | 48 | $this->updateIndex(); |
|---|
| | 49 | } |
|---|
| | 50 | |
|---|
| | 51 | if (isset($this->bindingIndex[$key])) { |
|---|
| | 52 | $binding = $this->bindingIndex[$key]; |
|---|
| | 53 | $scope = $binding->getScope(); |
|---|
| | 54 | if ($scope != null) { |
|---|
| | 55 | return $scope->getInstance($key, $binding); |
|---|
| | 56 | } else { |
|---|
| | 57 | return $binding->getInstance(); |
|---|
| | 79 | } |
|---|
| | 80 | |
|---|
| | 81 | /** |
|---|
| | 82 | * Update the binding index |
|---|
| | 83 | */ |
|---|
| | 84 | protected function updateIndex() { |
|---|
| | 85 | foreach ($this->bindings as $binding) { |
|---|
| | 86 | $this->bindingIndex[$this->createKey($binding)] = $binding; |
|---|
| | 87 | } |
|---|
| | 88 | $this->bindings = array(); |
|---|
| | 89 | } |
|---|
| | 90 | |
|---|
| | 91 | /** |
|---|
| | 92 | * Creates a unique key for a binding |
|---|
| | 93 | * |
|---|
| | 94 | * @param stubBinding $binding |
|---|
| | 95 | * @todo Key must also contain @Named() annotation value |
|---|
| | 96 | */ |
|---|
| | 97 | protected function createKey(stubBinding $binding) { |
|---|
| | 98 | $interface = $binding->getKey(); |
|---|
| | 99 | if ($interface instanceof stubReflectionClass) { |
|---|
| | 100 | $interface = $interface->getName(); |
|---|
| | 101 | } |
|---|
| | 102 | return $interface; |
|---|