Skip to content

Commit

Permalink
SecurityExtension: added getConfigSchema()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 15, 2019
1 parent daa6083 commit acb4015
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"nette/tester": "^2.0",
"tracy/tracy": "^2.4"
},
"conflict": {
"nette/di": "<3.0"
},
"autoload": {
"classmap": ["src/"]
},
Expand Down
27 changes: 18 additions & 9 deletions src/Bridges/SecurityDI/SecurityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,43 @@
namespace Nette\Bridges\SecurityDI;

use Nette;
use Nette\DI\Config\Expect;


/**
* Security extension for Nette DI.
*/
class SecurityExtension extends Nette\DI\CompilerExtension
{
public $defaults = [
'debugger' => null,
'users' => [], // of [user => password] or [user => ['password' => password, 'roles' => [role]]]
'roles' => [], // of [role => parent(s)]
'resources' => [], // of [resource => parent]
];

/** @var bool */
private $debugMode;


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


public function getConfigSchema(): Nette\DI\Config\Schema
{
return Expect::struct([
'debugger' => Expect::bool(interface_exists(\Tracy\IBarPanel::class)),
'users' => Expect::arrayOf( // of [user => password] or [user => ['password' => password, 'roles' => [role]]]
Expect::enum(
Expect::string(),
Expect::struct(['password' => Expect::string(), 'roles' => Expect::enum(Expect::string(), Expect::listOf('string'))])
)
),
'roles' => Expect::arrayOf('string'), // [role => parent(s)]
'resources' => Expect::arrayOf('string'), // [resource => parent]
]);
}


public function loadConfiguration()
{
$config = $this->validateConfig($this->defaults);
$config = $this->config;
$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('passwords'))
Expand Down

0 comments on commit acb4015

Please sign in to comment.