1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Spiral Framework. |
4
|
|
|
* |
5
|
|
|
* @license MIT |
6
|
|
|
* @author Anton Titov (Wolfy-J) |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Spiral\Vault\Configs; |
10
|
|
|
|
11
|
|
|
use Spiral\Core\InjectableConfig; |
12
|
|
|
use Spiral\Vault\VaultRoute; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Configuration for Vault administration panel. |
16
|
|
|
*/ |
17
|
|
|
class VaultConfig extends InjectableConfig |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Configuration section. |
21
|
|
|
*/ |
22
|
|
|
const CONFIG = 'modules/vault'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $config = [ |
28
|
|
|
'guard' => [ |
29
|
|
|
'namespace' => 'vault' |
30
|
|
|
], |
31
|
|
|
|
32
|
|
|
//Allowed vault controllers |
33
|
|
|
'controllers' => [], |
34
|
|
|
|
35
|
|
|
//Example: vault/users/addresses/1/remove/123 |
36
|
|
|
'route' => [ |
37
|
|
|
'name' => 'vault', |
38
|
|
|
'pattern' => 'vault[/<controller>[/<action>[/<id>[/<operation>[/<childID>]]]]]', |
39
|
|
|
'defaults' => [], |
40
|
|
|
'middlewares' => [], |
41
|
|
|
'matchHost' => false, |
42
|
|
|
], |
43
|
|
|
|
44
|
|
|
//Navigation widget configuration |
45
|
|
|
'navigation' => [], |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Guard namespace (prefix for all permissions) associated with given Vault instance. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function guardNamespace(): string |
54
|
|
|
{ |
55
|
|
|
return $this->config['guard']['namespace']; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $controller |
60
|
|
|
* |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
public function hasController(string $controller): bool |
64
|
|
|
{ |
65
|
|
|
return isset($this->config['controllers'][$controller]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Controller class. |
70
|
|
|
* |
71
|
|
|
* @param string $controller |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function controllerClass(string $controller): string |
76
|
|
|
{ |
77
|
|
|
return $this->config['controllers'][$controller]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Vault navigation structure including sections, permissions, titles and etc. |
82
|
|
|
* |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
|
public function navigationSections(): array |
86
|
|
|
{ |
87
|
|
|
return $this->config['navigation']; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $name |
92
|
|
|
* |
93
|
|
|
* @return VaultRoute |
94
|
|
|
*/ |
95
|
|
|
public function makeRoute(string $name): VaultRoute |
96
|
|
|
{ |
97
|
|
|
$route = new VaultRoute( |
98
|
|
|
$name, |
99
|
|
|
$this->config['route']['pattern'], |
100
|
|
|
$this->config['route']['defaults'] |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
return $route->withHost( |
104
|
|
|
$this->config['route']['matchHost'] |
105
|
|
|
)->withMiddleware( |
106
|
|
|
$this->config['route']['middlewares'] |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
} |