-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
executable file
·160 lines (137 loc) · 3.67 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
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
<?php
/**
* Site: http://tokapps.ir
* AuthorName: gholamreza beheshtian
* AuthorNumber:09353466620
* AuthorCompany: tokapps
*
*
*/
namespace system\modules\transactions;
/**
* transactions module definition class
*/
use kartik\mpdf\Pdf;
use Yii;
use yii\helpers\ArrayHelper;
class Module extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace;
public $name;
public $nameSpace;
public $config = [];
/**
* {@inheritdoc}
*/
public function init()
{
// < set Class Parameters >
{
$this->config = include realpath( __DIR__ . '/config.php' );
$this->nameSpace = 'system\modules\\' . $this->config['name'];
$this->controllerNamespace = 'system\modules\\' . $this->config['name'] . '\controllers';
$this->name = $this->config['name'];
}
// </ set Class Parameters >
//$this->initI18N();
$this->initModules();
// $this->initMigrations();
$this->registerTranslations();
// $this->initComponents();
}
/**
* TranslationTrait manages methods for all translations used in Krajee extensions
*
* @property array $i18n
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.8.8
* Yii i18n messages configuration for generating translations
* source : https://github.com/kartik-v/yii2-krajee-base/blob/master/TranslationTrait.php
* Edited by : Yohanes Candrajaya <[email protected]>
*
*
* @return void
*/
public function initI18N() {
$reflector = new \ReflectionClass( get_class( $this ) );
$dir = dirname( $reflector->getFileName() );
if ( ! empty( $this->config['message'] ) ) {
foreach ( $this->config['message'] as $message ) {
Yii::setAlias( "@" . $message , $dir );
$config = [
'class' => 'yii\i18n\PhpMessageSource' ,
'basePath' => "@" . $message . "/messages" ,
'forceTranslation' => true
];
$globalConfig = ArrayHelper::getValue( Yii::$app->i18n->translations , $message . "*" , [] );
if ( ! empty( $globalConfig ) ) {
$config = array_merge(
$config ,
is_array( $globalConfig ) ? $globalConfig : (array) $globalConfig
);
}
Yii::$app->i18n->translations[ $message . "*" ] = $config;
}
}
}
protected function registerTranslations() {
Yii::$app->i18n->translations[ $this->name ] = [
'class' => 'yii\i18n\PhpMessageSource' ,
'sourceLanguage' => Yii::$app->language ,
'basePath' => '@system/modules/' . $this->name . '/messages' ,
'fileMap' => [
$this->name => 'module.php' ,
] ,
];
}
public function initComponents() {
$Option =
[
'class' => 'system\modules\setting\components\Options' ,
];
//Yii::$app->components['pdf']= $pdf;
Yii::$app->setComponents( [ $Option ] );
}
public function initModules() {
if ( ! empty( $this->config['modules'] ) ) {
foreach ( $this->config['modules'] as $key => $val ) {
$this->modules[ $key ] = $val;
}
}
}
public function initMigrations() {
$classes = getFileList( realpath( __DIR__ . '/migrations' ) );
if ( ! empty( $classes ) ) {
foreach ( $classes as $key => $val ) {
if ( $val['type'] == 'text/x-php' ) {
$val['name'] = str_replace( '.php' , '' , $val['name'] );
$cname = $this->nameSpace . '\migrations\\' . $val['name'];
$class = new $cname();
try {
$generate = $class->safeUp();
} catch ( \Exception $e ) {
}
}
}
}
}
/**
* Translates a message. This is just a wrapper of Yii::t
*
* @see Yii::t
*
* @param $category
* @param $message
* @param array $params
* @param null $language
*
* @return string
*/
public static function t( $category , $message , $params = [] , $language = null ) {
return Yii::t( $category , $message , $params , $language );
}
}