|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: dsmrt |
|
5
|
|
|
* Date: 2/5/18 |
|
6
|
|
|
* Time: 10:01 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\keychain; |
|
10
|
|
|
|
|
11
|
|
|
use craft\base\Plugin; |
|
12
|
|
|
use craft\events\RegisterUrlRulesEvent; |
|
13
|
|
|
use craft\web\UrlManager; |
|
14
|
|
|
use flipbox\keychain\models\Settings; |
|
15
|
|
|
use flipbox\keychain\services\KeyChainService; |
|
16
|
|
|
use yii\base\Event; |
|
17
|
|
|
|
|
18
|
|
|
class KeyChain extends Plugin |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
// public $hasCpSection = true; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Initializes the module. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function init() |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
parent::init(); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Init Modules, Components, and Events |
|
33
|
|
|
*/ |
|
34
|
|
|
$this->initComponents(); |
|
35
|
|
|
$this->initEvents(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function initEvents() |
|
39
|
|
|
{ |
|
40
|
|
|
// CP routes |
|
41
|
|
|
Event::on( |
|
42
|
|
|
UrlManager::class, |
|
43
|
|
|
UrlManager::EVENT_REGISTER_CP_URL_RULES, |
|
44
|
|
|
[self::class, 'onRegisterCpUrlRules'] |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Init Continued |
|
50
|
|
|
*/ |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function initComponents() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->setComponents([ |
|
58
|
|
|
'keyChain' => KeyChainService::class, |
|
59
|
|
|
]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* COMPONENTS |
|
64
|
|
|
*/ |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return KeyChainService |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getService() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->get('keyChain'); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return Settings |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getSettings() |
|
78
|
|
|
{ |
|
79
|
|
|
return parent::getSettings(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @inheritdoc |
|
84
|
|
|
*/ |
|
85
|
|
|
public function createSettingsModel() |
|
86
|
|
|
{ |
|
87
|
|
|
return new Settings(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param RegisterUrlRulesEvent $event |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function onRegisterCpUrlRules(RegisterUrlRulesEvent $event) |
|
94
|
|
|
{ |
|
95
|
|
|
$event->rules = array_merge( |
|
96
|
|
|
$event->rules, |
|
97
|
|
|
[ |
|
98
|
|
|
'keychain' => 'keychain/cp/view/general/index', |
|
99
|
|
|
'keychain/new' => 'keychain/cp/view/edit/index', |
|
100
|
|
|
'keychain/<keypairId:\d+>' => 'keychain/cp/view/edit/index', |
|
101
|
|
|
'keychain/openssl' => 'keychain/cp/view/edit/openssl', |
|
102
|
|
|
] |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|