Skip to content

Commit 5d3261c

Browse files
committed
注入所有oauth*模块 以适应多个系统的用户验证
1 parent 5ae10b4 commit 5d3261c

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

Bootstrap.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,31 @@ class Bootstrap implements \yii\base\BootstrapInterface
3737
*/
3838
public function bootstrap($app)
3939
{
40-
/** @var $module Module */
41-
if ($app->hasModule('oauth2') && ($module = $app->getModule('oauth2')) instanceof Module) {
42-
$this->_modelMap = array_merge($this->_modelMap, $module->modelMap);
43-
foreach ($this->_modelMap as $name => $definition) {
44-
\Yii::$container->set("filsh\\yii2\\oauth2server\\models\\" . $name, $definition);
45-
$module->modelMap[$name] = is_array($definition) ? $definition['class'] : $definition;
40+
$module_list = array_keys($app->getModules());
41+
$module_oauth = [];
42+
foreach ($module_list as $item) {
43+
if (strpos($item,'oauth')===0) {
44+
$module_oauth[] = $item;
4645
}
46+
}
47+
foreach ($module_oauth as $oauth_name) {
48+
/** @var $module Module */
49+
if ($app->hasModule($oauth_name) && ($module = $app->getModule($oauth_name)) instanceof Module) {
50+
$this->_modelMap = array_merge($this->_modelMap, $module->modelMap);
51+
foreach ($this->_modelMap as $name => $definition) {
52+
\Yii::$container->set("filsh\\yii2\\oauth2server\\models\\" . $name, $definition);
53+
$module->modelMap[$name] = is_array($definition) ? $definition['class'] : $definition;
54+
}
4755

48-
$this->_storageMap = array_merge($this->_storageMap, $module->storageMap);
49-
foreach ($this->_storageMap as $name => $definition) {
50-
\Yii::$container->set($name, $definition);
51-
$module->storageMap[$name] = is_array($definition) ? $definition['class'] : $definition;
52-
}
56+
$this->_storageMap = array_merge($this->_storageMap, $module->storageMap);
57+
foreach ($this->_storageMap as $name => $definition) {
58+
\Yii::$container->set($name, $definition);
59+
$module->storageMap[$name] = is_array($definition) ? $definition['class'] : $definition;
60+
}
5361

54-
if ($app instanceof \yii\console\Application) {
55-
$module->controllerNamespace = 'filsh\yii2\oauth2server\commands';
62+
if ($app instanceof \yii\console\Application) {
63+
$module->controllerNamespace = 'filsh\yii2\oauth2server\commands';
64+
}
5665
}
5766
}
5867
}

0 commit comments

Comments
 (0)