-
Notifications
You must be signed in to change notification settings - Fork 23
/
Bootstrap.php
64 lines (56 loc) · 2.01 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
<?php
/**
* Project: yii2-blog for internal using
* Author: akiraz2
* Copyright (c) 2018.
*/
namespace akiraz2\blog;
use akiraz2\blog\traits\ModuleTrait;
use yii\base\BootstrapInterface;
use yii\i18n\PhpMessageSource;
/**
* Blogs module bootstrap class.
*/
class Bootstrap implements BootstrapInterface
{
use ModuleTrait;
/**
* @inheritdoc
*/
public function bootstrap($app)
{
// Add module URL rules.
$app->getUrlManager()->addRules(
[
'<_m:blog>/cat/<category_id:\d+>-<slug:[a-zA-Z0-9_-]{1,100}+>' => '<_m>/default/index',
'<_m:blog>/<id:\d+>-<slug:[a-zA-Z0-9_-]{1,100}+>' => '<_m>/default/view',
'<_m:blog>' => '<_m>/default/index',
]
);
// Add module I18N category.
if (!isset($app->i18n->translations['akiraz2/blog'])) {
$app->i18n->translations['akiraz2/blog'] = [
'class' => PhpMessageSource::class,
'basePath' => __DIR__ . '/messages',
//'forceTranslation' => true,
'fileMap' => [
'akiraz2/blog' => 'blog.php',
]
];
}
// Add redactor module if not exist (in my case - only in backend) and if the blog module enabled
if ($this->getModule()) {
$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']
]);
}
}
\Yii::setAlias('@akiraz2', \Yii::getAlias('@vendor') . '/akiraz2');
}
}