|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arcanedev\LaravelPolicies\Contracts; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Contracts\Support\{Arrayable, Jsonable}; |
|
8
|
|
|
use Closure; |
|
9
|
|
|
use JsonSerializable; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Interface Ability |
|
13
|
|
|
* |
|
14
|
|
|
* @author ARCANEDEV <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
interface Ability extends Arrayable, JsonSerializable, Jsonable |
|
17
|
|
|
{ |
|
18
|
|
|
/* ----------------------------------------------------------------- |
|
19
|
|
|
| Getters & Setters |
|
20
|
|
|
| ----------------------------------------------------------------- |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Get the ability's key. |
|
25
|
|
|
* |
|
26
|
|
|
* @return string |
|
27
|
|
|
*/ |
|
28
|
|
|
public function key(): string; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Set the ability's key. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $key |
|
34
|
|
|
* |
|
35
|
|
|
* @return $this |
|
36
|
|
|
*/ |
|
37
|
|
|
public function setKey(string $key); |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get the ability's method. |
|
41
|
|
|
* |
|
42
|
|
|
* @return \Closure|string |
|
43
|
|
|
*/ |
|
44
|
|
|
public function method(); |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get the ability's method name. |
|
48
|
|
|
* |
|
49
|
|
|
* @return string|null |
|
50
|
|
|
*/ |
|
51
|
|
|
public function methodName(); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the ability's class name. |
|
55
|
|
|
* |
|
56
|
|
|
* @param bool $fqn |
|
57
|
|
|
* |
|
58
|
|
|
* @return string|null |
|
59
|
|
|
*/ |
|
60
|
|
|
public function className(bool $fqn = true); |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Set the callback as method. |
|
64
|
|
|
* |
|
65
|
|
|
* @param \Closure $callback |
|
66
|
|
|
* |
|
67
|
|
|
* @return $this |
|
68
|
|
|
*/ |
|
69
|
|
|
public function callback(Closure $callback); |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Set the ability's method. |
|
73
|
|
|
* |
|
74
|
|
|
* @param \Closure|string $method |
|
75
|
|
|
* |
|
76
|
|
|
* @return $this |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setMethod($method); |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get the ability's meta. |
|
82
|
|
|
* |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
public function metas(): array; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Set the ability's meta. |
|
89
|
|
|
* |
|
90
|
|
|
* @param array $metas |
|
91
|
|
|
* @param bool $keepMetas |
|
92
|
|
|
* |
|
93
|
|
|
* @return $this |
|
94
|
|
|
*/ |
|
95
|
|
|
public function setMetas(array $metas, bool $keepMetas = true); |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get a meta. |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $key |
|
101
|
|
|
* @param mixed|null $default |
|
102
|
|
|
* |
|
103
|
|
|
* @return mixed |
|
104
|
|
|
*/ |
|
105
|
|
|
public function meta(string $key, $default = null); |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Set a meta. |
|
109
|
|
|
* |
|
110
|
|
|
* @param string $key |
|
111
|
|
|
* @param mixed $value |
|
112
|
|
|
* |
|
113
|
|
|
* @return $this |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setMeta(string $key, $value); |
|
116
|
|
|
|
|
117
|
|
|
/* ----------------------------------------------------------------- |
|
118
|
|
|
| Check Methods |
|
119
|
|
|
| ----------------------------------------------------------------- |
|
120
|
|
|
*/ |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Check if the ability is a callback method. |
|
124
|
|
|
* |
|
125
|
|
|
* @return bool |
|
126
|
|
|
*/ |
|
127
|
|
|
public function isClosure(): bool; |
|
128
|
|
|
} |
|
129
|
|
|
|