forked from humhub/humhub
/
Application.php
97 lines (82 loc) · 2.24 KB
/
Application.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
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\components;
use humhub\interfaces\ApplicationInterface;
use Yii;
use Exception;
/**
* Description of Application
*
* @inheritdoc
*/
class Application extends \yii\web\Application implements ApplicationInterface
{
use ApplicationTrait;
/**
* @inheritdoc
*/
public $controllerNamespace = 'humhub\\controllers';
/**
* @inheritdoc
*/
public function init()
{
if (version_compare(phpversion(), $this->minSupportedPhpVersion, '<')) {
throw new Exception(sprintf(
'Installed PHP Version is too old! Required minimum version is PHP %s (Installed: %s)',
$this->minSupportedPhpVersion,
phpversion()
));
}
parent::init();
$this->trigger(self::EVENT_ON_INIT);
}
/**
* @inheritdoc
*/
public function bootstrap()
{
$request = $this->getRequest();
if (Yii::getAlias('@web-static', false) === false) {
Yii::setAlias('@web-static', $request->getBaseUrl() . '/static');
}
if (Yii::getAlias('@webroot-static', false) === false) {
Yii::setAlias('@webroot-static', '@webroot/static');
}
parent::bootstrap();
}
/**
* @inheritdoc
*/
public function beforeAction($action)
{
/**
* Check if it's already installed - if not force controller module
*/
if (!$this->params['installed'] && $this->controller->module != null && $this->controller->module->id != 'installer') {
$this->controller->redirect(['/installer/index']);
return false;
}
/**
* More random widget autoId prefix
* Ensures to be unique also on ajax partials
*/
\yii\base\Widget::$autoIdPrefix = 'h' . mt_rand(1, 999999) . 'w';
return parent::beforeAction($action);
}
/**
* Switch current language
*
* @param string $value
*/
public function setLanguage($value)
{
if (!empty($value)) {
$this->language = $value;
}
}
}