1 | <?php |
||
20 | trait MakesResources |
||
21 | { |
||
22 | /** |
||
23 | * A list of cached related resources. |
||
24 | * |
||
25 | * @var \League\Fractal\ResourceInterface[] |
||
26 | */ |
||
27 | protected $resources = []; |
||
28 | |||
29 | /** |
||
30 | * Make a resource. |
||
31 | * |
||
32 | * @param mixed $data |
||
33 | * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer |
||
34 | * @param string|null $resourceKey |
||
35 | * @return \League\Fractal\Resource\ResourceInterface |
||
36 | */ |
||
37 | 22 | protected function resource($data = null, $transformer = null, string $resourceKey = null): ResourceInterface |
|
47 | |||
48 | /** |
||
49 | * Include a related resource. |
||
50 | * |
||
51 | * @param string $identifier |
||
52 | * @param mixed $data |
||
53 | * @param array $parameters |
||
54 | * @return \League\Fractal\Resource\ResourceInterface |
||
55 | * @throws \LogicException |
||
56 | */ |
||
57 | 23 | protected function includeResource(string $identifier, $data, array $parameters): ResourceInterface |
|
75 | |||
76 | /** |
||
77 | * Include a related resource from a model and cache the resource type for following calls. |
||
78 | * |
||
79 | * @param \Illuminate\Database\Eloquent\Model $model |
||
80 | * @param string $identifier |
||
81 | * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer |
||
82 | * @return \League\Fractal\Resource\ResourceInterface |
||
83 | */ |
||
84 | 19 | protected function includeResourceFromModel(Model $model, string $identifier, $transformer = null): ResourceInterface |
|
96 | |||
97 | /** |
||
98 | * Indicates if the resource should be cached. |
||
99 | * |
||
100 | * @param mixed $data |
||
101 | * @return bool |
||
102 | */ |
||
103 | 19 | protected function shouldCacheResource($data): bool |
|
107 | |||
108 | /** |
||
109 | * Resolve a container using the resolver callback. |
||
110 | * |
||
111 | * @return \Illuminate\Contracts\Container\Container |
||
112 | */ |
||
113 | protected abstract function resolveContainer(): Container; |
||
114 | |||
115 | /** |
||
116 | * Resolve relation data from a model. |
||
117 | * |
||
118 | * @param \Illuminate\Database\Eloquent\Model $model |
||
119 | * @param string $identifier |
||
120 | * @return mixed |
||
121 | */ |
||
122 | protected abstract function resolveRelation(Model $model, string $identifier); |
||
123 | |||
124 | /** |
||
125 | * Get a related transformer class mapped to a relation identifier. |
||
126 | * |
||
127 | * @param string $identifier |
||
128 | * @return string |
||
129 | */ |
||
130 | protected abstract function mappedTransformerClass(string $identifier); |
||
131 | } |