Skip to content

Commit acb4015

Browse files
committed
SecurityExtension: added getConfigSchema()
1 parent daa6083 commit acb4015

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"nette/tester": "^2.0",
2525
"tracy/tracy": "^2.4"
2626
},
27+
"conflict": {
28+
"nette/di": "<3.0"
29+
},
2730
"autoload": {
2831
"classmap": ["src/"]
2932
},

src/Bridges/SecurityDI/SecurityExtension.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,43 @@
1010
namespace Nette\Bridges\SecurityDI;
1111

1212
use Nette;
13+
use Nette\DI\Config\Expect;
1314

1415

1516
/**
1617
* Security extension for Nette DI.
1718
*/
1819
class SecurityExtension extends Nette\DI\CompilerExtension
1920
{
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-
2721
/** @var bool */
2822
private $debugMode;
2923

3024

3125
public function __construct(bool $debugMode = false)
3226
{
33-
$this->defaults['debugger'] = interface_exists(\Tracy\IBarPanel::class);
3427
$this->debugMode = $debugMode;
3528
}
3629

3730

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+
3847
public function loadConfiguration()
3948
{
40-
$config = $this->validateConfig($this->defaults);
49+
$config = $this->config;
4150
$builder = $this->getContainerBuilder();
4251

4352
$builder->addDefinition($this->prefix('passwords'))

0 commit comments

Comments
 (0)