1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* @copyright Copyright (C) 2019 Sergio coderius <coderius> |
4
|
|
|
* @license This program is free software: the MIT License (MIT) |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace coderius\hitCounter; |
8
|
|
|
|
9
|
|
|
use Yii; |
10
|
|
|
use yii\web\GroupUrlRule; |
11
|
|
|
use \yii\base\Application; |
12
|
|
|
use yii\base\Model; |
13
|
|
|
|
14
|
|
|
class Module extends \yii\base\Module |
15
|
|
|
{ |
16
|
|
|
/** @var string module name */ |
17
|
|
|
public static $moduleName = 'hitCounter'; |
18
|
|
|
|
19
|
|
|
/** @var string|null */ |
20
|
|
|
public $userIdentityClass = null; |
21
|
|
|
|
22
|
|
|
public $controllerNamespace = 'coderius\hitCounter\controllers'; |
23
|
|
|
|
24
|
|
|
public function init() |
25
|
|
|
{ |
26
|
|
|
parent::init(); |
27
|
|
|
|
28
|
|
|
\Yii::configure($this, require __DIR__ . '/config/main.php'); |
29
|
|
|
|
30
|
|
|
//иначе ломает консольные комманды |
31
|
|
|
if (Yii::$app instanceof yii\web\Application) { |
32
|
|
|
if ($this->userIdentityClass === null) { |
33
|
|
|
$this->userIdentityClass = \Yii::$app->getUser()->identityClass; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// var_dump(Module::t('messages', 'No comments yet.'));die; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Adds UrlManager rules. |
42
|
|
|
* |
43
|
|
|
* @param Application $app the application currently running |
44
|
|
|
*/ |
45
|
|
|
public function addUrlManagerRules(Application $app) |
46
|
|
|
{ |
47
|
|
|
$app->urlManager->addRules([new GroupUrlRule([ |
48
|
|
|
'prefix' => $this->id, |
49
|
|
|
'rules' => require __DIR__ . '/config/_routes.php', |
50
|
|
|
])], true); |
51
|
|
|
|
52
|
|
|
// var_dump(\Yii::$app->urlManager); |
53
|
|
|
// var_dump($this->id.'s'); |
54
|
|
|
// die; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return static |
59
|
|
|
*/ |
60
|
|
|
public static function selfInstance() |
61
|
|
|
{ |
62
|
|
|
return \Yii::$app->getModule(static::$moduleName); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get default model classes. |
67
|
|
|
*/ |
68
|
|
|
public function getDefaultModels() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
'HitCounter' => \coderius\hitCounter\models\HitCounterModel::className(), |
|
|
|
|
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function model(Model $name) |
76
|
|
|
{ |
77
|
|
|
$models = $this->getDefaultModels(); |
78
|
|
|
if (array_key_exists($name, $models)) { |
79
|
|
|
return $models[$name]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.