1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/zhuravljov/yii2-queue-monitor |
4
|
|
|
* @copyright Copyright (c) 2017 Roman Zhuravlev |
5
|
|
|
* @license http://opensource.org/licenses/BSD-3-Clause |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace zhuravljov\yii\queue\monitor; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
use yii\base\BootstrapInterface; |
12
|
|
|
use yii\base\InvalidConfigException; |
13
|
|
|
use yii\i18n\PhpMessageSource; |
14
|
|
|
use yii\web\Application as WebApplication; |
15
|
|
|
use yii\web\GroupUrlRule; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Web Module |
19
|
|
|
* |
20
|
|
|
* @property \yii\i18n\Formatter $formatter |
21
|
|
|
* |
22
|
|
|
* @author Roman Zhuravlev <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class Module extends \yii\base\Module implements BootstrapInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
public $canPushAgain = false; |
30
|
|
|
/** |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
public $canExecStop = false; |
34
|
|
|
/** |
35
|
|
|
* @var bool |
36
|
|
|
*/ |
37
|
|
|
public $canWorkerStop = false; |
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
*/ |
41
|
|
|
public $layout = 'main'; |
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
*/ |
45
|
|
|
public $controllerNamespace = 'zhuravljov\yii\queue\monitor\controllers'; |
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
|
|
public $defaultRoute = 'job/index'; |
50
|
|
|
|
51
|
|
|
public function init() |
52
|
|
|
{ |
53
|
|
|
parent::init(); |
54
|
|
|
$this->registerTranslations(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritdoc |
59
|
|
|
*/ |
60
|
|
|
public function bootstrap($app) |
61
|
|
|
{ |
62
|
|
|
if ($app instanceof WebApplication) { |
63
|
|
|
$app->urlManager->addRules([[ |
64
|
|
|
'class' => GroupUrlRule::class, |
65
|
|
|
'prefix' => $this->id, |
66
|
|
|
'rules' => [ |
67
|
|
|
'jobs' => 'job/index', |
68
|
|
|
'job/<id:\d+>/<action\w+>' => 'job/view-<action>', |
69
|
|
|
'workers' => 'worker/index', |
70
|
|
|
'<controller:\w+>/<id:\d+>' => '<controller>/view', |
71
|
|
|
'<controller:\w+>/<action\w+>/<id:\d+>' => '<controller>/<action>', |
72
|
|
|
'<controller:\w+>/<action\w+>' => '<controller>/<action>', |
73
|
|
|
], |
74
|
|
|
]], false); |
75
|
|
|
} else { |
76
|
|
|
throw new InvalidConfigException('The module must be used for web application only.'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function registerTranslations() |
81
|
|
|
{ |
82
|
|
|
if (!isset(Yii::$app->i18n->translations['queue-monitor/*'])) { |
83
|
|
|
Yii::$app->i18n->translations['queue-monitor/*'] = [ |
84
|
|
|
'class' => PhpMessageSource::class, |
85
|
|
|
'sourceLanguage' => 'en-US', |
86
|
|
|
'basePath' => '@zhuravljov/yii/queue/monitor/messages', |
87
|
|
|
'fileMap' => [ |
88
|
|
|
'queue-monitor/main' => 'main.php', |
89
|
|
|
'queue-monitor/notice' => 'notice.php', |
90
|
|
|
], |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Module translator. |
97
|
|
|
* |
98
|
|
|
* @param string $category |
99
|
|
|
* @param string $message |
100
|
|
|
* @param array $params |
101
|
|
|
* @param string $language |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public static function t($category, $message, $params = [], $language = null) |
105
|
|
|
{ |
106
|
|
|
return Yii::t('queue-monitor/' . $category, $message, $params, $language); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|