1 | <?php |
||
16 | abstract class Policy implements PolicyContract |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Properties |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | /** |
||
24 | * Default metas for the abilities. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $metas = []; |
||
29 | |||
30 | /* ----------------------------------------------------------------- |
||
31 | | Getters & Setters |
||
32 | | ----------------------------------------------------------------- |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * Get the ability's prefix. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | 28 | protected static function prefix(): string |
|
44 | |||
45 | /** |
||
46 | * Set the default metas for the abilities. |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | 28 | protected function getMetas(): array |
|
54 | |||
55 | /** |
||
56 | * Set the default metas for the abilities. |
||
57 | * |
||
58 | * @param array $metas |
||
59 | * |
||
60 | * @return $this |
||
61 | */ |
||
62 | 20 | protected function setMetas(array $metas) |
|
68 | |||
69 | /* ----------------------------------------------------------------- |
||
70 | | Main Methods |
||
71 | | ----------------------------------------------------------------- |
||
72 | */ |
||
73 | |||
74 | /** |
||
75 | * Get the ability's key. |
||
76 | * |
||
77 | * @param array|string $keys |
||
78 | * |
||
79 | * @return array|string |
||
80 | */ |
||
81 | 12 | public static function ability($keys) |
|
82 | { |
||
83 | 12 | if (is_string($keys)) |
|
84 | 8 | return static::prefixedKey($keys); |
|
85 | |||
86 | 4 | return array_map(function (string $key) { |
|
87 | 4 | return static::prefixedKey($key); |
|
88 | 4 | }, (array) $keys); |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * Make a new ability. |
||
93 | * |
||
94 | * @param string $key |
||
95 | * @param string|null $method |
||
96 | * |
||
97 | * @return \Arcanedev\LaravelPolicies\Contracts\Ability |
||
98 | */ |
||
99 | 28 | protected function makeAbility(string $key, $method = null): AbilityContract |
|
106 | |||
107 | /** |
||
108 | * Get a prefixed key. |
||
109 | * |
||
110 | * @param string $key |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 36 | protected static function prefixedKey(string $key): string |
|
120 | |||
121 | /** |
||
122 | * Prepare the method name. |
||
123 | * |
||
124 | * @param string $method |
||
125 | * |
||
126 | * @return string|null |
||
127 | */ |
||
128 | 28 | protected static function prepareMethod(string $method): ?string |
|
142 | } |
||
143 |