1 | <?php |
||
15 | trait CanImpersonate |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Main Methods |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | /** |
||
23 | * Impersonate the given user. |
||
24 | * |
||
25 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
26 | * |
||
27 | * @return bool |
||
28 | */ |
||
29 | 12 | public function impersonate(Impersonatable $impersonated) |
|
34 | |||
35 | /** |
||
36 | * Stop the impersonation. |
||
37 | * |
||
38 | * @return bool |
||
39 | */ |
||
40 | 12 | public function stopImpersonation() |
|
44 | |||
45 | /* ----------------------------------------------------------------- |
||
46 | | Check Methods |
||
47 | | ----------------------------------------------------------------- |
||
48 | */ |
||
49 | |||
50 | /** |
||
51 | * Check if the current modal can impersonate other models. |
||
52 | * |
||
53 | * @return bool |
||
54 | */ |
||
55 | abstract public function canImpersonate(); |
||
56 | |||
57 | /** |
||
58 | * Check if the current model can be impersonated. |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | abstract public function canBeImpersonated(); |
||
63 | |||
64 | /** |
||
65 | * Check if impersonation is ongoing. |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | 12 | public function isImpersonated() |
|
73 | |||
74 | /** |
||
75 | * Check if the two persons are the same. |
||
76 | * |
||
77 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | 44 | public function isSamePerson($impersonated) |
|
89 | } |
||
90 |
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.