-
Notifications
You must be signed in to change notification settings - Fork 9
/
ModuleInit.php
51 lines (47 loc) · 1.33 KB
/
ModuleInit.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
<?php
/**
* @copyright Copyright © Kartik Visweswaran, communityii, 2014 - 2015
* @package communityii/yii2-user
* @version 1.0.0
* @see https://github.com/communityii/yii2-user
*/
namespace comyii\user;
use Yii;
use yii\web\Application;
use yii\console\Application as ConsoleApplication;
use yii\base\BootstrapInterface;
use yii\web\GroupUrlRule;
/**
* Module initialization bootstrap class for yii2-user module. This class assigns and enables module specific URL rules.
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.0
*/
class ModuleInit implements BootstrapInterface
{
/**
* @inheritdoc
*/
public function bootstrap($app)
{
/**
* @var Module $m
*/
$m = $app->getModule('user');
if (!$m instanceof Module) {
return;
}
if ($app instanceof ConsoleApplication && $app->hasModule('user')) {
$m->controllerNamespace = 'comyii\user\commands';
return;
}
if (!$app instanceof Application || !$app->hasModule('user')) {
return;
}
$config = ['prefix' => $m->urlPrefix, 'rules' => $m->urlRules];
if ($m->urlPrefix != 'user') {
$config['routePrefix'] = 'user';
}
$app->urlManager->addRules([new GroupUrlRule($config)], false);
}
}