| @@ 53-75 (lines=23) @@ | ||
| 50 | return $this->strategies; |
|
| 51 | } |
|
| 52 | ||
| 53 | public function get($object, string $key): ExtractionStrategyInterface |
|
| 54 | { |
|
| 55 | $strategy = $this->getCachedStrategy(get_class($object), $key); |
|
| 56 | if (null !== $strategy) { |
|
| 57 | return $strategy; |
|
| 58 | } |
|
| 59 | ||
| 60 | foreach ($this->all() as $strategy) { |
|
| 61 | if ($strategy->supports($object, $key)) { |
|
| 62 | ||
| 63 | $this->setCachedStrategy(get_class($object), $key, $strategy); |
|
| 64 | ||
| 65 | return $strategy; |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||
| 69 | throw new LogicException( |
|
| 70 | sprintf( |
|
| 71 | 'Property "%s" cannot be extracted', |
|
| 72 | $key |
|
| 73 | ) |
|
| 74 | ); |
|
| 75 | } |
|
| 76 | ||
| 77 | } |
|
| 78 | ||
| @@ 51-73 (lines=23) @@ | ||
| 48 | return $this->strategies; |
|
| 49 | } |
|
| 50 | ||
| 51 | public function get($object, string $key, $value): InjectionStrategyInterface |
|
| 52 | { |
|
| 53 | $strategy = $this->getCachedStrategy(get_class($object), $key); |
|
| 54 | if (null !== $strategy) { |
|
| 55 | return $strategy; |
|
| 56 | } |
|
| 57 | ||
| 58 | foreach ($this->all() as $strategy) { |
|
| 59 | if ($strategy->supports($object, $key, $value)) { |
|
| 60 | ||
| 61 | $this->setCachedStrategy(get_class($object), $key, $strategy); |
|
| 62 | ||
| 63 | return $strategy; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| 67 | throw new LogicException( |
|
| 68 | sprintf( |
|
| 69 | 'Property "%s" cannot be injected', |
|
| 70 | $key |
|
| 71 | ) |
|
| 72 | ); |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||