|
13 | 13 | use function str_starts_with; |
14 | 14 | use function trim; |
15 | 15 |
|
16 | | -abstract class DataStructuresBuilder |
| 16 | +abstract class DataStructuresProvider |
17 | 17 | { |
18 | | - /** |
19 | | - * Caller object instance, where defined data structure getters like caller::getUserStructure() |
20 | | - */ |
21 | | - protected static object $caller; |
22 | | - |
23 | | - public static function includeNestedRelations(object $caller, array &$item, array $relations): void |
| 18 | + protected static function includeNestedRelations(array &$item, array $relations): void |
24 | 19 | { |
25 | 20 | if (empty($relations)) { |
26 | 21 | return; |
27 | 22 | } |
28 | 23 |
|
29 | | - self::setCallerObject($caller); |
30 | | - |
31 | 24 | foreach ($relations as $relation) { |
32 | 25 | $parentRelations = explode('.', $relation); |
33 | 26 | self::includeNestedRelation($item, $parentRelations); |
@@ -71,22 +64,11 @@ protected static function includeNestedRelation(array &$item, array $parentRelat |
71 | 64 |
|
72 | 65 | protected static function getItemStructure(string $relationItem): array |
73 | 66 | { |
74 | | - $caller = self::getCallerObject(); |
75 | 67 | $method = 'get' . $relationItem . 'Structure'; |
76 | | - if (! is_callable([$caller, $method])) { |
| 68 | + if (! is_callable(['static', $method])) { |
77 | 69 | throw new InvalidArgumentException('Getter method for structure "' . $relationItem . '" does not exists'); |
78 | 70 | } |
79 | 71 |
|
80 | | - return $caller->$method(); |
81 | | - } |
82 | | - |
83 | | - protected static function setCallerObject(object $caller): void |
84 | | - { |
85 | | - self::$caller = $caller; |
86 | | - } |
87 | | - |
88 | | - protected static function getCallerObject(): object |
89 | | - { |
90 | | - return self::$caller; |
| 72 | + return static::$method(); |
91 | 73 | } |
92 | 74 | } |
0 commit comments