| 1 | <?php |
||
| 7 | trait Impersonable |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Start impersonating this user. |
||
| 11 | * |
||
| 12 | * @return $this |
||
| 13 | */ |
||
| 14 | public function impersonate() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Stop impersonating. |
||
| 23 | * |
||
| 24 | * @return $this |
||
| 25 | */ |
||
| 26 | public function unimpersonate() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Check if user is impersonating. |
||
| 35 | * |
||
| 36 | * @return bool |
||
| 37 | */ |
||
| 38 | public function isImpersonating() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get impersonating user id. |
||
| 45 | * |
||
| 46 | * @return int |
||
| 47 | */ |
||
| 48 | public function getImpersonatingId() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Get impersonating key. |
||
| 55 | * |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | public function getImpersonatingKey() |
||
| 62 | } |
||
| 63 |
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
Idableprovides a methodequalsIdthat 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.