1 | <?php |
||
14 | trait HasRelationships |
||
15 | { |
||
16 | /** |
||
17 | * List of available relations. |
||
18 | * |
||
19 | * @var string[] |
||
20 | */ |
||
21 | protected $relations = ['*']; |
||
22 | |||
23 | /** |
||
24 | * A list of autoloaded default relations. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $load = []; |
||
29 | |||
30 | /** |
||
31 | * Indicates if the transformer has whitelisted all relations. |
||
32 | * |
||
33 | * @return bool |
||
34 | */ |
||
35 | 3 | public function allRelationsAllowed(): bool |
|
39 | |||
40 | /** |
||
41 | * Get a list of whitelisted relations. |
||
42 | * |
||
43 | * @return string[] |
||
44 | */ |
||
45 | public function getRelations(): array |
||
51 | |||
52 | /** |
||
53 | * Get a list of default relations. |
||
54 | * |
||
55 | * @return string[] |
||
56 | */ |
||
57 | public function getDefaultRelations(): array |
||
67 | |||
68 | /** |
||
69 | * Extract a deep list of default relations, recursively. |
||
70 | * |
||
71 | * @return string[] |
||
72 | */ |
||
73 | public function extractDefaultRelations(): array |
||
83 | |||
84 | /** |
||
85 | * Extract a deep list of default relations, recursively. |
||
86 | * |
||
87 | * @param string $method |
||
88 | * @return \Closure |
||
89 | */ |
||
90 | public function makeEagerLoadCallback(string $method): Closure |
||
96 | } |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.