Skip to content
Permalink
Browse files

SecurityExtension: added getConfigSchema()

  • Loading branch information...
dg committed Mar 11, 2019
1 parent daa6083 commit acb40153d18f7177bef5f6ff46058e8b25739698
Showing with 21 additions and 9 deletions.
  1. +3 −0 composer.json
  2. +18 −9 src/Bridges/SecurityDI/SecurityExtension.php
@@ -24,6 +24,9 @@
"nette/tester": "^2.0",
"tracy/tracy": "^2.4"
},
"conflict": {
"nette/di": "<3.0"
},
"autoload": {
"classmap": ["src/"]
},
@@ -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'))

0 comments on commit acb4015

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.