-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebApplication.php
201 lines (170 loc) · 5.59 KB
/
WebApplication.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
namespace panix\engine;
use panix\engine\controllers\AdminController;
use Yii;
use yii\helpers\ArrayHelper;
use yii\web\Application;
use panix\mod\admin\models\Modules;
/**
* Class WebApplication
* @package panix\engine
* @property array $counters
* @property-read \panix\engine\components\Settings $settings The user component. This property is read-only.
* @property-read ManagerLanguage $languageManager The user component. This property is read-only.
* @property \panix\engine\db\Connection $db The database connection. This property is read-only.
*/
class WebApplication extends Application
{
const version = '2.0.0-alpha';
public $counters = [];
private $_findMenu = [];
public function run()
{
$langManager = $this->languageManager;
$this->language = (isset($langManager->default->code)) ? $langManager->default->code : $this->language;
$result = [];
$modules = $this->getModules();
foreach ($modules as $mid => $module) {
if (method_exists($module, 'getAdminMenu')) {
$result = ArrayHelper::merge($result, $module->getAdminMenu());
}
}
$resultFinish = [];
foreach ($result as $mid => $res) {
$resultFinish[$mid] = $res;
if (isset($res['items'])) {
foreach ($res['items'] as $k => $item) {
if (isset($item['visible'])) {
if (!$item['visible']) {
unset($resultFinish[$mid]['items'][$k]);
}
}
}
}
}
$this->_findMenu = $resultFinish;
return parent::run();
}
public function getModulesInfo()
{
$modules = $this->getModules();
if (YII_DEBUG)
unset($modules['debug'], $modules['gii'], $modules['admin']);
$result = [];
foreach ($modules as $name => $className) {
//$info = $this->getModule($name)->info;
if (isset($this->getModule($name)->info))
$result[$name] = $this->getModule($name)->info;
}
return $result;
}
public function getFindMenu()
{
return $this->_findMenu;
}
public static function powered()
{
return Yii::t('app/default', 'COPYRIGHT', [
'year' => date('Y'),
'by' => Html::a('PIXELION CMS', '//pixelion.com.ua')
]);
}
public function getVersion()
{
return self::version;
}
public function init()
{
//$this->setEngineModules();
foreach ($this->getModules() as $id => $module) {
if (isset($module['class'])) {
$reflectionClass = new \ReflectionClass($module['class']);
$this->setAliases([
'@' . $id => realpath(dirname($reflectionClass->getFileName())),
]);
$this->registerTranslations($id);
}
}
/*$modulesList = array_filter(glob(Yii::getAlias('@app/modules/*')), 'is_dir');
foreach ($modulesList as $module) {
$id = basename($module);
$this->setAliases([
'@' . $id => realpath(Yii::getAlias("@app/modules/{$id}")),
]);
$this->registerTranslations($id);
}*/
parent::init();
}
private function setEngineModules()
{
$mods = (new Modules)->getEnabled();
if ($mods) {
foreach ($mods as $module) {
$this->setModule($module->name, [
'class' => $module->className,
]);
}
}
}
/**
* @param string $id
* @param string $path
* @return array
*/
public function getTranslationsFileMap($id, $path)
{
$lang = $this->language;
$result = [];
$basePath = realpath(Yii::getAlias("{$path}/{$lang}"));
if (is_dir($basePath)) {
$fileList = \yii\helpers\FileHelper::findFiles($basePath, [
'only' => ['*.php'],
'recursive' => false
]);
foreach ($fileList as $path) {
$result[$id . '/' . basename($path, '.php')] = basename($path);
// $result[basename($path, '.php')] = basename($path);
}
}
return $result;
}
public function registerTranslations($id)
{
$path = '@' . $id . '/messages';
$translations[$id . '/*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => $path,
'fileMap' => $this->getTranslationsFileMap($id, $path)
];
$this->i18n->translations = ArrayHelper::merge($translations, $this->i18n->translations);
}
/**
* Returns the settings component.
* @return \panix\engine\components\Settings|object the settings component.
* @throws \yii\base\InvalidConfigException
*/
public function getSettings()
{
return $this->get('settings');
}
/**
* Returns the languageManager component.
* @return ManagerLanguage|object the languageManager component.
* @throws \yii\base\InvalidConfigException
*/
public function getLanguageManager()
{
return $this->get('languageManager');
}
/**
* {@inheritdoc}
*/
public function coreComponents()
{
return array_merge(parent::coreComponents(), [
'settings' => ['class' => 'panix\engine\components\Settings'],
'languageManager' => ['class' => 'panix\engine\ManagerLanguage'],
]);
}
}