| @@ 14-61 (lines=48) @@ | ||
| 11 | * |
|
| 12 | * @author Hugues Maignol <[email protected]> |
|
| 13 | */ |
|
| 14 | final class DefaultExtractionStrategies implements ExtractionStrategies |
|
| 15 | { |
|
| 16 | ||
| 17 | use StrategyCachingCapabilities; |
|
| 18 | ||
| 19 | private $strategies; |
|
| 20 | ||
| 21 | public function all() : TypedCollection |
|
| 22 | { |
|
| 23 | if ($this->strategies == null) { |
|
| 24 | return $this->strategies = new TypedCollection( |
|
| 25 | ExtractionStrategyInterface::class, |
|
| 26 | [ |
|
| 27 | new GetterStrategy, |
|
| 28 | new NamedMethodStrategy, |
|
| 29 | new ReflectionStrategy, |
|
| 30 | ] |
|
| 31 | ); |
|
| 32 | } |
|
| 33 | ||
| 34 | return $this->strategies; |
|
| 35 | } |
|
| 36 | ||
| 37 | public function get($object, string $key) : ExtractionStrategyInterface |
|
| 38 | { |
|
| 39 | $strategy = $this->getCachedStrategy(get_class($object), $key); |
|
| 40 | if (null !== $strategy) { |
|
| 41 | return $strategy; |
|
| 42 | } |
|
| 43 | ||
| 44 | foreach ($this->all() as $strategy) { |
|
| 45 | if ($strategy->supports($object, $key)) { |
|
| 46 | ||
| 47 | $this->setCachedStrategy(get_class($object), $key, $strategy); |
|
| 48 | ||
| 49 | return $strategy; |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||
| 53 | throw new LogicException( |
|
| 54 | sprintf( |
|
| 55 | 'Property "%s" cannot be extracted', |
|
| 56 | $key |
|
| 57 | ) |
|
| 58 | ); |
|
| 59 | } |
|
| 60 | ||
| 61 | } |
|
| 62 | ||
| @@ 14-59 (lines=46) @@ | ||
| 11 | * |
|
| 12 | * @author Hugues Maignol <[email protected]> |
|
| 13 | */ |
|
| 14 | final class DefaultInjectionStrategies implements InjectionStrategies |
|
| 15 | { |
|
| 16 | use StrategyCachingCapabilities; |
|
| 17 | ||
| 18 | private $strategies; |
|
| 19 | ||
| 20 | public function all() : TypedCollection |
|
| 21 | { |
|
| 22 | if ($this->strategies == null) { |
|
| 23 | return $this->strategies = new TypedCollection( |
|
| 24 | InjectionStrategyInterface::class, |
|
| 25 | [ |
|
| 26 | new SetterStrategy, |
|
| 27 | new NamedMethodStrategy, |
|
| 28 | new ReflectionStrategy, |
|
| 29 | ] |
|
| 30 | ); |
|
| 31 | } |
|
| 32 | ||
| 33 | return $this->strategies; |
|
| 34 | } |
|
| 35 | ||
| 36 | public function get($object, string $key, $value) : InjectionStrategyInterface |
|
| 37 | { |
|
| 38 | $strategy = $this->getCachedStrategy(get_class($object), $key); |
|
| 39 | if (null !== $strategy) { |
|
| 40 | return $strategy; |
|
| 41 | } |
|
| 42 | ||
| 43 | foreach ($this->all() as $strategy) { |
|
| 44 | if ($strategy->supports($object, $key, $value)) { |
|
| 45 | ||
| 46 | $this->setCachedStrategy(get_class($object), $key, $strategy); |
|
| 47 | ||
| 48 | return $strategy; |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||
| 52 | throw new LogicException( |
|
| 53 | sprintf( |
|
| 54 | 'Property "%s" cannot be injected', |
|
| 55 | $key |
|
| 56 | ) |
|
| 57 | ); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||