1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SaasReady\Auth; |
4
|
|
|
|
5
|
|
|
use Closure; |
6
|
|
|
|
7
|
|
|
final class ReadyAuthorization |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var array<string, Closure> |
11
|
|
|
*/ |
12
|
|
|
private static array $customAuthorizations = [ |
13
|
|
|
'events.index' => null, |
14
|
|
|
'events.show' => null, |
15
|
|
|
|
16
|
|
|
'countries.index' => null, |
17
|
|
|
'countries.show' => null, |
18
|
|
|
'countries.store' => null, |
19
|
|
|
'countries.update' => null, |
20
|
|
|
'countries.destroy' => null, |
21
|
|
|
|
22
|
|
|
'currencies.index' => null, |
23
|
|
|
'currencies.show' => null, |
24
|
|
|
'currencies.store' => null, |
25
|
|
|
'currencies.update' => null, |
26
|
|
|
'currencies.destroy' => null, |
27
|
|
|
|
28
|
|
|
'languages.index' => null, |
29
|
|
|
'languages.show' => null, |
30
|
|
|
'languages.store' => null, |
31
|
|
|
'languages.update' => null, |
32
|
|
|
'languages.destroy' => null, |
33
|
|
|
|
34
|
|
|
'release-notes.index' => null, |
35
|
|
|
'release-notes.show' => null, |
36
|
|
|
'release-notes.store' => null, |
37
|
|
|
'release-notes.update' => null, |
38
|
|
|
'release-notes.destroy' => null, |
39
|
|
|
|
40
|
|
|
'dynamic-settings.index' => null, |
41
|
|
|
'dynamic-settings.show' => null, |
42
|
|
|
'dynamic-settings.store' => null, |
43
|
|
|
'dynamic-settings.update' => null, |
44
|
|
|
'dynamic-settings.destroy' => null, |
45
|
|
|
|
46
|
|
|
'translations.index' => null, |
47
|
|
|
'translations.show' => null, |
48
|
|
|
'translations.store' => null, |
49
|
|
|
'translations.update' => null, |
50
|
|
|
'translations.destroy' => null, |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set Custom Authorization check |
55
|
|
|
* |
56
|
|
|
* @param string $endpointName |
57
|
|
|
* @param callable $customAuthorization |
58
|
|
|
* - 1st param will be the FormRequest |
59
|
|
|
* - You must be a boolean |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public static function setCustomAuthorization( |
64
|
|
|
string $endpointName, |
65
|
|
|
callable $customAuthorization |
66
|
|
|
): void { |
67
|
|
|
ReadyAuthorization::$customAuthorizations[$endpointName] = $customAuthorization; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public static function getAuthorization(string $endpointName): Closure |
71
|
|
|
{ |
72
|
|
|
return (ReadyAuthorization::$customAuthorizations[$endpointName] ?? fn () => true) |
73
|
|
|
?: fn () => true; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|