/
Bootstrap.php
54 lines (48 loc) · 2.06 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
<?php
namespace jarrus90\Blog;
use Yii;
use yii\i18n\PhpMessageSource;
use yii\base\BootstrapInterface;
use yii\console\Application as ConsoleApplication;
/**
* Bootstrap class registers module and user application component. It also creates some url rules which will be applied
* when UrlManager.enablePrettyUrl is enabled.
*/
class Bootstrap implements BootstrapInterface {
/** @inheritdoc */
public function bootstrap($app) {
/** @var Module $module */
/** @var \yii\db\ActiveRecord $modelName */
if ($app->hasModule('blog') && ($module = $app->getModule('blog')) instanceof Module) {
Yii::$container->setSingleton(BlogFinder::className(), [
'tagQuery' => \jarrus90\Blog\Models\Tag::find(),
'postQuery' => \jarrus90\Blog\Models\Post::find(),
'commentQuery' => \jarrus90\Blog\Models\Comment::find(),
]);
if (!$app instanceof ConsoleApplication) {
$configUrlRule = [
'prefix' => $module->urlPrefix,
'rules' => $module->urlRules,
];
if ($module->urlPrefix != 'blog') {
$configUrlRule['routePrefix'] = 'blog';
}
$configUrlRule['class'] = 'yii\web\GroupUrlRule';
$rule = Yii::createObject($configUrlRule);
$app->urlManager->addRules([$rule], false);
} else {
if(empty($app->controllerMap['migrate'])) {
$app->controllerMap['migrate']['class'] = 'yii\console\controllers\MigrateController';
}
$app->controllerMap['migrate']['migrationNamespaces'][] = 'jarrus90\Blog\migrations';
}
if (!isset($app->get('i18n')->translations['blog*'])) {
$app->get('i18n')->translations['blog*'] = [
'class' => PhpMessageSource::className(),
'basePath' => __DIR__ . '/messages',
'sourceLanguage' => 'en-US'
];
}
}
}
}