-
Notifications
You must be signed in to change notification settings - Fork 26
/
Bootstrap.php
82 lines (72 loc) · 2.78 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
<?php
/**
* @author akiraz@bk.ru
* @link https://github.com/akiraz2/yii2-ticket-support
* @copyright 2018 akiraz2
* @license MIT
*/
namespace akiraz2\support;
use akiraz2\support\traits\ModuleTrait;
use yii\base\BootstrapInterface;
use yii\console\Application as ConsoleApplication;
use yii\i18n\PhpMessageSource;
/**
* support module bootstrap class.
*/
class Bootstrap implements BootstrapInterface
{
use ModuleTrait;
/**
* @inheritdoc
*/
public function bootstrap($app)
{
if ($app->hasModule('support') && ($module = $app->getModule('support')) instanceof Module) {
\Yii::$container->set('akiraz2\support\Mailer', $module->mailer);
$redactorModule = $this->getModule()->redactorModule;
if ($this->getModule()->getIsBackend() && !$app->hasModule($redactorModule)) {
$app->setModule($redactorModule, [
'class' => 'yii\redactor\RedactorModule',
/*'imageUploadRoute' => ['/blog/upload/image'],
'uploadDir' => $this->getModule()->imgFilePath . '/upload/',
'uploadUrl' => $this->getModule()->getImgFullPathUrl() . '/upload',
'imageAllowExtensions' => ['jpg', 'png', 'gif', 'svg']*/
]);
}
if ($app instanceof ConsoleApplication) {
$this->getModule()->controllerNamespace = 'akiraz2\support\commands';
}
$app->urlManager->addRules(
[
'<_m:support>/new-ticket' => '<_m>/ticket/create',
'<_m:support>/<id:\w+>' => '<_m>/ticket/view',
'<_m:support>' => '<_m>/ticket/index',
]
);
$app->get($this->getModule()->urlManagerFrontend)->addRules(
[
'<_m:support>/new-ticket' => '<_m>/ticket/create',
'<_m:support>/<id:\w+>' => '<_m>/ticket/view',
'<_m:support>' => '<_m>/ticket/index',
]
);
if (!$app->has($this->getModule()->queueComponent)) {
$app->set($this->getModule()->queueComponent, [
'class' => \yii\queue\sync\Queue::class,
'handle' => true, // whether tasks should be executed immediately
]);
}
}
// Add module I18N category.
if (!isset($app->i18n->translations['akiraz2/support'])) {
$app->i18n->translations['akiraz2/support'] = [
'class' => PhpMessageSource::class,
'basePath' => __DIR__ . '/messages',
'forceTranslation' => true,
'fileMap' => [
'akiraz2/support' => 'support.php',
]
];
}
}
}