Total Complexity | 7 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | trait Resolvable |
||
20 | { |
||
21 | protected static $resolved = []; |
||
22 | |||
23 | protected static function resolveInstance($instance, ...$parameters) |
||
24 | { |
||
25 | $class = is_object($instance) ? get_class($instance) : $instance; |
||
26 | |||
27 | if (isset(self::$resolved[$class])) { |
||
28 | return self::$resolved[$class]; |
||
29 | } |
||
30 | |||
31 | return self::$resolved[$class] = is_object($instance) ? $instance : new $instance(...$parameters); |
||
32 | } |
||
33 | |||
34 | protected static function resolveCallback(string $value, callable $callback) |
||
35 | { |
||
36 | $class = static::getSameClass(); |
||
37 | |||
38 | if (isset(static::$resolved[$class][$value])) { |
||
39 | return static::$resolved[$class][$value]; |
||
40 | } |
||
41 | |||
42 | return static::$resolved[$class][$value] = $callback($value); |
||
43 | } |
||
44 | |||
45 | protected static function getSameClass(): string |
||
48 | } |
||
49 | } |
||
50 |