1 | <?php |
||
15 | trait HashIdTrait |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * endpoint to be skipped from decoding their ID's (example for external ID's) |
||
20 | * @var array |
||
21 | */ |
||
22 | private $skippedEndpoints = [ |
||
23 | // 'orders/{id}/external', |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * All ID's passed with all endpoints will be decoded before entering the Application |
||
28 | */ |
||
29 | public function runEndpointsHashedIdsDecoder() |
||
49 | |||
50 | /** |
||
51 | * @param $id |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | public function decodeThisId($id) |
||
63 | |||
64 | /** |
||
65 | * Will be used by the Eloquent Models (since it's used as trait there). |
||
66 | * |
||
67 | * @param null $key |
||
68 | * |
||
69 | * @return mixed |
||
70 | */ |
||
71 | public function getHashedKey($key = null) |
||
80 | |||
81 | |||
82 | /** |
||
83 | * without decoding the encoded ID's you won't be able to use |
||
84 | * validation features like `exists:table,id` |
||
85 | * |
||
86 | * @param array $requestData |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | private function decodeHashedIdsBeforeValidatingThem(Array $requestData) |
||
107 | |||
108 | /** |
||
109 | * @param $id |
||
110 | * |
||
111 | * @return mixed |
||
112 | */ |
||
113 | private function decoder($id) |
||
117 | |||
118 | /** |
||
119 | * @param $id |
||
120 | * |
||
121 | * @return mixed |
||
122 | */ |
||
123 | private function encoder($id) |
||
127 | |||
128 | } |
||
129 |
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.