/
Module.php
executable file
·88 lines (79 loc) · 2.49 KB
/
Module.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
<?php
namespace afzalroq\cms;
use afzalroq\cms\components\Language;
/**
* Class Module
* @package afzalroq\cms
* @property string $path
* @property string $host
* @property string $cache
* @property integer $cacheDuration
* @property string $fallback
* @property string $watermark
* @property integer $watermarkBottom
* @property integer $watermarkRight
* @property string $imageOperation
* @property string $imageBackground
* @property string $imageXPos
* @property string $imageYPos
* @property array|null $textConverter
* @property array $languages
* @property array $menuActions
*/
class Module extends \yii\base\Module
{
public $userClass = '\common\models\User';
public $frontHost;
public $path;
public $host;
public $cache = 'cache';
public $cacheDuration = YII_ENV_DEV ? 1 : 3600;
public $fallback;
public $watermark;
public $watermarkBottom = 15;
public $watermarkRight = 15;
public $imageOperation = 'cropResize';
public $imageBackground = 'transparent';
public $imageXPos = 'center';
public $imageYPos = 'center';
public $textConverter = false;
public $languages;
public $menuActions;
public $optimized = false;
public $pageSize = 10;
private static function dataKeys()
{
return [0, 1, 2, 3, 4];
}
public function init()
{
parent::init();
$this->fixPathParam();
$this->registerAppParams();
$this->validateLanguages();
}
private function registerAppParams()
{
$languageIds = [];
foreach ($this->languages as $prefix => $language) {
//deprecated
\Yii::$app->params['cms']['languageIds'][$prefix] = $language['id'];
\Yii::$app->params['cms']['languages'][$language['id']] = $language['name'];
// preferred params
\Yii::$app->params['l-name'][$language['id']] = $language['name'];
\Yii::$app->params['l-name'][$prefix] = $language['name'];
\Yii::$app->params['l'][$language['id']] = $prefix;
\Yii::$app->params['l'][$prefix] = $language['id'];
}
}
private function validateLanguages()
{
if (count(array_diff(\Yii::$app->params['cms']['languageIds'], self::dataKeys()))) {
throw new \RuntimeException('Language key is invalid. Current support keys range is ' . json_encode(self::dataKeys()));
}
}
private function fixPathParam()
{
$this->path = rtrim($this->path, '/') . '/';
}
}