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