diff --git a/Bootstrap.php b/Bootstrap.php index 809cd6dd..6c5c81ca 100644 --- a/Bootstrap.php +++ b/Bootstrap.php @@ -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', ]; } @@ -42,9 +42,10 @@ 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'); } @@ -52,10 +53,10 @@ public function bootstrap($app) // 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 @@ -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 @@ -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 diff --git a/docs/installation.md b/docs/installation.md index 7c683dff..ac2e5674 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -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', + ... ], ... ```