1 | <?php |
||
17 | trait Versionable |
||
18 | { |
||
19 | static protected $versioning = true; |
||
20 | |||
21 | // You can add these properties to you versionable model |
||
22 | //protected $versionable = []; |
||
23 | //protected $dontVersionable = ['*']; |
||
24 | |||
25 | 6 | public static function bootVersionable() |
|
39 | |||
40 | 6 | private static function createVersionForModel(Model $model): void |
|
47 | |||
48 | /** |
||
49 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
50 | */ |
||
51 | 6 | public function versions(): MorphMany |
|
55 | |||
56 | /** |
||
57 | * @return \Illuminate\Database\Eloquent\Relations\MorphOne |
||
58 | */ |
||
59 | 4 | public function lastVersion(): MorphOne |
|
63 | |||
64 | /** |
||
65 | * @param int $id |
||
66 | * |
||
67 | * @return \Illuminate\Database\Eloquent\Model|null |
||
68 | */ |
||
69 | 1 | public function getVersion($id) |
|
73 | |||
74 | /** |
||
75 | * @param int $id |
||
76 | * |
||
77 | * @return mixed |
||
78 | */ |
||
79 | 1 | public function revertToVersion($id) |
|
83 | |||
84 | /** |
||
85 | * @param int $keep |
||
86 | */ |
||
87 | 6 | public function removeOldVersions(int $keep): void |
|
95 | |||
96 | 1 | public function removeAllVersions() |
|
100 | |||
101 | /** |
||
102 | * @return bool |
||
103 | */ |
||
104 | 6 | public function shouldVersioning(): bool |
|
108 | |||
109 | /** |
||
110 | * @return array |
||
111 | */ |
||
112 | 6 | public function getVersionableAttributes(): array |
|
133 | |||
134 | /** |
||
135 | * @param array $attributes |
||
136 | * |
||
137 | * @return $this |
||
138 | * |
||
139 | * @throws \Exception |
||
140 | */ |
||
141 | public function setVersionable(array $attributes) |
||
151 | |||
152 | /** |
||
153 | * @param array $attributes |
||
154 | * |
||
155 | * @return $this |
||
156 | * |
||
157 | * @throws \Exception |
||
158 | */ |
||
159 | public function setDontVersionable(array $attributes) |
||
169 | |||
170 | /** |
||
171 | * @return array |
||
172 | */ |
||
173 | 6 | public function getVersionable(): array |
|
177 | |||
178 | /** |
||
179 | * @return array |
||
180 | */ |
||
181 | public function getDontVersionable(): array |
||
185 | |||
186 | /** |
||
187 | * @return string |
||
188 | */ |
||
189 | 6 | public function getVersionStrategy() |
|
193 | |||
194 | /** |
||
195 | * @param string $strategy |
||
196 | * |
||
197 | * @return $this |
||
198 | * |
||
199 | * @throws \Exception |
||
200 | */ |
||
201 | 1 | public function setVersionStrategy(string $strategy) |
|
211 | |||
212 | /** |
||
213 | * @return string |
||
214 | */ |
||
215 | 6 | public function getVersionModel(): string |
|
219 | |||
220 | /** |
||
221 | * @return string |
||
222 | */ |
||
223 | 6 | public function getKeepVersionsCount(): string |
|
227 | |||
228 | /** |
||
229 | * Get the versionable attributes of a given array. |
||
230 | * |
||
231 | * @param array $attributes |
||
232 | * |
||
233 | * @return array |
||
234 | */ |
||
235 | 6 | public function versionableFromArray(array $attributes): array |
|
247 | |||
248 | /** |
||
249 | * @param callable $callback |
||
250 | */ |
||
251 | 1 | public static function withoutVersion(callable $callback) |
|
259 | } |
||
260 |
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.