forked from dektrium/yii2-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.php
75 lines (64 loc) · 2.15 KB
/
Bootstrap.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace dektrium\user;
use yii\base\BootstrapInterface;
use yii\web\GroupUrlRule;
/**
* Bootstrap class registers module and user application component. It also creates some url rules which will be applied
* when UrlManager.enablePrettyUrl is enabled.
*
* @author Dmitry Erofeev <[email protected]>
*/
class Bootstrap implements BootstrapInterface
{
/**
* @inheritdoc
*/
public function bootstrap($app)
{
if ($app->hasModule('user')) {
$identityClass = $app->getModule('user')->manager->userClass;
} else {
$app->setModule('user', [
'class' => 'dektrium\user\Module'
]);
$identityClass = 'dektrium\user\models\User';
}
if ($app instanceof \yii\console\Application) {
$app->getModule('user')->controllerNamespace = 'dektrium\user\commands';
} else {
$app->set('user', [
'class' => 'yii\web\User',
'enableAutoLogin' => true,
'loginUrl' => ['/user/security/login'],
'identityClass' => $identityClass
]);
/** @var $module Module */
$module = $app->getModule('user');
$configUrlRule = [
'prefix' => $module->urlPrefix,
'rules' => $module->urlRules
];
if ($module->urlPrefix != 'user') {
$configUrlRule['routePrefix'] = 'user';
}
$app->get('urlManager')->rules[] = new GroupUrlRule($configUrlRule);
if (!$app->has('authClientCollection')) {
$app->set('authClientCollection', [
'class' => 'yii\authclient\Collection',
]);
}
}
$app->get('i18n')->translations['user*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => __DIR__ . '/messages',
];
}
}