-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBootstrap.php
60 lines (51 loc) · 1.88 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
<?php
/*
* This file is part of the Macklus Yii2-Payments project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace macklus\payments;
use Yii;
use yii\base\BootstrapInterface;
use yii\i18n\PhpMessageSource;
use macklus\payments\exceptions\OldConfigurationValueException;
/**
* Bootstrap class registers module.
* It also creates required url rules
*
*/
class Bootstrap implements BootstrapInterface
{
/** @inheritdoc */
public function bootstrap($app)
{
$module = $app->getModule('payments');
if ((isset($module->logDir) && $module->logDir != 'deprecated') || (isset($module->logDirPerms) && $module->logDirPerms != 'deprecated')) {
throw new OldConfigurationValueException();
}
if ($app->hasModule('payments') && $module instanceof \yii\base\Module) {
if ($app instanceof ConsoleApplication) {
$module->controllerNamespace = 'macklus\payments\commands';
} else {
$configUrlRule = [
'prefix' => $module->urlPrefix,
'rules' => $module->urlRules,
];
if ($module->urlPrefix != 'payments') {
$configUrlRule['routePrefix'] = 'payments';
}
$configUrlRule['class'] = 'yii\web\GroupUrlRule';
$rule = Yii::createObject($configUrlRule);
$app->urlManager->addRules([$rule], false);
}
if (!isset($app->get('i18n')->translations['payments*'])) {
$app->get('i18n')->translations['payments*'] = [
'class' => PhpMessageSource::className(),
'basePath' => __DIR__ . '/messages',
'sourceLanguage' => 'en-US'
];
}
}
}
}