|
10 | 10 | namespace Nette\Bridges\SecurityDI; |
11 | 11 |
|
12 | 12 | use Nette; |
| 13 | +use Nette\DI\Config\Expect; |
13 | 14 |
|
14 | 15 |
|
15 | 16 | /** |
16 | 17 | * Security extension for Nette DI. |
17 | 18 | */ |
18 | 19 | class SecurityExtension extends Nette\DI\CompilerExtension |
19 | 20 | { |
20 | | - public $defaults = [ |
21 | | - 'debugger' => null, |
22 | | - 'users' => [], // of [user => password] or [user => ['password' => password, 'roles' => [role]]] |
23 | | - 'roles' => [], // of [role => parent(s)] |
24 | | - 'resources' => [], // of [resource => parent] |
25 | | - ]; |
26 | | - |
27 | 21 | /** @var bool */ |
28 | 22 | private $debugMode; |
29 | 23 |
|
30 | 24 |
|
31 | 25 | public function __construct(bool $debugMode = false) |
32 | 26 | { |
33 | | - $this->defaults['debugger'] = interface_exists(\Tracy\IBarPanel::class); |
34 | 27 | $this->debugMode = $debugMode; |
35 | 28 | } |
36 | 29 |
|
37 | 30 |
|
| 31 | + public function getConfigSchema(): Nette\DI\Config\Schema |
| 32 | + { |
| 33 | + return Expect::struct([ |
| 34 | + 'debugger' => Expect::bool(interface_exists(\Tracy\IBarPanel::class)), |
| 35 | + 'users' => Expect::arrayOf( // of [user => password] or [user => ['password' => password, 'roles' => [role]]] |
| 36 | + Expect::enum( |
| 37 | + Expect::string(), |
| 38 | + Expect::struct(['password' => Expect::string(), 'roles' => Expect::enum(Expect::string(), Expect::listOf('string'))]) |
| 39 | + ) |
| 40 | + ), |
| 41 | + 'roles' => Expect::arrayOf('string'), // [role => parent(s)] |
| 42 | + 'resources' => Expect::arrayOf('string'), // [resource => parent] |
| 43 | + ]); |
| 44 | + } |
| 45 | + |
| 46 | + |
38 | 47 | public function loadConfiguration() |
39 | 48 | { |
40 | | - $config = $this->validateConfig($this->defaults); |
| 49 | + $config = $this->config; |
41 | 50 | $builder = $this->getContainerBuilder(); |
42 | 51 |
|
43 | 52 | $builder->addDefinition($this->prefix('passwords')) |
|
0 commit comments