/
Bootstrap.php
105 lines (87 loc) · 3.05 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace sap55\order;
use yii\base\Application;
use yii\base\BootstrapInterface;
use yii\base\InvalidConfigException;
use yii\db\ActiveRecord;
use yii\i18n\PhpMessageSource;
use yii\web\IdentityInterface;
use yii\web\GroupUrlRule;
use yii\console\Application as ConsoleApplication;
class Bootstrap implements BootstrapInterface
{
public function bootstrap($app)
{
if ($app->hasModule('order') && ($module = $app->getModule('order')) instanceof Module) {
if ($app instanceof ConsoleApplication) {
} else {
$configUrlRule = [
'prefix' => $module->urlPrefix,
'rules' => $module->urlRules,
];
if ($module->urlPrefix != 'order') {
$configUrlRule['routePrefix'] = 'order';
}
$app->urlManager->addRules([new GroupUrlRule($configUrlRule)], false);
}
// register auth manager
if ($app->authManager === null) {
throw new InvalidConfigException('You should configure authManager component');
}
if (!$this->checkSettingModuleInstalled($app)) {
throw new InvalidConfigException('You should configure pheme\settings module');
}
if (!$this->checkGridViewModuleInstalled($app)) {
throw new InvalidConfigException('You should configure kartik\grid module');
}
if (!$this->checkAttachmentsModuleInstalled($app)) {
throw new InvalidConfigException('You should configure nemmo\attachments module');
}
// if (!$this->checkUserClassConfigured($app)) {
// throw new InvalidConfigException('You should configure your user class instance of ActiveRecord');
// }
}
if (!isset($app->get('i18n')->translations['order*'])) {
$app->get('i18n')->translations['order*'] = [
'class' => PhpMessageSource::className(),
'basePath' => __DIR__ . '/messages',
];
}
}
/**
* Verifies that user class is instance of ActiveRecord.
* @param Application $app
* @return bool
*/
protected function checkUserClassConfigured(Application $app)
{
return $app->user->identityClass instanceof ActiveRecord;
}
/**
* Verifies that kartik/grid module is installed and configured.
* @param Application $app
* @return bool
*/
protected function checkGridViewModuleInstalled(Application $app)
{
return $app->hasModule('gridview') && $app->getModule('gridview') instanceof \kartik\base\Module;
}
/**
* Verifies that pheme/settings module is installed and configured.
* @param Application $app
* @return bool
*/
protected function checkSettingModuleInstalled(Application $app)
{
return $app->hasModule('settings');
}
/**
* Verifies that nemmo\attachments module is installed and configured.
* @param Application $app
* @return bool
*/
protected function checkAttachmentsModuleInstalled(Application $app)
{
return $app->hasModule('attachments') && $app->getModule('attachments') instanceof \nemmo\attachments\Module;
}
}