forked from artkost/yii2-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActiveRecord.php
58 lines (49 loc) · 1.29 KB
/
ActiveRecord.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
<?php
namespace artkost\qa;
use artkost\qa\Module;
use Yii;
use yii\base\InvalidConfigException;
/**
* ActiveRecord
* @package artkost\qa
*/
class ActiveRecord extends \yii\db\ActiveRecord
{
/**
* @var Module
*/
protected static $module;
/**
* Get instance of module Active Record depends on
* @return Module
* @throws InvalidConfigException
*/
public function getModule()
{
if (self::$module == null) {
$modules = Yii::$app->getModules(true);
foreach ($modules as $id => $module) {
if ($module instanceof Module) {
self::$module = $module;
} elseif(is_array($module) && $module['class'] == Module::className()) {
self::$module = Yii::$app->getModule($id);
}
}
if (self::$module == null) {
throw new InvalidConfigException('Module not defined for this model');
}
}
return self::$module;
}
/**
* Alias of [[Module::t()]]
* @param $message
* @param array $params
* @param null $language
* @return string
*/
public function t($message, $params = [], $language = null)
{
return Module::t($message, $params, $language);
}
}