| Total Complexity | 9 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | trait ContainerReflectionTrait |
||
| 23 | { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $key |
||
| 27 | * @param $object |
||
| 28 | */ |
||
| 29 | protected function rawSet(string $key, $object) |
||
| 30 | { |
||
| 31 | $this->objects[$key] = $object; |
||
|
|
|||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param string $key |
||
| 36 | * @param $object |
||
| 37 | * @param null $params |
||
| 38 | */ |
||
| 39 | protected function iOc(string $key, $object, $params = null): void |
||
| 40 | { |
||
| 41 | $reflection = new ReflectionClass($object); |
||
| 42 | $constructor = $reflection->getConstructor(); |
||
| 43 | |||
| 44 | if ($constructor && $constructor->getNumberOfParameters()) { |
||
| 45 | $paramsIoC = $this->getParamsIoC($constructor, $params); |
||
| 46 | $this->objects[$key] = $reflection->newInstanceArgs($paramsIoC); |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | $this->objects[$key] = new $object; |
||
| 51 | } |
||
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * @param ReflectionMethod $constructor |
||
| 56 | * @param $params |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | protected function getParamsIoC(ReflectionMethod $constructor, $params): array |
||
| 78 | } |
||
| 79 | } |