Bootstrap.php
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace filsh\yii2\oauth2server;
use yii\web\GroupUrlRule;
class Bootstrap implements \yii\base\BootstrapInterface
{
/**
* @var array Model's map
*/
private $_modelMap = [
'OauthClients' => 'filsh\yii2\oauth2server\models\OauthClients',
'OauthAccessTokens' => 'filsh\yii2\oauth2server\models\OauthAccessTokens',
'OauthAuthorizationCodes' => 'filsh\yii2\oauth2server\models\OauthAuthorizationCodes',
'OauthRefreshTokens' => 'filsh\yii2\oauth2server\models\OauthRefreshTokens',
'OauthScopes' => 'filsh\yii2\oauth2server\models\OauthScopes',
];
/**
* @var array Storage's map
*/
private $_storageMap = [
'access_token' => 'filsh\yii2\oauth2server\storage\Pdo',
'authorization_code' => 'filsh\yii2\oauth2server\storage\Pdo',
'client_credentials' => 'filsh\yii2\oauth2server\storage\Pdo',
'client' => 'filsh\yii2\oauth2server\storage\Pdo',
'refresh_token' => 'filsh\yii2\oauth2server\storage\Pdo',
'user_credentials' => 'filsh\yii2\oauth2server\storage\Pdo',
'public_key' => 'filsh\yii2\oauth2server\storage\Pdo',
'jwt_bearer' => 'filsh\yii2\oauth2server\storage\Pdo',
'scope' => 'filsh\yii2\oauth2server\storage\Pdo',
];
/**
* @inheritdoc
*/
public function bootstrap($app)
{
/** @var $module Module */
if ($app->hasModule('oauth2') && ($module = $app->getModule('oauth2')) instanceof Module) {
$this->_modelMap = array_merge($this->_modelMap, $module->modelMap);
foreach ($this->_modelMap as $name => $definition) {
\Yii::$container->set("filsh\\yii2\\oauth2server\\models\\" . $name, $definition);
$module->modelMap[$name] = is_array($definition) ? $definition['class'] : $definition;
}
$this->_storageMap = array_merge($this->_storageMap, $module->storageMap);
foreach ($this->_storageMap as $name => $definition) {
\Yii::$container->set($name, $definition);
$module->storageMap[$name] = is_array($definition) ? $definition['class'] : $definition;
}
if ($app instanceof \yii\console\Application) {
$module->controllerNamespace = 'filsh\yii2\oauth2server\commands';
}
}
}
}