1 | <?php |
||
8 | trait HasAccess |
||
9 | { |
||
10 | /** |
||
11 | * @var \Illuminate\Support\Collection |
||
12 | */ |
||
13 | protected $abilities; |
||
14 | |||
15 | /** |
||
16 | * Access observer class |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $observer = \Sco\Admin\Component\Observer::class; |
||
21 | |||
22 | /** |
||
23 | * User exposed observable abilities. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $observables = []; |
||
28 | |||
29 | public function bootHasAccess() |
||
35 | |||
36 | public function isView() |
||
40 | |||
41 | public function isCreate() |
||
45 | |||
46 | public function isEdit() |
||
50 | |||
51 | public function isDelete() |
||
55 | |||
56 | public function isDestroy() |
||
60 | |||
61 | public function isRestore() |
||
65 | |||
66 | protected function isRestorableModel() |
||
70 | |||
71 | /** |
||
72 | * Register an observer with the Component. |
||
73 | * |
||
74 | * @param $class |
||
75 | */ |
||
76 | public function observe($class) |
||
89 | |||
90 | /** |
||
91 | * Get the observable ability names. |
||
92 | * |
||
93 | * @return array |
||
94 | */ |
||
95 | public function getObservableAbilities() |
||
105 | |||
106 | public function registerAbility($ability, $callback) |
||
110 | |||
111 | protected function makeAbilityCallback($callback) |
||
123 | |||
124 | /** |
||
125 | * @param string $ability |
||
126 | * |
||
127 | * @return mixed |
||
128 | */ |
||
129 | final public function can($ability) |
||
138 | |||
139 | public function getAccesses() |
||
145 | } |
||
146 |
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.