Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function bootstrap($app)
// register translations
if (!isset($app->get('i18n')->translations['rbac*'])) {
$app->get('i18n')->translations['rbac*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => __DIR__ . '/messages',
];
}
Expand All @@ -42,20 +42,21 @@ public function bootstrap($app)
$authManager = $app->get('authManager', false);

if (!$authManager) {
$app->set('authManager', [
'class' => DbManager::className(),
]);
$attributes = get_object_vars($app->get('authManager'));
$app->set('authManager', DbManager::className());
foreach ($attributes as $key => $value)
$app->authManager->$key = $value;
} else if (!($authManager instanceof ManagerInterface)) {
throw new InvalidConfigException('You have wrong authManager configuration');
}

// if dektrium/user extension is installed, copy admin list from there
if ($this->checkUserModuleInstalled($app) && $app instanceof WebApplication) {
$app->getModule('rbac')->admins = $app->getModule('user')->admins;
}
}
}
}

/**
* Verifies that dektrium/yii2-rbac is installed and configured.
* @param Application $app
Expand All @@ -69,7 +70,7 @@ protected function checkRbacModuleInstalled(Application $app)
return $app->hasModule('rbac') && $app->getModule('rbac') instanceof RbacConsoleModule;
}
}

/**
* Verifies that dektrium/yii2-user is installed and configured.
* @param Application $app
Expand All @@ -79,7 +80,7 @@ protected function checkUserModuleInstalled(Application $app)
{
return $app->hasModule('user') && $app->getModule('user') instanceof UserModule;
}

/**
* Verifies that authManager component is configured.
* @param Application $app
Expand Down
13 changes: 9 additions & 4 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ $ composer require dektrium/yii2-rbac:1.0.0-alpha@dev
Add rbac module to web application config file as follows:

```php
'components' => [
'authManager' => [
'class' => 'dektrium\rbac\components\DbManager',
'cache' => 'yii\caching\FileCache', // optional
],
...
'modules' => [
...
'rbac' => 'dektrium\rbac\RbacWebModule',
...
'modules' => [
...
'rbac' => 'dektrium\rbac\RbacWebModule',
...
],
...
```
Expand Down