1 | <?php |
||
19 | trait Loggable |
||
20 | { |
||
21 | /** |
||
22 | * The name of the scope that is applied to make trashed versions to be |
||
23 | * viewable |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | static public $LOGGABLE_SCOPE = 'view trashed versions'; |
||
28 | |||
29 | /** |
||
30 | * Previous (to the change referenced in the request query) changes made |
||
31 | * to this model |
||
32 | * |
||
33 | * @var Collection |
||
34 | */ |
||
35 | private $previous_changes; |
||
36 | |||
37 | /** |
||
38 | * Get the polymorphic relationship to Changes |
||
39 | * |
||
40 | * @return Illuminate\Database\Eloquent\Relations\Relation |
||
41 | */ |
||
42 | public function changes() |
||
46 | |||
47 | /** |
||
48 | * Boot events |
||
49 | * |
||
50 | * @return void |
||
51 | */ |
||
52 | public static function bootLoggable() |
||
69 | |||
70 | /** |
||
71 | * Should this model log it's changes. Defaults to true if the change |
||
72 | * happened while handling an admin request or via the console but not |
||
73 | * during a non-http unit test. |
||
74 | * |
||
75 | * @param string $action Like "deleted", "updated", etc |
||
76 | * @return boolean |
||
77 | */ |
||
78 | public function shouldLogChange($action) |
||
83 | |||
84 | /** |
||
85 | * Show trashed models for matching change |
||
86 | * |
||
87 | * @param Builder $builder |
||
88 | * @return void |
||
89 | */ |
||
90 | private static function showTrashedVersion(Builder $builder) |
||
98 | |||
99 | /** |
||
100 | * Get a Change record mentioned in the query, if appropriate |
||
101 | * |
||
102 | * @return Change|void |
||
103 | */ |
||
104 | private static function lookupRequestedChange() |
||
124 | |||
125 | /** |
||
126 | * Does the Change referenced in the GET query match the conditions already |
||
127 | * applied in the query builder? |
||
128 | * |
||
129 | * @param Change $change |
||
130 | * @param Builder $builder |
||
131 | * @return boolean |
||
132 | */ |
||
133 | private static function builderMatchesChange(Change $change, Builder $builder) |
||
162 | |||
163 | /** |
||
164 | * Replace all the attributes with those from the specified Change specified |
||
165 | * in the reqeust query. |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | private function replaceAttributesWithChange() |
||
180 | |||
181 | /** |
||
182 | * Get the attributes of the model at a given Change |
||
183 | * |
||
184 | * @param Change $change |
||
185 | * @return array |
||
186 | */ |
||
187 | private function attributesAtChange(Change $change) |
||
196 | |||
197 | /** |
||
198 | * Get the list of pervious changes of this model, storing it to reduce |
||
199 | * future lookups |
||
200 | * |
||
201 | * @param Change $change |
||
202 | * @return Collection |
||
203 | */ |
||
204 | private function previousChanges(Change $change) |
||
212 | |||
213 | } |
||
214 |
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.